A loosely coupled set of tools and libraries for ES6 JavaScript applications.
$ npm install --save kixx-lib-es6
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(list)
parameter | type | description |
---|---|---|
list | Array | A list to filter |
Returns a new list with all the falsy values filtered out.
deepFreeze(object)
parameter | type | description |
---|---|---|
object | Object | An Object to deeply freeze. |
Returns the passed Object after recursively calling Object.freeze() deeply throughout.
mergeDeep(target, ...sources)
parameter | type | description |
---|---|---|
target | Object | The target object to merge into. |
sources | Objects | Source 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(min, max)
parameter | type | description |
---|---|---|
min | Number | The inclusive minimum. |
max | Number | The exclusive maximum. |
Returns a random Integer from min (inclusive) to max (exclusive). Is automatically curried.
sampleOne(list)
parameter | type | description |
---|---|---|
list | Array | An Array. |
Returns a single random element from the given Array.
clamp(min, max, n)
parameter | type | description |
---|---|---|
min | Number | The inclusive minimum. |
max | Number | The exclusive maximum. |
n | Number | The 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: (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.