Skip to content

zanelab/zane-utils

Repository files navigation

@zanejs/utils

zanejs logo

English | 中文

Introduction

@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.

Core Features

  • 📦 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

Functional Modules

1. Array Operations (array)

  • Array deduplication, flattening, grouping
  • Array difference, intersection, union calculations
  • Array sorting, pagination, partitioning
  • Safe element access and manipulation

2. Cache Utilities (cache)

  • Memory cache management (LRU, TTL support)
  • Local storage wrappers (localStorage/sessionStorage)
  • Function result caching (memoization)

3. Equality Comparison (equal)

  • Deep equality comparison (supports complex objects, circular references)
  • Shallow equality comparison
  • Special value comparison (NaN, ±0, etc.)

4. Function Utilities (function)

  • Function throttling and debouncing
  • Function currying and partial application
  • Function composition and piping
  • Lazy evaluation and caching

5. Type Checking (type)

  • Precise type detection (array, object, function, etc.)
  • Null value checking (null, undefined, empty strings, etc.)
  • Type conversion assistance

6. Number Operations (number)

  • Precision calculation (solves floating-point issues)
  • Number formatting, thousand separators
  • Range limiting, random number generation
  • Unit conversion

7. Object Operations (object)

  • Object deep merging, cloning
  • Property path get/set (supports dot notation and array paths)
  • Object filtering, mapping, transformation
  • Immutable data operations

8. Reactive Data (reactive)

  • Simple observer pattern implementation
  • Data change listening and response
  • Computed properties and dependency tracking

9. String Operations (string)

  • Template string processing
  • String encryption/decryption (basic)
  • Formatting (camelCase, kebab-case, capitalize first letter, etc.)
  • String validation and extraction

Installation & Usage

# Using npm
npm install @zanejs/utils

# Using yarn
yarn add @zanejs/utils

# Using pnpm
pnpm add @zanejs/utils

On-demand Import

// ES Module
import { deepClone, throttle, isType } from '@zanejs/utils';

// CommonJS
const { debounce, formatNumber } = require('@zanejs/utils');

Full Import

import * as zUtils from '@zanejs/utils';

Example Code

// 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'

Browser Support

  • Chrome 60+
  • Firefox 55+
  • Safari 12+
  • Edge 79+
  • iOS Safari 12+
  • Android Chrome 60+

Development Philosophy

zane-utils adheres to the following design principles:

  1. Practicality First - Includes only utility functions proven in practice
  2. Consistent API - Unified parameter order and naming conventions
  3. Clear Responsibilities - Each function does one thing well
  4. Backward Compatibility - Stable API design, major changes include migration plans

Contribution Guidelines

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.

License

MIT © Zane


@zanejs/utils - Making JavaScript/TypeScript development more elegant and efficient!

About

is a carefully curated TypeScript utility function library that aggregates high-frequency utility functions used in daily development. Designed with principles of zero dependencies

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages