Custom JavaScript Utilities for MJ Studio
npm install @mj-studio/js-utilA comprehensive collection of JavaScript utility functions for modern development. Written in
TypeScript with full type safety and extensive JSDoc documentation.
``bash`
yarn add @mj-studio/js-util
npm install @mj-studio/js-util
| Category | Function | Description |
|----------------|----------------------------------------------------|------------------------------------------------|
| String | camelCase(str) | Converts snake_case or kebab-case to camelCase |snakeCase(str)
| | | Converts strings to snake_case format |capitalize(str)
| | | Capitalizes the first character |camelCaseObject(obj)
| Object | | Recursively converts object keys to camelCase |snakeCaseObject(obj)
| | | Recursively converts object keys to snake_case |reverseObjectKeyValues(obj)
| | | Swaps keys and values in object |replaceJsonKeysRecursively(obj, options)
| | | Replace object keys recursively |replaceJsonValuesRecursively(obj, options)
| | | Replace object values recursively |groupByArray(arr, getKey)
| Array | | Groups array elements into subarrays |groupByObject(arr, getKey)
| | | Groups array elements into object |doBatch(arr, work, batchCount)
| | | Processes arrays in batches |unique(arr)
| | | Removes duplicate values |generateArray(size)
| | | Creates array [0, 1, 2, ..., size-1] |randomItem(arr)
| | | Returns random element |lastOf(arr)
| | | Returns last element |toggled(arr, element)
| | | Toggles element in array |withTimeout(ms, promise)
| Promise | | Adds timeout to promises |withMinimumResolveTime(ms, promise)
| | | Ensures minimum resolve time |is.string(value)
| Type Check | | String type check |is.number(value)
| | | Number type check (excludes NaN) |is.boolean(value)
| | | Boolean type check |is.array(value)
| | | Array type check |is.function(value)
| | | Function type check |is.object(value)
| | | Object type check (excludes null) |is.plainObject(value)
| | | Plain object type check |is.null(value)
| | | Null check |is.undefined(value)
| | | Undefined check |is.nullOrUndefined(value)
| | | Null or undefined check |is.falsy(value)
| | | Falsy values check |is.truthy(value)
| | | Truthy values check |is.notEmptyString(value)
| | | Non-empty string check |is.emptyString(value)
| | | Empty string check |is.numberString(value)
| | | Numeric string check |is.integerString(value)
| | | Integer string check |is.notEmptyArray(value)
| | | Non-empty array check |is.emptyArray(value)
| | | Empty array check |is.promise(value)
| | | Promise check |filterJsonKeys(json, keys)
| Filter | | Filter JSON object by keys |filterNonNullish(arr)
| | | Remove null/undefined from array |filterNonNullishKeys(obj, options)
| | | Remove null/undefined from object |removeValueByKeyInObject(obj, key)
| | | Remove specific keys from object |numberWithComma(num)
| Number | | Format with thousand separators |padZero(num, len)
| | | Pad with leading zeros |toFixed(num, digits, default)
| | | Safe toFixed with undefined handling |toFixedIfNeed(num, digits)
| | | toFixed that removes trailing zeros |toSiUnitString(num)
| | | Convert to SI units (1.5K, 1.5M) |clamp(value, min, max)
| | | Clamps value between min and max |parseSecond(seconds)
| Time | | Parse seconds into time components |formatSec(seconds, format)
| | | Format seconds with various formats |createTimer()
| | | Timer management |setIntervalWithTimeout(callback, ms)
| | | Clearable intervals |interpolate(value, inMin, inMax, outMin, outMax)
| Math | | Linear interpolation |interpolateColor(ratio, startColor, endColor)
| | | Color interpolation |formatJson(data)
| Misc | | Pretty-print JSON with error handling |lastMatchIndex(str, match)` | Find last occurrence index |
| |
All functions include comprehensive TypeScript type definitions and JSDoc documentation for
excellent IDE support.
See CONTRIBUTING.md for contribution guidelines.
MIT © MJ Studio