js-utils-lib-core
v1.1.1
Published
Well-known, battle-tested JavaScript utility functions
Maintainers
Readme
js-utils-lib-core
A minimal, dependency-free JavaScript utility library. Provides commonly used helpers for arrays, objects, strings, functions, types, and numbers—inspired by lodash-style APIs with a small surface area and tree-shakeable subpath exports.
Table of Contents
Features
- Zero dependencies — No runtime or peer dependencies.
- Subpath exports — Import only what you need (e.g.
js-utils-lib-core/array). - Consistent API — Predictable naming and signatures across all modules.
- Node & bundlers — Works in Node.js and with ESM/CJS bundlers.
Requirements
- Node.js 14+ (or any runtime with ES2020 support)
Installation
npm install js-utils-lib-coreQuick Start
CommonJS
const {
debounce,
chunk,
uniq,
pick,
omit,
get,
camelCase,
isEmpty,
clamp,
memoize,
} = require('js-utils-lib-core');
// Event handling
window.addEventListener('resize', debounce(() => console.log('resized'), 200));
// Arrays
chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
uniq([1, 2, 1, 3, 2]); // [1, 2, 3]
compact([0, 1, null, 2, '', 3]); // [1, 2, 3]
// Objects
pick({ a: 1, b: 2, c: 3 }, ['a', 'c']); // { a: 1, c: 3 }
omit({ a: 1, b: 2, c: 3 }, ['b']); // { a: 1, c: 3 }
get({ a: { b: { c: 42 } } }, 'a.b.c'); // 42
// Strings
camelCase('hello world'); // 'helloWorld'
kebabCase('helloWorld'); // 'hello-world'
truncate('Long text...', 8); // 'Long...'
// Types & numbers
isEmpty([]); // true
isObject({}); // true
clamp(15, 0, 10); // 10
random(1, 10); // integer in [1, 10)ES Modules
import { debounce, chunk, pick, camelCase, isEmpty } from 'js-utils-lib-core';
// or by category
import { chunk, uniq } from 'js-utils-lib-core/array';
import { pick, omit } from 'js-utils-lib-core/object';Subpath Imports
Import by category for smaller bundles and clearer dependencies:
const { chunk, uniq, groupBy } = require('js-utils-lib-core/array');
const { pick, omit, deepClone } = require('js-utils-lib-core/object');
const { debounce, throttle, memoize } = require('js-utils-lib-core/function');
const { isArray, isEmpty, isPlainObject } = require('js-utils-lib-core/type');
const { camelCase, truncate, kebabCase } = require('js-utils-lib-core/string');
const { clamp, random, sum, mean } = require('js-utils-lib-core/number');API Reference
Type — js-utils-lib-core/type
| Function | Description |
|----------------|--------------------------------------------|
| isArray | Returns true if value is an array. |
| isObject | Plain object (excludes null and arrays). |
| isFunction | Returns true if value is a function. |
| isString | Returns true if value is a string. |
| isNumber | Finite number (excludes NaN). |
| isBoolean | Returns true for true or false. |
| isNull | Returns true for null. |
| isUndefined | Returns true for undefined. |
| isNil | Returns true for null or undefined. |
| isPlainObject| Object with default prototype. |
| isEmpty | Empty array, string, or object. |
Array — js-utils-lib-core/array
| Function | Description |
|----------------|----------------------------------------------|
| chunk | Split array into chunks of given size. |
| compact | Remove falsy values. |
| uniq | Unique values (order preserved). |
| uniqBy | Unique by iteratee (key or function). |
| flatten | Flatten one level. |
| flattenDeep | Flatten recursively. |
| difference | Elements in first array not in second. |
| intersection | Elements in both arrays. |
| groupBy | Group by key or iteratee. |
| keyBy | Index by key or iteratee. |
| sortBy | Sort by key(s) or iteratee(s). |
| take / drop| First N elements / skip first N. |
| first / last | First or last element. |
| sample | Random element. |
| shuffle | Shuffle (returns new array). |
| range | Integer range. |
| without | Exclude given values. |
Object — js-utils-lib-core/object
| Function | Description |
|-----------|----------------------------------------------|
| pick | Subset of object by keys. |
| omit | Object without given keys. |
| get | Nested value by path (e.g. 'a.b.c'). |
| set | Set nested value (returns new object). |
| merge | Deep merge objects. |
| deepClone | Recursive clone. |
| invert | Swap keys and values (primitives only). |
| defaults| Fill missing keys from source objects. |
| has | Has property at path. |
| keys / values / entries | Object keys, values, or entries. |
String — js-utils-lib-core/string
| Function | Description |
|-----------|----------------------------------------------|
| capitalize | First character uppercase. |
| truncate | Truncate with optional suffix. |
| camelCase / kebabCase / snakeCase | Case conversion. |
| startCase | Title-style words. |
| padStart / padEnd | Pad string to length. |
| repeat | Repeat string. |
| trim / trimStart / trimEnd | Trim whitespace. |
| words | Split into words (regex). |
| escape / unescape | HTML entity encode/decode. |
Function — js-utils-lib-core/function
| Function | Description |
|-----------|----------------------------------------------|
| debounce | Delay execution until calls stop. |
| throttle | Limit execution rate. |
| once | Execute only once. |
| memoize | Cache results by arguments (optional resolver). |
| noop | No-op function. |
| identity| Return first argument. |
| constant| Return a constant function. |
| compose / pipe | Compose or pipe functions. |
| bind / partial / partialRight | Partial application. |
| delay | Invoke after timeout. |
| negate | Negate predicate. |
Number — js-utils-lib-core/number
| Function | Description |
|-----------|----------------------------------------------|
| clamp | Clamp value to [lower, upper]. |
| random | Random number or integer in range. |
| round | Round to given precision. |
| sum | Sum of array. |
| min / max | Minimum or maximum of array. |
| inRange | Whether value is in numeric range. |
| mean | Average of array. |
License
MIT © js-utils-lib-core
