English | 中文
@zanejs/utils is a carefully curated TypeScript utility function library that aggregates high-frequency utility functions used in daily development. Designed with principles of zero dependencies, type safety, and high performance, this library helps developers improve efficiency and reduce repetitive code writing.
- 📦 Zero Dependencies - No reliance on any third-party libraries, ready to use out of the box
- 🛡 Full TypeScript - Provides complete type definitions for an excellent development experience
- 🚀 High Performance - Each function is performance-optimized
- 📚 Modular Design - Supports on-demand import, tree-shaking friendly
- Array deduplication, flattening, grouping
- Array difference, intersection, union calculations
- Array sorting, pagination, partitioning
- Safe element access and manipulation
- Memory cache management (LRU, TTL support)
- Local storage wrappers (localStorage/sessionStorage)
- Function result caching (memoization)
- Deep equality comparison (supports complex objects, circular references)
- Shallow equality comparison
- Special value comparison (NaN, ±0, etc.)
- Function throttling and debouncing
- Function currying and partial application
- Function composition and piping
- Lazy evaluation and caching
- Precise type detection (array, object, function, etc.)
- Null value checking (null, undefined, empty strings, etc.)
- Type conversion assistance
- Precision calculation (solves floating-point issues)
- Number formatting, thousand separators
- Range limiting, random number generation
- Unit conversion
- Object deep merging, cloning
- Property path get/set (supports dot notation and array paths)
- Object filtering, mapping, transformation
- Immutable data operations
- Simple observer pattern implementation
- Data change listening and response
- Computed properties and dependency tracking
- Template string processing
- String encryption/decryption (basic)
- Formatting (camelCase, kebab-case, capitalize first letter, etc.)
- String validation and extraction
# Using npm
npm install @zanejs/utils
# Using yarn
yarn add @zanejs/utils
# Using pnpm
pnpm add @zanejs/utils// ES Module
import { deepClone, throttle, isType } from '@zanejs/utils';
// CommonJS
const { debounce, formatNumber } = require('@zanejs/utils');import * as zUtils from '@zanejs/utils';// Array operations
import { uniqueBy, chunk } from '@zanejs/utils/array';
const users = [{id: 1}, {id: 2}, {id: 1}];
const uniqueUsers = uniqueBy(users, 'id'); // [{id: 1}, {id: 2}]
const chunks = chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
// Function utilities
import { debounce, memoize } from '@zanejs/utils/function';
const search = debounce((query) => {
console.log(`Searching: ${query}`);
}, 300);
const factorial = memoize((n) => {
return n <= 1 ? 1 : n * factorial(n - 1);
});
// Object operations
import { deepMerge, get } from '@zanejs/utils/object';
const obj1 = { a: { b: 1 } };
const obj2 = { a: { c: 2 } };
const merged = deepMerge(obj1, obj2); // { a: { b: 1, c: 2 } }
const value = get({ user: { name: 'Zane' } }, 'user.name'); // 'Zane'- Chrome 60+
- Firefox 55+
- Safari 12+
- Edge 79+
- iOS Safari 12+
- Android Chrome 60+
zane-utils adheres to the following design principles:
- Practicality First - Includes only utility functions proven in practice
- Consistent API - Unified parameter order and naming conventions
- Clear Responsibilities - Each function does one thing well
- Backward Compatibility - Stable API design, major changes include migration plans
Welcome to submit Issues and Pull Requests! If you have suggestions for commonly used utility functions or find any issues, please feel free to contribute.
MIT © Zane
@zanejs/utils - Making JavaScript/TypeScript development more elegant and efficient!