English | δΈζ
A modern collection of utility functions for TypeScript/JavaScript projects.
- π TypeScript First - Built with TypeScript, providing excellent type safety
- π¦ Tree Shaking - Only import what you need
- π§ Zero Dependencies - Lightweight and self-contained
- β‘ Well Tested - Comprehensive test coverage with Vitest
- π Full Documentation - Complete API reference with examples
- π― Modern Tooling - ESM, CJS, and UMD builds
# npm
npm install xfunc
# yarn
yarn add xfunc
# pnpm
pnpm add xfunc// Import specific functions (recommended for tree shaking)
import { debounce } from 'xfunc'
// Or import everything
import * as xfunc from 'xfunc'
// Usage examples
const debouncedHandler = debounce(() => {
console.log('Called after 300ms delay')
}, 300)
if (Array.isArray(data)) {
console.log('data is an array')
}toArray- Convert value to arrayunionBy- Merge arrays and remove duplicates by iterateerange- Generate numeric range arrayssortBy- Sort array by iteratee functionsorderBy- Sort array by multiple criteria with orderuniq- Create deduplicated arrayuniqWith- Create deduplicated array with custom comparatorcastArray- Convert value to array (wrap if needed)remove- Remove first occurrence of item from array
β‘ Function Methods
debounce- Create debounced functionthrottle- Create throttled functionmemoize- Create memoized function with cache
toNumber- Convert value to numberrandomInt- Generate random integer in range
omit/omitBy- Create object excluding propertiespick/pickBy- Create object with only specified propertiesmapEntries- Transform object key-value pairsforEachEntry- Iterate over object entriesforOwn- Iterate over own object propertieshasOwn- Check for own propertyclone- Create shallow clonecloneDeep- Create deep clonemerge- Deep merge objects
capitalize- Capitalize first character, lowercase restlowerFirst- Convert first character to lowercaseupperFirst- Convert first character to uppercasecamelize- Convert hyphenated string to camelCasehyphenate- Convert camelCase string to hyphenated
21 type checking utilities including:
isString,isNumber,isBooleanisEmpty,isNil,isFunction,isObjectisDate,isRegExp,isPromise,isErrorisTypeString,toRawType,makeMap,isNumericKey- And more...
QueueMap- Map-based queue with insertion order
import { debounce } from 'xfunc'
const searchHandler = debounce((query: string) => {
// API call will only happen 300ms after user stops typing
searchAPI(query)
}, 300)
input.addEventListener('input', (e) => {
searchHandler(e.target.value)
})import { pick, omit, isObject, isEmpty } from 'xfunc'
const user = { id: 1, name: 'John', email: 'john@example.com', password: 'secret' }
// Pick only safe properties for API response
const safeUser = pick(user, ['id', 'name', 'email'])
// { id: 1, name: 'John', email: 'john@example.com' }
// Omit sensitive data
const publicUser = omit(user, ['password'])
// { id: 1, name: 'John', email: 'john@example.com' }
// Type-safe checking
if (isObject(data) && !isEmpty(data)) {
// Process the object safely
}import { toArray, range, uniq, isNumber } from 'xfunc'
// Convert various types to arrays
toArray('hello') // ['h', 'e', 'l', 'l', 'o']
toArray(42) // [42]
toArray([1, 2, 3]) // [1, 2, 3]
toArray(null) // []
// Generate numeric ranges
range(5) // [0, 1, 2, 3, 4]
range(1, 5) // [1, 2, 3, 4]
range(0, 20, 5) // [0, 5, 10, 15]
// Remove duplicates
uniq([1, 2, 2, 3, 3, 3]) // [1, 2, 3]
// Safe type checking
isNumber('42') // false
isNumber(42) // trueVisit our documentation site for:
- π Complete API reference
- π‘ Usage examples
- π― Best practices
- π Type definitions
# Install dependencies
pnpm install
# Run tests in watch mode
pnpm test
# Run tests once
pnpm test:run
# Build the library
pnpm build
# Lint and fix code
pnpm lint
# Start documentation site
pnpm docs:dev
# Build documentation
pnpm docs:buildMIT
Contributions are welcome! Please read our contributing guidelines and submit a pull request.
xfunc - Utility functions that just work β‘