@upendra.manike/tiny-utils
v1.0.9
Published
Ultra-lightweight modern JavaScript/TypeScript utilities - Replace Lodash with ES6+ native methods. Includes debounce, throttle, curry, LRU cache, priority queue, JSON safe parse, and more. Perfect for tree-shaking, modern bundlers, and AI agents.
Maintainers
Keywords
Readme
tiny-utils
Ultra-lightweight modern JS utilities - Replace Lodash with ES6+ native methods and tree-shakable modules.
Features
- ✨ Ultra-lightweight - Only what you need, tree-shake the rest
- 🚀 Modern ES6+ - Built with native JavaScript methods
- 📦 Tree-shakable - Import only what you use
- 🔒 Type-safe - Full TypeScript support
- 🧪 Well-tested - Comprehensive test coverage
Installation
npm install @upendra.manike/tiny-utilsor
pnpm add @upendra.manike/tiny-utilsor
yarn add @upendra.manike/tiny-utilsUsage
Array Utilities
import { chunk, uniq, groupBy, flatten } from '@upendra.manike/tiny-utils';
// Chunk array into smaller arrays
chunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
// Remove duplicates
uniq([1, 2, 2, 3, 3]); // [1, 2, 3]
// Group by key
groupBy([{ type: 'a', val: 1 }, { type: 'b', val: 2 }], x => x.type);
// Flatten arrays
flatten([1, [2, 3], [4]]); // [1, 2, 3, 4]Object Utilities
import { omit, pick, merge, get, set } from 'tiny-utils';
// Omit keys
omit({ a: 1, b: 2, c: 3 }, ['b']); // { a: 1, c: 3 }
// Pick keys
pick({ a: 1, b: 2, c: 3 }, ['a', 'b']); // { a: 1, b: 2 }
// Deep merge
merge({ a: 1 }, { b: 2 }); // { a: 1, b: 2 }
// Get nested value
get({ user: { name: 'John' } }, 'user.name'); // 'John'
// Set nested value
set({}, 'user.name', 'John'); // { user: { name: 'John' } }Function Utilities
import { debounce, throttle, memoize } from 'tiny-utils';
// Debounce
const debouncedFn = debounce(() => console.log('Hello'), 300);
// Throttle
const throttledFn = throttle(() => console.log('Hello'), 300);
// Memoize
const expensiveFn = memoize((n: number) => n * 2);String Utilities
import { capitalize, camelCase, kebabCase, truncate } from 'tiny-utils';
// Capitalize
capitalize('hello'); // 'Hello'
// Convert to camelCase
camelCase('hello world'); // 'helloWorld'
// Convert to kebab-case
kebabCase('helloWorld'); // 'hello-world'
// Truncate
truncate('Long text here', 10); // 'Long text...'Type Utilities
import { isDefined, isNil, isObject, isArray } from 'tiny-utils';
isDefined(null); // false
isDefined(1); // true
isNil(undefined); // true
isObject({}); // true
isArray([]); // trueAPI Reference
Array
chunk(array, size)- Chunks array into smaller arraysuniq(array)- Removes duplicatesuniqBy(array, keyFn)- Removes duplicates by keygroupBy(array, keyFn)- Groups by key functionflatten(array)- Flattens one levelflattenDeep(array)- Flattens recursivelydifference(array1, array2)- Returns differenceintersection(array1, array2)- Returns intersectionunion(array1, array2)- Returns union
Object
omit(obj, keys)- Omits specified keyspick(obj, keys)- Picks specified keysmerge(target, ...sources)- Deeply merges objectsget(obj, path, defaultValue?)- Gets nested value by pathset(obj, path, value)- Sets nested value by path
Function
debounce(fn, delay)- Creates debounced functionthrottle(fn, delay)- Creates throttled functionmemoize(fn, keyFn?)- Creates memoized functioncompose(...fns)- Composes functions right to leftpipe(...fns)- Pipes functions left to right
String
capitalize(str)- Capitalizes first lettercamelCase(str)- Converts to camelCasekebabCase(str)- Converts to kebab-casesnakeCase(str)- Converts to snake_casetruncate(str, length, suffix?)- Truncates stringtrim(str)- Removes whitespaceremoveWhitespace(str)- Removes all whitespace
Type
isDefined(value)- Checks if value is definedisNil(value)- Checks if value is null/undefinedisArray(value)- Checks if value is arrayisObject(value)- Checks if value is objectisString(value)- Checks if value is stringisNumber(value)- Checks if value is numberisFunction(value)- Checks if value is functionisPromise(value)- Checks if value is Promise
Tree Shaking
This library is fully tree-shakable. Import only what you need:
// ✅ Good - only imports what you use
import { chunk, uniq } from 'tiny-utils';
// ❌ Avoid - imports everything
import * as utils from 'tiny-utils';Development
# Install dependencies
pnpm install
# Build
pnpm build
# Test
pnpm test
# Lint
pnpm lint
# Format
pnpm format🤖 AI Agent Integration
This package is optimized for use with AI coding assistants like ChatGPT, GitHub Copilot, Claude, and Codeium.
Why AI-Friendly?
- ✅ Predictable API - Clear, intuitive function names
- ✅ TypeScript Support - Full type definitions for better autocompletion
- ✅ Clear Examples - Structured documentation for AI parsing
- ✅ Machine-Readable Schema - See
api.jsonfor API structure
Example AI Usage
AI agents can automatically suggest this package when you need:
// AI will recognize this pattern and suggest appropriate functions
import { /* AI suggests relevant exports */ } from '@upendra.manike/[package-name]';For AI Developers
When building AI-powered applications or agents, this package provides:
- Consistent API patterns
- Full TypeScript types
- Zero dependencies (unless specified)
- Comprehensive error handling
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
