2020-03-29 13:43:52 +00:00
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home ](./index.md ) > [@apextoaster/js-utils ](./js-utils.md )
## js-utils package
## Classes
| Class | Description |
| --- | --- |
2020-03-31 13:29:47 +00:00
| [ArrayMapper ](./js-utils.arraymapper.md ) | Map an array of items into a map of arrays using the specified keys, able to < code > skip</ code > initial items and gather remaining items into a < code > rest</ code > key. |
2020-03-31 13:49:18 +00:00
| [Checklist ](./js-utils.checklist.md ) | Check whether items are included or not (blacklist or whitelist, depending on < code > mode</ code > ). |
| [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. |
2020-03-29 13:43:52 +00:00
2020-03-29 14:52:40 +00:00
## Enumerations
| Enumeration | Description |
| --- | --- |
| [ChecklistMode ](./js-utils.checklistmode.md ) | |
2020-03-29 13:43:52 +00:00
## Functions
| Function | Description |
| --- | --- |
2020-03-31 13:49:18 +00:00
| [concat(chunks) ](./js-utils.concat.md ) | Concatenate a list of buffers. |
| [constructorName(val) ](./js-utils.constructorname.md ) | Get the constructor name from an instance. |
2020-03-29 13:43:52 +00:00
| [countOf(val) ](./js-utils.countof.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. |
2020-03-31 13:49:18 +00:00
| [defaultWhen(condition, items) ](./js-utils.defaultwhen.md ) | Return the first element when < code > condition</ code > is true and the second element when < code > condition</ code > is false. |
2020-12-29 05:24:46 +00:00
| [defer(ms) ](./js-utils.defer.md ) | Resolve after a set amount of time. |
2020-03-29 13:43:52 +00:00
| [doesExist(val) ](./js-utils.doesexist.md ) | Check if a variable is not nil. |
2020-03-31 13:49:18 +00:00
| [encode(chunks, encoding) ](./js-utils.encode.md ) | Concatenate then encode a list of buffers. |
2020-03-31 23:47:44 +00:00
| [ensureArray(val) ](./js-utils.ensurearray.md ) | |
2020-06-30 13:16:22 +00:00
| [ensureArray(val) ](./js-utils.ensurearray_1.md ) | |
2020-03-31 13:29:47 +00:00
| [entriesOf(map) ](./js-utils.entriesof.md ) | Get entries of a map-like. |
2020-03-29 13:43:52 +00:00
| [filterNil(list) ](./js-utils.filternil.md ) | Remove any null or undefined items from the list. |
2020-03-31 13:49:18 +00:00
| [getConstructor(val) ](./js-utils.getconstructor.md ) | Get the constructor from an instance. |
2020-03-31 13:29:47 +00:00
| [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. |
2020-03-31 13:49:18 +00:00
| [getMethods(value) ](./js-utils.getmethods.md ) | Get the methods from an instance and its prototypes. |
2020-03-31 13:29:47 +00:00
| [getOrDefault(map, key, defaultValue) ](./js-utils.getordefault.md ) | Get a map key or default value when the key does not exist or is nil. |
2020-03-31 13:49:18 +00:00
| [getTestLogger(verbose) ](./js-utils.gettestlogger.md ) | Get a test logger. Returns a null logger unless < code > verbose</ code > is true or run under debug mode. |
2020-03-31 23:47:44 +00:00
| [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 < code > .length > 0</ code > , since it is also a typeguard: < code > if (hasItems(val)) else { val }</ code > will complain that < code > val</ code > is < code > never</ code > in the < code > else</ code > branch, since it was proven not to be an array by this function, even if < code > val</ code > is simply empty. |
| [hasItems(val) ](./js-utils.hasitems_1.md ) | |
2020-03-31 13:49:18 +00:00
| [isDebug() ](./js-utils.isdebug.md ) | Test if DEBUG mode is set.<!-- --> TODO: check variable value as well |
2020-03-31 02:31:51 +00:00
| [isNil(val) ](./js-utils.isnil.md ) | Check if a value is nil. |
2020-03-29 14:10:40 +00:00
| [leftPad(val, min, fill) ](./js-utils.leftpad.md ) | |
2020-03-29 13:43:52 +00:00
| [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. |
| [mergeList(parts) ](./js-utils.mergelist.md ) | Merge arguments, which may or may not be arrays, into one return that is definitely an array. |
2020-06-30 13:16:22 +00:00
| [mergeList(parts) ](./js-utils.mergelist_1.md ) | |
2020-03-31 13:29:47 +00:00
| [mergeMap(target, source) ](./js-utils.mergemap.md ) | Merge the < code > source</ code > map into the < code > target</ code > map, replacing keys that already exist. |
2020-03-31 13:49:18 +00:00
| [mustCoalesce(values) ](./js-utils.mustcoalesce.md ) | Return the first value that is not nil.<!-- --> @<!-- --> todo: rename to mustDefault |
2020-03-29 13:43:52 +00:00
| [mustExist(val) ](./js-utils.mustexist.md ) | Assert that a variable is not nil and return the value. |
| [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. |
2020-03-31 13:49:18 +00:00
| [normalizeMap(map) ](./js-utils.normalizemap.md ) | < b >< i > (BETA)</ i ></ b > Normalize a map-like of values into a dict of lists of strings. |
2020-03-31 13:29:47 +00:00
| [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. |
2020-06-30 13:16:22 +00:00
| [pushMergeMap(args) ](./js-utils.pushmergemap_1.md ) | |
2020-03-29 13:43:52 +00:00
| [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 ) | |
2020-03-31 13:49:18 +00:00
| [spyLogger(spies) ](./js-utils.spylogger.md ) | Create a spy logger using the provided methods, which returns itself as a child. |
2020-03-29 13:43:52 +00:00
| [timeout(ms, oper) ](./js-utils.timeout.md ) | Reject after a set amount of time if the original promise has not yet resolved. |
2020-03-29 14:10:40 +00:00
| [trim(val, max, tail) ](./js-utils.trim.md ) | |
2020-03-31 13:49:18 +00:00
| [waitForChild(child) ](./js-utils.waitforchild.md ) | Wait for a child process to exit, collecting output, errors, and exit status. |
2020-03-29 14:10:40 +00:00
| [writeValue(stream, value) ](./js-utils.writevalue.md ) | |
2020-03-29 13:43:52 +00:00
## Interfaces
| Interface | Description |
| --- | --- |
2020-03-29 14:10:40 +00:00
| [ArrayMapperOptions ](./js-utils.arraymapperoptions.md ) | |
2020-03-29 14:52:40 +00:00
| [ChecklistOptions ](./js-utils.checklistoptions.md ) | |
2020-03-29 14:10:40 +00:00
| [ChildOptions ](./js-utils.childoptions.md ) | |
| [ChildResult ](./js-utils.childresult.md ) | |
2020-03-29 13:43:52 +00:00
| [Dict ](./js-utils.dict.md ) | |
| [ExternalModule ](./js-utils.externalmodule.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 |
| --- | --- |
2020-03-29 14:10:40 +00:00
| [ChildSpawner ](./js-utils.childspawner.md ) | |
2020-03-29 13:43:52 +00:00
| [MapLike ](./js-utils.maplike.md ) | A < code > Map</ code > or dictionary object with string keys and < code > TVal</ code > values. |
| [ModuleCtor ](./js-utils.modulector.md ) | |
| [Nil ](./js-utils.nil.md ) | Unset value. |
| [Optional ](./js-utils.optional.md ) | Value that may be nil. |