@abw/badger-utils
v1.1.4
Published
Javascript utility modules
Downloads
55
Readme
Badger Utils
This is a collection of various useful Javascript utility functions that I've written over the years.
Many of them are wrappers for simple code snippets that exist only to make my code more self-documenting and/or easier to read. Some are more complicated and are the kind of things that I prefer not to copy-and-paste into different projects.
You'll find similar functions in other libraries like underscore and Lodash. These just happen to be the ones I tend to use all the time.
Installation
Install badger-utils
using your favourite package manager.
npm
npm add @abw/badger-utils
pnpm
pnpm add @abw/badger-utils
yarn
yarn add @abw/badger-utils
Documentation
Visit the website for detailed documentation.
Assertions
- isBoolean(value)
- isString(value)
- isNumber(value)
- isInteger(value)
- isFloat(value)
- isArray(value)
- isFunction(value)
- isRegExp(value)
- isObject(value)
- isSimple(value)
- isUndefined(value)
- isNull(value)
- isEmpty(...values)
- hasValue(value)
- noValue(value)
- haveValue(...values)
- firstValue(...values)
Numbers
- range(from, to, step=1)
- formatNumber(number, options)
- currency(number, options)
- commas(n)
- setNumberDefaults(defaults)
Text
- splitLines(text)
- splitList(value)
- splitHash(value, set=true, hash={})
- joinList(array, joint=' ', lastJoint=joint)
- joinListAnd(array, joint=', ', lastJoint=' and ')
- joinListOr(array, joint=', ', lastJoint=' or ')
- capitalise(word) / capitalize(word)
- capitaliseWords(string) / capitalizeWords(string)
- snakeToStudly(snake)
- snakeToCamel(snake)
- plural(singular)
- singular(plural)
- inflect(n, singular, plural, no='no')
- Inflect(n, singular, plural, no='No')
- format(message, data)
Objects
- hash(source, options)
- objMap(obj, fn)
- remove(object, key)
- extract(object, keys, options)
- keys(object)
- values(object)
- entries(object)
Functions
Select
Sort
- stringSort(field)
- numberSort(field)
- integerSort(field)
- booleanSort(field)
- multiSort(fields)
- stringField(obj,field)
- numberField(obj,field)
- integerField(obj,field)
- booleanField(obj,field)
- descendingOrder(sortFn)
- ascendingOrder(sortFn)
Timing
Errors
Miscellaneous
Author
Andy Wardley [email protected]