@paravano/utils
This library contains es5 and es6 implementations in the deliverable and is fully tree-shakable for es6. Simply import your utils as named imports like this:
import { isNilOrEmpty, take } from '@paravano/utils';
Version: 1.16.1
Click on each function name for details and examples
Array
Function | Description |
---|---|
at | Gets the item at the specified index of an array |
count | Counts the number of items that match the condition |
drop | Immutably drops the first or last specified number of items of an array |
fill | Creates a new array of the specified size and fills each index with the item |
findIndexes | Finds the indexes of an array that match the predicate |
findLastIndex | Finds the last index in an array that matches the predicate |
first | Gets the first item of an array |
insertAt | Immutably inserts the item(s) at the specified index |
last | Gets the last item of an array |
limit | Immutably inserts an item into the array if the size of the array has not reached the specified limit |
limitItem | Immutably inserts an item into the array if the occurrence of the item in the array has not reached the specified limit |
move | Immutably moves an item from one index to another |
pad | Immutably pads the array with {size} number of {item} |
pluck | Gets an array of items given a set of indexes |
removeAt | Immutably removes an item at the specified index of the array |
removeIf | Immutably removes an item or items based on the predicate |
replaceAt | Immutably replaces an item at the specified index of the array |
replaceIf | Immutably replaces an item or items based on the predicate |
reverse | Immutably reverse an array |
search | Searches an array of objects and returns the items that match the search |
splice | Immutably adds/removes items from within the array |
take | Gets the first or last specified number of items of an array |
toggle | Immutably adds the item to the array if it's not already included; removes it if it's already included |
Function
Function | Description |
---|---|
executionTime | Calculates the execution time of a function in milliseconds |
pipe | Executes a queue of nested functions where the result of each function is fed as an argument into the subsequent function in the queue |
Keyboard
Function | Description |
---|---|
altKeyPressed | Verifies that the Alt key was pressed |
backspaceKeyPressed | Verifies that the Backspace key was pressed |
ctrlKeyPressed | Verifies that the Ctrl key was pressed |
deleteKeyPressed | Verifies that the Delete key was pressed |
downKeyPressed | Verifies that the down arrow key was pressed |
enterKeyPressed | Verifies that the Enter key was pressed |
escKeyPressed | Verifies that the Escape key was pressed |
insertKeyPressed | Verifies that the Insert key was pressed |
keyPressed | Verifies that at least one of the provided keys was pressed |
leftKeyPressed | Verifies that the left arrow key was pressed |
rightKeyPressed | Verifies that the right arrow key was pressed |
shiftKeyPressed | Verifies that the Shift key was pressed |
spaceKeyPressed | Verifies that the Space key was pressed |
tabKeyPressed | Verifies that the Tab key was pressed |
upKeyPressed | Verifies that the up arrow key was pressed |
Logic
Function | Description |
---|---|
all | Returns true if all values in {args} match the {check} |
any | Returns true if any value in {args} matches the {check} |
iif | Performs an inline if and returns either {whenTrue} or {whenFalse} |
or | Returns true if {value} has equality with any item in {args} |
Number
Function | Description |
---|---|
commaString | Creates a comma separated number string |
range | Determines whether or not the value is within the numeric range |
round | Rounds a number to a maximum specified number of significant digits |
Object
Function | Description |
---|---|
assign | Immutably assigns or adds (if it doesn't exist) the specified key and value to the input object |
get | Gets the value at the specified path of the object |
has | Checks if the path is a direct property of obj |
keys | Gets a string array of the object's own keys |
only | Creates an object from another with only the specified keys |
removeKeys | Immutably removes a set of key from an object |
sortKeys | Immutably sorts the object keys |
symbols | Gets a string array of the object's own symbols |
Sorting
Function | Description |
---|---|
sortReduce | Reduces to an object's key value for sorting |
sortReduceDate | Reduces an object's key value (Date or string representation of a date) to a sortable string |
sortReduceSemver | Reduces an object's key value (Semver) to a sortable string |
sortReduceString | Reduces an object's key value to a sortable string |
String
Function | Description |
---|---|
camel | Converts the string to camel case |
capitalize | Capitalizes every word in the string |
fuzzyMatch | Determines if a string has a fuzzy match to given search terms |
initials | Returns the person's initials |
kebab | Converts the string to kebab case |
leadingZero | Adds a leading zero to a value if the value is less than 10 |
remove | Removes a matching string or RegExp |
splitCamelCase | Splits a camel-cased string apart and capitalizes each word |
trim | Trims the start and the end of a string by whitespace (default), specified string, or array of possible strings |
trimEnd | Trims the end of a string by whitespace (default), specified string, or array of possible strings |
trimStart | Trims the start of a string by whitespace (default), specified string, or array of possible strings |
Type
Function | Description |
---|---|
is | Returns true if the type of value is the same as the provided type |
isArray | Returns true if the value is an array |
isBoolean | Returns true if the value is a boolean |
isDate | Returns true if the value is an instance of Date |
isFunction | Returns true if the value is a function |
isNumber | Returns true if the value is a number |
isObject | Returns true if the value is an object |
isString | Returns true if the value is a string |
isSymbol | Returns true if the value is a symbol |
type | Returns a string representation of the type which also differentiates between 'object', 'array', 'date' |
Value
Function | Description |
---|---|
defaultEmptyTo | Returns a default value if the original value is null, undefined, or empty |
defaultTo | Returns a default value if the original value is null or undefined |
isEmpty | Returns true if the value is empty |
isNil | Returns true if the value is null or undefined |
isNilOrEmpty | Returns true if the value is null, undefined, or empty |
isNotEmpty | Returns true if the value is NOT empty |
isNotNil | Returns true if the value is NOT null or undefined |
isNotNilOrEmpty | Returns true if the value is NOT null, undefined, or empty |
License
MIT
Michael Paravano Author
Dependencies
None