@svizzle/utils v0.21.0
@svizzle/utils
Svizzle Utils is a library to help transforming data types.
https://nestauk.github.io/svizzle
Installation
npm
npm i -S @svizzle/utils
browser
<script src="https://unpkg.com/@svizzle/utils">Directory structure
In this package, the modules path tries to convey the type signature of the functions in the module.
For example:
@svizzle/utils/array/objectcontains functions expecting an array and returning an object:Array -> Object.For example,
makeAllOccurrencesexpects anArrayof objects and returns anObjectof occurrences of all the keys.const objects = [{a: 1}, {a: 6, b: -1}, {a: 2, b: 0, c: 1}, {c: 4, e: 2}]; makeAllOccurrences(objects) // {a: 3, b: 2, c: 2, e: 1}Sometimes a function expects more than one argument: in this case the directory reports the type of the first argument.
For example
makeOccurrencesexpects twoArrays and return an object of occurrences of keys in the provided array containing the provided keys:> objects = [{a: 1}, {a: 6, b: -1}, {a: 2, b: 0, c: 1}, {c: 4, e: 2}]; > makeOccurrences(objects, ['a', 'b']) {a: 3, b: 2} > makeOccurrences(objects, ['c', 'e']) {c: 2, e: 1} > makeOccurrences(objects, ['k', 'a']) {k: 0, a: 3}Similarly,
@svizzle/utils/array_proto-stringcontains functions derived from theArray.prototypehence expecting anArrayas a first argument (and potentially other arguments of different type) and returning aString:(Array, *+) -> String.For example,
joinexpects anArrayand aStringand returns anString.> join([0, 1, 2], '-') '0-1-2'@svizzle/utils/array-[number-boolean]contains functions expecting anArrayand returning a function expecting anNumberand returning aBoolean:Array -> (Number -> Boolean).For example,
makeIsWithinRangeexpects a range (anArray) and returns a function expecting aNumberand returning if that number is within the given range or not (aBoolean).> isWithinRange = makeIsWithinRange([0, 5]); > isWithinRange(2) true > isWithinRange(8) false
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago