2.0.0 • Published 2 years ago

kixx-lib-es6 v2.0.0

Weekly downloads
6
License
MIT
Repository
github
Last release
2 years ago

Kixx

A loosely coupled set of tools and libraries for ES6 JavaScript applications.

Installation

$ npm install --save kixx-lib-es6

Library

Import the library like this:

const lib = require('kixx-lib-es6');

// Or, using destructuring:
const {compact} = require('kixx-lib-es6');

lib.compact === compact; // true

compact()

compact(list)

parametertypedescription
listArrayA list to filter

Returns a new list with all the falsy values filtered out.

deepFreeze()

deepFreeze(object)

parametertypedescription
objectObjectAn Object to deeply freeze.

Returns the passed Object after recursively calling Object.freeze() deeply throughout.

mergeDeep()

mergeDeep(target, ...sources)

parametertypedescription
targetObjectThe target object to merge into.
sourcesObjectsSource objects to merge into the target.

Returns the target Object after deeply merging all passed in Objects from left to right. The right most Object has precedence. The target object will be mutated. Source objects will not be mutated.

Will throw a TypeError if the target prototype is not Object.prototype or null.

random()

random(min, max)

parametertypedescription
minNumberThe inclusive minimum.
maxNumberThe exclusive maximum.

Returns a random Integer from min (inclusive) to max (exclusive). Is automatically curried.

sampleOne()

sampleOne(list)

parametertypedescription
listArrayAn Array.

Returns a single random element from the given Array.

clamp()

clamp(min, max, n)

parametertypedescription
minNumberThe inclusive minimum.
maxNumberThe exclusive maximum.
nNumberThe Number to clamp.

Returns Number n only if it is greater then or equal to the minimum and less than the maximum. Otherwise, return the min or max as appropriate.

Copyright and License

Copyright: (c) 2017 - 2022 by Kris Walker (www.kixx.name)

Unless otherwise indicated, all source code is licensed under the MIT license. See MIT-LICENSE for details.