npm install uty
This utility package provides helper functions for JavaScript tasks.
``shell`
npm i uty
Provides functions to assess variable types, compare values, and gather information about the system environment.
`js
import { isArrayLike, isEqual } from 'uty/is';
isArrayLike('fruits'); //=> true
isEqual([1, 2, 3], [1, 2, 3, 4]); //=> false
`
Helpers for working with arrays and objects, providing functions for data extraction and manipulation.
`js
import { pluck } from 'uty/collect';
pluck('name', 'detail.date', [
{ name: 'Albert', detail: { date: 1879 } },
{ name: 'Isaac', detail: { date: 1643 } },
]);
//=> {1879: 'Albert', 1643: 'Isaac'}
`
Efficient tools for a wide range of mathematical calculations designed to simplify number handling and analysis.
`js
import { avg } from 'uty/math';
avg('pages', [
{ name: 'Les Miserables', pages: 176 },
{ name: 'My Left Foot', pages: 1096 },
]);
//=> 636
`
Utility functions for easy and efficient string manipulation and formatting.
`js
import { ucfirst, ucwords } from 'uty/string';
ucfirst('uty is simple'); //=> Uty is simple
ucwords('uty is simple'); //=> Uty Is Simple
`
Converts data types and structures, making it easy to switch between arrays, objects, and other formats.
`js
import { toArray } from 'uty/to';
toArray({ first: 'Lionel', middle: 'Andrés', last: 'Messi' });
//=> ['Lionel', 'Andrés', 'Messi']
`
Commonly used utility functions that streamline coding patterns and reduce repetitive tasks.
`js
import { pipe } from 'uty';
import { divisible, add, sum } from 'uty/math';
const total = pipe(divisible(2), add(10), sum);
total([1, 2, 3, 4, 5]);
//=> 26
await total(Promise.resolve([6, 7, 8, 9, 10]));
//=> 54
`
A simple, customizable event system for handling and emitting events.
`js
import { event } from 'uty/event';
const bus = event();
bus.on('tick', number => {
console.log(number);
});
bus.emit('tick', 1);
//=> 1
`
A set of consistent values used throughout the application to maintain clarity and reduce redundancy.
`js
import { MAX_SAFE_INTEGER, RGX_WHITESPACE } from 'uty/define';
console.log(MAX_SAFE_INTEGER); //=> 9007199254740991
console.log(RGX_WHITESPACE); //=> /^\s*$/
`
Advanced type-checking and utilities to ensure safe operations.
`ts
import type { Include } from 'uty/type';
function isArray
return Array.isArray(value);
}
``
Visit our [documentation][DOCUMENTATION] for detailed guides and references.
---
Release Notes
All notable changes to this project will be documented in the [changelog][CHANGELOG].
License
[MIT][LICENSE]
[TEST]: https://github.com/kodla-dev/uty/actions/workflows/test.yaml
[PACKAGE]: https://www.npmjs.com/package/uty
[SIZE]: https://bundlephobia.com/package/uty
[LICENSE]: https://github.com/kodla-dev/uty/blob/main/LICENSE
[CHANGELOG]: https://github.com/kodla-dev/uty/blob/main/CHANGELOG.md
[DOCUMENTATION]: https://github.com/kodla-dev/uty/tree/main/docs