Members
(constant) splitFirst
Split a string into two parts by the first occurance of a separator
(constant) splitLast
Split a string into two parts by the last occurance of a separator
Methods
Box() → {Array}
Box is a utility function that wrap an inner object and returns a reader proxy and a writer function.
Returns:
- Type:
-
Array
- Reader proxy and writer function
baseName(str, includePath) → {string}
Get basename with or without path.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
str |
string
|
Path |
includePath |
boolean
|
Include path in the result. |
Returns:
- Type:
-
string
dbgGetCallerFile(depth) → {string}
Get the nth call file name from callstack
- Source:
Parameters:
Name | Type | Default | Description |
---|---|---|---|
depth |
integer
|
1 |
the nth depth, 0 means the file call this function, usually depth 1 is most expected result |
defaultDeep(obj, …sources) → {object}
Fallback to default value according to the sequence of sources, if the value of a key in all sources is null or undefined.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
obj |
object
|
immutable object. |
|
sources |
object
|
<repeatable> |
esmCheck(obj) → {*}
Check whether the object is an ES module, if yes, return the default export.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
obj |
*
|
Returns:
- Type:
-
*
esmIsMain(entryMetaUrl) → {boolean}
Check if the current module is the main module.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
entryMetaUrl |
*
|
import.meta.url of the entry module. |
Returns:
- Type:
-
boolean
flattenObject(object, keyPathSep) → {object}
Convert a hierachy object into a flat object with the key path sperarated by a given string, default as ".".
- Source:
Parameters:
Name | Type | Default | Description |
---|---|---|---|
object |
*
|
||
keyPathSep |
*
|
. |
Returns:
- Type:
-
object
fxargs(args, types)
Function arguments extractor.
Parameters:
Name | Type | Description |
---|---|---|
args |
Array
|
Array of function arguments |
types |
Array
|
Array of types, with suffix |
Example
function withClient(...args) {
const [server, authenticator, testToRun, options] = fxargs(args, ['string?', 'string?', 'function', 'object?']);
// ...
}
1. withClient('http://localhost:3000', 'admin', (app) => {});
- server: 'http://localhost:3000'
- authenticator: 'admin'
- testToRun: (app) => {}
- options: undefined
2. withClient('http://localhost:3000', (app) => {});
- server: 'http://localhost:3000'
- authenticator: undefined
- testToRun: (app) => {}
- options: undefined
3. withClient((app) => {});
- server: undefined
- authenticator: undefined
- testToRun: (app) => {}
- options: undefined
isEmpty(value) → {boolean}
Check whether a value is empty, or an object is empty. Note: lodash's isEmpty does not check symbol properties. const key = Symbol('key'); const obj = { [key]: 'something' }; _.isEmpty(obj).should.be.true; isEmpty(obj).should.be.false;
- Source:
Parameters:
Name | Type | Description |
---|---|---|
value |
*
|
Returns:
- Type:
-
boolean
isInteger(value) → {boolean}
Check a number or string whether it is exactly an integer
- Source:
Parameters:
Name | Type | Description |
---|---|---|
value |
*
|
Returns:
- Type:
-
boolean
keyAt(object, index) → {String|*}
Returns the key at the specified index of an object.
Parameters:
Name | Type | Description |
---|---|---|
object |
Object
|
|
index |
integer
|
Returns:
- Type:
-
String
|*
mapFilter(collection, filterPredicate, mapper)
Map the filtered collection.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
collection |
object
|
|
filterPredicate |
function
|
|
mapper |
function
|
(async) shouldThrow_(fn, error)
Test if an async function throws an error
- Source:
Parameters:
Name | Type | Description |
---|---|---|
fn |
function
|
Function (async) that should throw an error |
error |
*
|
simpleCsvParser(str, optionsopt) → {array}
Parse csv string into array, simple implementation especially for one-line parsing. 23x faster than csv-parse for single line parsing 10x faster than csv-parse/sync for single line parsing
split + simpleCsvParser, however split('\n') is not good for massive data, should use stream reader instead 5x faster than csv-parse/sync for multiple lines parsing
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
options.delimiter |
string
|
<optional> |
',' | |
options.emptyAsNull |
boolean
|
<optional> |
false |
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
str |
string
|
||
options |
object
|
<optional> |
Returns:
- Type:
-
array
size(collection) → {number}
Get the size of a collection. Note: lodash's size does not check symbol properties and will return unicode length for strings.
Parameters:
Name | Type | Description |
---|---|---|
collection |
*
|
Returns:
- Type:
-
number
splitBaseAndExt(filePath)
Split the base and extension (including the ".") of a file path.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
filePath |
*
|
Returns:
(array) [base, ext]
valueAt(object, index) → {*}
Returns the value at the specified index of an array|object|string.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
object |
*
|
|
index |
integer
|
Returns:
- Type:
-
*