@svizzle/utils
v0.21.0
Published
Svizzle Utils is a library to help transforming data.
Downloads
43
Readme
@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/object
contains functions expecting an array and returning an object:Array -> Object
.For example,
makeAllOccurrences
expects anArray
of objects and returns anObject
of 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
makeOccurrences
expects twoArray
s 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-string
contains functions derived from theArray.prototype
hence expecting anArray
as a first argument (and potentially other arguments of different type) and returning aString
:(Array, *+) -> String
.For example,
join
expects anArray
and aString
and returns anString
.> join([0, 1, 2], '-') '0-1-2'
@svizzle/utils/array-[number-boolean]
contains functions expecting anArray
and returning a function expecting anNumber
and returning aBoolean
:Array -> (Number -> Boolean)
.For example,
makeIsWithinRange
expects a range (anArray
) and returns a function expecting aNumber
and returning if that number is within the given range or not (aBoolean
).> isWithinRange = makeIsWithinRange([0, 5]); > isWithinRange(2) true > isWithinRange(8) false