@cuboapp/utils
v1.0.12
Published
Utils
Downloads
4,048
Readme
@cuboapp/utils
A small, dependency-free collection of TypeScript utility functions.
Install
npm install @cuboapp/utilsThe package ships compiled CommonJS with type declarations and works from both CommonJS and ESM:
import { chunk, get, numberFormat } from '@cuboapp/utils'
// or
const { chunk, get, numberFormat } = require('@cuboapp/utils')What's inside
| Area | Exports |
| --- | --- |
| array | chunk |
| object | get, set, unset, pick, omit, groupBy, keyBy, sortBy, invert, flatten, unflatten, cloneDeep |
| codecs | toBoolean, toInt, toDecimal, toArrayOfNumbers, toArrayOfStrings, toJson |
| color | rgbToHex, hexToRgb, componentToHex, shadeColor |
| time | unixtime, isotime, fromUnixTime |
| transliter | translate, untranslate (ru / uk / mn presets) |
| misc | debounce, memoize, wrap, trim / trimStart / trimEnd, ucfirst, ending, numberFormat, generatePassword, uuid, LimitedSet, gracefullShutdown |
| other | Cache, EventEmitter |
Examples
import { chunk, numberFormat, translate, groupBy } from '@cuboapp/utils'
chunk([1, 2, 3, 4, 5], 2) // [[1, 2], [3, 4], [5]]
numberFormat(1234567.891, 2) // "1 234 567.89"
translate('ru', 'Привет Игорь') // "Privet-Igor"
groupBy([{ t: 'a' }, { t: 'b' }, { t: 'a' }], 't')
// { a: [{ t: 'a' }, { t: 'a' }], b: [{ t: 'b' }] }Build
npm run build # compile src -> dist
npm run typecheck # type-check without emittingLicense
MIT
