[Home](./index.md) > [@apextoaster/js-utils](./js-utils.md)
## js-utils package
## Classes
| Class | Description |
| --- | --- |
| [ArrayMapper](./js-utils.arraymapper.md) | Map an array of items into a map of arrays using the specified keys, able to skip
initial items and gather remaining items into a rest
key. |
| [Checklist](./js-utils.checklist.md) | Check whether items are included or not. |
| [ChildProcessError](./js-utils.childprocesserror.md) | Error indicating that a child process exited with an error status. |
| [InvalidArgumentError](./js-utils.invalidargumenterror.md) | Error indicating that an invalid argument was passed to a function call. |
| [MissingKeyError](./js-utils.missingkeyerror.md) | Error indicating that a required key did not exist in a map-like. |
| [NotFoundError](./js-utils.notfounderror.md) | Error indicating that some value was not found. |
| [NotImplementedError](./js-utils.notimplementederror.md) | Error indicating that a function has not been implemented yet. |
| [TimeoutError](./js-utils.timeouterror.md) | Error indicating that a promise timed out. |
## Enumerations
| Enumeration | Description |
| --- | --- |
| [ChecklistMode](./js-utils.checklistmode.md) | Whether items should be checked for inclusion (allow list) or exclusion (deny list). |
## Functions
| Function | Description |
| --- | --- |
| [childResult(child)](./js-utils.childresult.md) | Wait for a child process to exit, collecting output, errors, and exit status. |
| [concat(chunks)](./js-utils.concat.md) | Concatenate a list of buffers. |
| [constructorName(val)](./js-utils.constructorname.md) | Get the constructor name from an instance. |
| [defaultWhen(condition, items)](./js-utils.defaultwhen.md) | Return the first element when condition
is true and the second element when condition
is false. |
| [defer(ms)](./js-utils.defer.md) | Resolve after a set amount of time. |
| [deferUntil(cb, step, max)](./js-utils.deferuntil.md) | Resolve if cb
returns true within max
tries, otherwise reject with a TimeoutError
. |
| [deferValue(ms, val)](./js-utils.defervalue.md) | Resolve with the given value, after a set amount of time. |
| [doesExist(val)](./js-utils.doesexist.md) | Check if a variable is some T
. |
| [encode(chunks, encoding)](./js-utils.encode.md) | Concatenate then encode a list of buffers. |
| [ensureArray(val)](./js-utils.ensurearray.md) | |
| [ensureArray(val)](./js-utils.ensurearray_1.md) | |
| [entriesOf(map)](./js-utils.entriesof.md) | Get entries of a map-like. |
| [filterZip(cb, l1)](./js-utils.filterzip.md) | Filter and zip some arrays. The cb
is called for each slice, which is kept if cb
returns true. |
| [filterZip(cb, l1, l2)](./js-utils.filterzip_1.md) | |
| [filterZip(cb, l1, l2, l3)](./js-utils.filterzip_2.md) | |
| [filterZip(cb, l1, l2, l3, l4)](./js-utils.filterzip_3.md) | |
| [getConstructor(val)](./js-utils.getconstructor.md) | Get the constructor from an instance. |
| [getHead(map, key)](./js-utils.gethead.md) | Get the first element from the specified key within a map of lists. |
| [getHeadOrDefault(map, key, defaultValue)](./js-utils.getheadordefault.md) | Get the first element from the specified key, within a map of lists, or a default value when the key does not exist or is nil. |
| [getMethods(value)](./js-utils.getmethods.md) | Get the methods from an instance and its prototypes. |
| [getOrDefault(map, key, defaultValue)](./js-utils.getordefault.md) | Get a map key or default value when the key does not exist or is nil. |
| [getTestLogger(verbose)](./js-utils.gettestlogger.md) | Get a test logger. Returns a null logger unless verbose
is true or run under debug mode. |
| [hasItems(val)](./js-utils.hasitems.md) |
Test if a value is an array with some items (length > 0
).
This is not a general replacement for .length > 0
, since it is also a typeguard: if (hasItems(val)) else { val }
will complain that val
is never
in the else
branch, since it was proven not to be an array by this function, even if val
is simply empty.
Array.isArray
with better readonly type handling. |
| [isArray(list)](./js-utils.isarray_1.md) | Wrapper for Array.isArray
with better readonly type handling. |
| [isEmpty(val)](./js-utils.isempty.md) | Check if a Maybe<Array<T>>
does in fact contain an array, and that array has items. |
| [isNil(val)](./js-utils.isnil.md) | Check if a value is nil. |
| [isNone(val)](./js-utils.isnone.md) | Typeguard to check if a Maybe
is None
(null or undefined). |
| [isSome(val)](./js-utils.issome.md) | Typeguard to check if a Maybe
is Some
value (not None
). |
| [leftPad(val, min, fill)](./js-utils.leftpad.md) | Prefix val
with fill
until it is at least min
characters. |
| [lengthOf(val)](./js-utils.lengthof.md) | Calculate the length of an array or value.
Arrays return their length, single values return 1, and nil values return 0. This counts the number of elements that setOrPush would add.
| | [makeDict(map)](./js-utils.makedict.md) | Turns a map or dict into a dict | | [makeMap(val)](./js-utils.makemap.md) | Clone a map or map-like object into a new map. | | [mergeArray(parts)](./js-utils.mergearray.md) | Merge arguments, which may or may not be arrays, into one return that is definitely an array. | | [mergeArray(parts)](./js-utils.mergearray_1.md) | | | [mergeArrays(parts)](./js-utils.mergearrays.md) | | | [mergeArrays(parts)](./js-utils.mergearrays_1.md) | | | [mergeMap(target, source)](./js-utils.mergemap.md) | Merge thesource
map into the target
map, replacing keys that already exist. |
| [mustCoalesce(values)](./js-utils.mustcoalesce.md) | Return the first value that is not nil. |
| [mustDefault(values)](./js-utils.mustdefault.md) | Return the first value that is some T
. Throw if they are all None
. |
| [mustExist(val, err)](./js-utils.mustexist.md) | Assert that a variable is not None
and return the value. Throw if it is None
. |
| [mustFind(list, predicate)](./js-utils.mustfind.md) | Find a value matching the given predicate or throw. |
| [mustGet(map, key)](./js-utils.mustget.md) | Get an element from a Map and guard against nil values. |
| [normalizeMap(map)](./js-utils.normalizemap.md) | Normalize a map-like of values into a dict of lists of strings. |
| [pairsToMap(pairs)](./js-utils.pairstomap.md) | Turns a list of name-value pairs into a map. |
| [pushMergeMap(args)](./js-utils.pushmergemap.md) | Merge the provided maps into a new map, merging keys that already exist by pushing new items. |
| [pushMergeMap(args)](./js-utils.pushmergemap_1.md) | Merge the provided maps into a new map, merging keys that already exist by pushing new items. |
| [removeNone(list)](./js-utils.removenone.md) | Remove any null or undefined items from the list. |
| [setOrPush(map, key, val)](./js-utils.setorpush.md) | Set a map key to a new array or push to the existing value. |
| [signal(signals)](./js-utils.signal.md) | Wait for an OS signal. |
| [sum(a, b)](./js-utils.sum.md) | Add numbers. |
| [timeout(ms, inner)](./js-utils.timeout.md) | Reject after a set amount of time if the original promise has not yet resolved. |
| [toArray(val)](./js-utils.toarray.md) | Copy an existing array-like or convert a single value to an array. |
| [toArray(val)](./js-utils.toarray_1.md) | Copy an existing readonly array-like or convert a single value to a readonly array. |
| [trim(val, max, tail)](./js-utils.trim.md) | Return the start of val
, up to max
characters. If val
is longer than max
and there is room, suffix with tail
. |
| [waitFor(cb, step, tries)](./js-utils.waitfor.md) | |
| [waitForChild(child)](./js-utils.waitforchild.md) | |
| [writeInput(stream, value)](./js-utils.writeinput.md) | |
| [writeValue(stream, value)](./js-utils.writevalue.md) | |
## Interfaces
| Interface | Description |
| --- | --- |
| [ArrayMapperOptions](./js-utils.arraymapperoptions.md) | |
| [ChecklistOptions](./js-utils.checklistoptions.md) | Mode of operation and items to check. |
| [ChildOptions](./js-utils.childoptions.md) | |
| [ChildResult](./js-utils.childresult.md) | |
| [Dict](./js-utils.dict.md) | |
## Variables
| Variable | Description |
| --- | --- |
| [SIGNAL\_RELOAD](./js-utils.signal_reload.md) | |
| [SIGNAL\_RESET](./js-utils.signal_reset.md) | |
| [SIGNAL\_STOP](./js-utils.signal_stop.md) | |
## Type Aliases
| Type Alias | Description |
| --- | --- |
| [AllowedBufferEncoding](./js-utils.allowedbufferencoding.md) | |
| [ChildSpawner](./js-utils.childspawner.md) | |
| [MapLike](./js-utils.maplike.md) | A Map
or dictionary object with string keys and TVal
values. |
| [Maybe](./js-utils.maybe.md) | Value that may be nil. |
| [Nil](./js-utils.nil.md) | Old name for None. |
| [None](./js-utils.none.md) | Unset value. |
| [Optional](./js-utils.optional.md) | Old name for Maybe. |