Skip to content

Latest commit

 

History

History
223 lines (170 loc) · 7.75 KB

README.md

File metadata and controls

223 lines (170 loc) · 7.75 KB

mostaza-utils

Our own utilities

Setup

This library is available on npm, install it with: npm install --save mostaza-utils

API

delayPromise.<void>

Simple syntactic sugar over setTimeout that looks good when using the async/await pattern.

formatMacAddressString

Formats a numeric string MAC address by adding the the right colon charactes.

numberToHexString

Transforms a number to its hexadecimal representation.

hexToNumberNumber

Transforms an hexadecimal numeric string to its numeric value.

appendArray.<any>

Returns a new array containing the contents of the array list, followed by the given element/s.

removeArray.<any>

Removes an element from the array (returns a new array). Doesn't work with collections (array of objects).

removeByArray.<any>

Iterates over elements of the array/collection, deleting the first element predicate returns truthy for and returning a new array. See Lodash.find() for more info on the quey param.

appendOrRemoveArray.<any>

Removes an element from an array if it exists in it, otherwise pushes it (aka toggles it). Returns a new array.

toIntNumber

Parses a string to an integer. Useful for converting environment variable (while maintaing the 0 values).

omitUndefinedObject

Creates a new object composed of all the properties of the input object that do not have an undefined value.

omitNullObject

Creates a new object composed of all the properties of the input object that do not have an null value.

omitNilObject

Creates a new object composed of all the properties of the input object that do not have an undefined or null value.

formatBytesString

Formats bytes in a readable string.

delay ⇒ Promise.<void>

Simple syntactic sugar over setTimeout that looks good when using the async/await pattern.

Kind: global variable Returns: Promise.<void> - A promise that resolves when the given time has ended.

Param Type Description
number ms Time to wait for in milliseconds.

formatMacAddress ⇒ String

Formats a numeric string MAC address by adding the the right colon charactes.

Kind: global variable Returns: String - The MAC address with the colon characters.

Param Type Description
plainMacAddress String The MAC address without the colon characters.

numberToHex ⇒ String

Transforms a number to its hexadecimal representation.

Kind: global variable Returns: String - The hexadecimal representation of the input number.

Param Type Description
num Number The number to convert.

hexToNumber ⇒ Number

Transforms an hexadecimal numeric string to its numeric value.

Kind: global variable Returns: Number - The numeric representation of the input string.

Param Type Description
hex String The hexadecimal string to convert.

append ⇒ Array.<any>

Returns a new array containing the contents of the array list, followed by the given element/s.

Kind: global variable Returns: Array.<any> - The new array.

Param Type Description
array Array.<any> The array.
el any/any The value/values to push.

remove ⇒ Array.<any>

Removes an element from the array (returns a new array). Doesn't work with collections (array of objects).

Kind: global variable Returns: Array.<any> - The new array.

Param Type Description
array Array.<any> The array.
el any The value to pull.

removeBy ⇒ Array.<any>

Iterates over elements of the array/collection, deleting the first element predicate returns truthy for and returning a new array. See Lodash.find() for more info on the quey param.

Kind: global variable Returns: Array.<any> - The new array (without the found elements).

Param Type Description
array Array.<any> The collection to inspect.
query Object The function invoked per iteration / Object used for the query.

appendOrRemove ⇒ Array.<any>

Removes an element from an array if it exists in it, otherwise pushes it (aka toggles it). Returns a new array.

Kind: global variable Returns: Array.<any> - The new array.

Param Type Description
array Array.<any> The array to inspect and update.
el any The value to push/pull.

toInt ⇒ Number

Parses a string to an integer. Useful for converting environment variable (while maintaing the 0 values).

Kind: global variable Returns: Number - The integer output.

Param Type Description
input Number | String The string to convert to integer.
defaultOutput Number Returned if the string is not a valid number.

omitUndefined ⇒ Object

Creates a new object composed of all the properties of the input object that do not have an undefined value.

Kind: global variable Returns: Object - A new object without properties with undefined values.

Param Type Description
obj Object The input object.

omitNull ⇒ Object

Creates a new object composed of all the properties of the input object that do not have an null value.

Kind: global variable Returns: Object - A new object without properties with null values.

Param Type Description
obj Object The input object.

omitNil ⇒ Object

Creates a new object composed of all the properties of the input object that do not have an undefined or null value.

Kind: global variable Returns: Object - A new object without properties with undefined and null values.

Param Type Description
obj Object The input object.

formatBytes ⇒ String

Formats bytes in a readable string.

Kind: global variable Returns: String - The formatted bytes.

Param Type Description
bytes Number The bytes to format.