Function Reference
Assertions
Functions for testing the type of a value.
Function | Description |
---|---|
isBoolean(value) | Test if a value is a Boolean |
isString(value) | Test if a value is a String |
isNumber(value) | Test if a value is a Number |
isInteger(value) | Test if a value is an Integer |
isFloat(value) | Test if a value is a Float |
isArray(value) | Test if a value is an Array |
isFunction(value) | Test if a value is a Function |
isRegExp(value) | Test if a value is a RegExp |
isObject(value) | Test if a value is an Object |
isUndefined(value) | Test if a value is undefined |
isNull(value) | Test if a value is null |
hasValue(value) | Test if a value is not null or undefined |
noValue(value) | Test if a value is null or undefined |
haveValue(...values) | Test if all values are not null or undefined |
firstValue(...values) | Return the first value that is not null or undefined |
Numbers
Functions for working with numbers.
Function | Description |
---|---|
range(from, to, step=1) | Return an array of numbers in a range |
formatNumber(number, options) | Format a number using Intl.NumberFormat |
currency(number, options) | Format a number as a currency |
commas(n) | Add commas as thousand separators to a number |
setNumberDefaults(defaults) | Set the default formatting options for numbers |
Text
Functions for working with text.
Function | Description |
---|---|
splitLines(text) | Split text into lines |
splitList(value) | Split a whitespace delimited string into an array of words |
splitHash(value,set=true, hash={}) | Split a whitespace delimited string into a hash table object for quick lookup |
joinList(array, joint=' ', lastJoint=joint) | Join an array of words into a single string with separators |
joinListAnd(array, joint=', ', lastJoint=' and ') | Join an array of words using commas and 'and', e.g. David, Nigel and Derek |
joinListOr(array, joint=', ', lastJoint=' or ') | Join an array of words using commas and 'or', e.g. David, Nigel or Derek |
capitalise(word) / capitalize(word) | Capitalise a word |
capitaliseWords(string) / capitalizeWords(string) | Capitalise all words in a string |
snakeToStudly(snake) | Convert snake case to studly caps (e.g. foo_bar to FooBar ) |
snakeToCamel(snake) | Convert snake case to camel case (e.g. foo_bar to fooBar ) |
plural(singular) | Return the plural form of a singular word |
singular(plural) | Return the singular form of a plural word |
inflect(n, singular, plural, no='no') | Inflect a noun based on the plurality (e.g. no cats , 1 cat , 2 cats ) |
Inflect(n, singular, plural, no='No') | Inflect a noun with first capital letter (e.g. No cats , 1 cat , 2 cats ) |
format(message, data) | Format a string to fill in <placeholder> markers |
Objects
Functions for working with objects.
Function | Description |
---|---|
hash(source, options) | Modify (a.k.a "make a hash of") an object (a.k.a a "hash table") |
objMap(obj, fn) | Apply a function to each value in an object |
remove(object, key) | Remove a value from an object |
extract(object, keys, options) | Extract values from an object |
keys(object) | Return the keys for an object |
values(object) | Return the values for an object |
entries(object) | Return the entries ([key, value] pairs) for an object |
Functions
Functions for working with functions.
Function | Description |
---|---|
maybeFunction(fn, args) | Call a function or simply return a static value that isn't a function |
Select
Function for selecting things.
Function | Description |
---|---|
[selector(spec) (select#selector) | Factory to create a function that will select values using various criteria |
Sort
Functions for sorting arrays of objects.
Function | Description |
---|---|
stringSort(field) | Sort using a string field |
numberSort(field) | Sort using a numeric field |
integerSort(field) | Sort using an integer field |
booleanSort(field) | Sort using a boolean field |
multiSort(fields) | Sort using multiple fields |
stringField(obj,field) | Extract a string field from an object |
numberField(obj,field) | Extract a number field from an object |
integerField(obj,field) | Extract an integer field from an object |
booleanField(obj,field) | Extract a boolean field from an object |
descendingOrder(sortFn) | Sort in descending order |
ascendingOrder(sortFn) | Sort in ascending order |
Timing
Timing-related function.
Function | Description |
---|---|
debounce(func, timeout=300) | Create a debouncing function |
sleep(ms) | Delay function which waits before resolving |
Errors
Functions for throwing errors.
Function | Description |
---|---|
fail(message) | Throw an error |
failMsg(message, data) | Throw an error using a message format string |
rethrow(error) | Rethrow an error |
Miscellaneous
Miscellaneous functions.
Function | Description |
---|---|
doNothing() | Function that does nothing |
defaultLocale() | Return the default locale |