Metarhia Common Library
npm install @metarhia/common





``bash`
$ npm install @metarhia/common
- splitAt
- shuffle
- sample
- range
- sequence
- last
- pushSame
- checkLogin
- checkPassword
- checkLoginPassword
- BTree
- BTree.prototype.constructor
- BTree.prototype.get
- BTree.prototype.iterator
- BTree.prototype.remove
- BTree.prototype.set
- cache
- Cache
- Cache.prototype.constructor
- Cache.prototype.add
- Cache.prototype.clr
- Cache.prototype.del
- falseness
- trueness
- emptiness
- nop
- noop
- once
- unsafeCallback
- safeCallback
- requiredCallback
- onceCallback
- safeFunction
- unsafeFunction
- id
- asyncId
- isScalar
- copy
- clone
- duplicate
- getByPath
- setByPath
- deleteByPath
- merge
- mergeObjects
- Enum
- Enum.from
- Enum.prototype.constructor
- forwardEvents
- emitter
- EnhancedEmitter
- EnhancedEmitter.prototype.constructor
- EnhancedEmitter.prototype.emit
- EnhancedEmitter.prototype.forward
- Flags
- Flags.from
- Flags.prototype.constructor
- partial
- omap
- compose
- maybe
- zip
- replicate
- zipWith
- curryUntil
- curryN
- curryTwice
- curry
- applyArgs
- either
- restLeft
- mkdirp
- mkdirpPromise
- rmdirp
- rmRecursive
- rmRecursivePromise
- generateKey
- generateGUID
- generateToken
- crcToken
- validateToken
- hash
- validateHash
- generateStorageKey
- idToChunks
- idToPath
- pathToId
- Int64
- Int64.add
- Int64.and
- Int64.cmp
- Int64.div
- Int64.mod
- Int64.mult
- Int64.not
- Int64.one
- Int64.or
- Int64.shiftLeft
- Int64.shiftRight
- Int64.sub
- Int64.xor
- Int64.zero
- Int64.prototype.constructor
- Int64.prototype.add
- Int64.prototype.and
- Int64.prototype.dec
- Int64.prototype.inc
- Int64.prototype.not
- Int64.prototype.or
- Int64.prototype.shiftLeft
- Int64.prototype.shiftRight
- Int64.prototype.shiftRightArithmetic
- Int64.prototype.shiftRightLogical
- Int64.prototype.sub
- Int64.prototype.toInt32
- Int64.prototype.toJSON
- Int64.prototype.toPostgres
- Int64.prototype.toString
- Int64.prototype.toUint32
- Int64.prototype.xor
- Iterator
- Iterator.indices
- Iterator.range
- Iterator.zip
- Iterator.prototype.constructor
- Iterator.prototype.apply
- Iterator.prototype.chain
- Iterator.prototype.chainApply
- Iterator.prototype.collectTo
- Iterator.prototype.collectWith
- Iterator.prototype.count
- Iterator.prototype.each
- Iterator.prototype.enumerate
- Iterator.prototype.every
- Iterator.prototype.filter
- Iterator.prototype.filterMap
- Iterator.prototype.find
- Iterator.prototype.findCompare
- Iterator.prototype.firstNonNullable
- Iterator.prototype.flat
- Iterator.prototype.flatMap
- Iterator.prototype.forEach
- Iterator.prototype.groupBy
- Iterator.prototype.includes
- Iterator.prototype.join
- Iterator.prototype.last
- Iterator.prototype.map
- Iterator.prototype.max
- Iterator.prototype.min
- Iterator.prototype.next
- Iterator.prototype.partition
- Iterator.prototype.reduce
- Iterator.prototype.skip
- Iterator.prototype.skipWhile
- Iterator.prototype.some
- Iterator.prototype.someCount
- Iterator.prototype.take
- Iterator.prototype.takeWhile
- Iterator.prototype.toArray
- Iterator.prototype.toObject
- Iterator.prototype.zip
- iter
- iterEntries
- iterKeys
- iterValues
- cryptoPrefetcher
- random
- cryptoRandom
- methods
- properties
- ipToInt
- localIPs
- parseHost
- override
- mixin
- Pool
- Pool.prototype.constructor
- Pool.prototype.get
- Pool.prototype.put
- sortComparePriority
- sortCompareDirectories
- sortCompareByName
- MemoryWritable
- MemoryWritable.prototype.constructor
- MemoryWritable.prototype.getData
- subst
- htmlEscape
- fileExt
- removeExt
- spinalToCamel
- escapeRegExp
- newEscapedRegExp
- addTrailingSlash
- stripTrailingSlash
- dirname
- capitalize
- between
- removeBOM
- arrayRegExp
- section
- rsection
- split
- rsplit
- normalizeEmail
- isTimeEqual
- nowDate
- nowDateTime
- Uint64
- Uint64.add
- Uint64.and
- Uint64.cmp
- Uint64.div
- Uint64.mod
- Uint64.mult
- Uint64.not
- Uint64.or
- Uint64.shiftLeft
- Uint64.shiftRight
- Uint64.sub
- Uint64.xor
- Uint64.prototype.constructor
- Uint64.prototype.add
- Uint64.prototype.and
- Uint64.prototype.dec
- Uint64.prototype.inc
- Uint64.prototype.not
- Uint64.prototype.or
- Uint64.prototype.shiftLeft
- Uint64.prototype.shiftRight
- Uint64.prototype.sub
- Uint64.prototype.toJSON
- Uint64.prototype.toPostgres
- Uint64.prototype.toString
- Uint64.prototype.toUint32
- Uint64.prototype.xor
- duration
- durationToString
- bytesToSize
- sizeToBytes
- safe
- captureMaxStack
- callerFilename
- callerFilepath
- index: [][number] index defining end of first part and start ofarray
second
- : [][array] to be split
_Returns:_ [][array] tuple with two parts of the array
Split array into two parts
- arr: [][array]
_Returns:_ [][array]
Shuffle an array
- arr: [][array]
_Returns:_
Random element from array
- from: [][number] range startto
- : [][number] range end
_Returns:_ [][array]
Generate int array from given range
_Example:_
`js`
range(1, 5);
_Result:_
`js`
[1, 2, 3, 4, 5];
- seq: [][array]max
- : [][number] (optional), max
_Returns:_ [][array]
Generate int array from sequence syntax
_Example:_
`js`
list: sequence([81, 82, 83]);
_Result:_
`js`
[81, 82, 83];
_Example:_
`js`
range from..to: sequence([81,,83]) = [81, 82, 83];
_Result:_
`js`
[81, 82, 83];
_Example:_
`js`
range from..count: sequence([81, [3]]) = [81, 82, 83];
_Result:_
`js`
[81, 82, 83];
_Example:_
`js`
range from..max-to: sequence([81, [-2]], 5) = [81, 82, 83];
_Result:_
`js`
[81, 82, 83];
- arr: [][array]
_Returns:_ element
Get last element of array
- arr: [][array]n
- : [][number]value
- :
_Returns:_ [][number] new value of arr.length
Push single value multiple times
- login: [][string] login to testrequired
- : [][array] required tests configsoptional
- : [][array] optional tests configs, defalult: []
_Returns:_
Function that tests the login
- password: [][string] password to testrequired
- : [][array] required tests configsoptional
- : [][array] optional tests configs, default: []
_Returns:_
Function that tests the password
- login: [][string] login to testpassword
- : [][string] password to testrequired
- : [][array] required tests configsoptional
- : [][array] optional tests configs, default: []
_Returns:_
Function that tests the login with password
#### BTree.prototype.constructor(degree = DEFAULT\_DEGREE)
#### BTree.prototype.get(key)
#### BTree.prototype.iterator(start, finish)
#### BTree.prototype.remove(key)
#### BTree.prototype.set(key, data)
_Returns:_
Create Cache, enhanced Map
#### Cache.prototype.constructor()
#### Cache.prototype.add(key, val)
- key: [][string] keyval
- : associated value
Add key-value pair to cache
#### Cache.prototype.clr(prefix\[, fn\])
- prefix: [][string] to compare with beginning of the keyfn
- : [][function] (optional)key
- : [][string] keyval
- : associative value to be called on each key
Clear cache elements that start with prefix
#### Cache.prototype.del(key)
- key: [][string] key
Delete cache element
_Returns:_ [][boolean] always false
Empty function
_Returns:_ [][boolean] always true
Empty function
Empty function
- callback: [][function] callback to be called with (null)
Empty asynchronous callback-last single-argument function
- empty: incoming value to be ignoredcallback
- : [][function] callback to be called with (null, null)
Empty asynchronous callback-last double-argument function
- fn: [][function] (optional)
_Returns:_ [][function] function(...args) wrapped callback
- args: [][array]
Wrap function: call once, not null
- args: [][array] arguments
_Returns:_ [][function]|[][null] callback if any
Extract callback function
It's unsafe: may return null, allows multiple calls
- args: [][array] arguments
_Returns:_ [][function] callback or common.emptiness if there is no
callback
Extract callback
- args: [][array] arguments
_Returns:_ [][function] extracted callback
Extract callback
_Throws:_ [][typeerror] if there is no callback
- args: [][array] arguments
_Returns:_ [][function] callback or common.emptiness if there is no
callback
Extract callback and make it safe
Wrap callback with once()
- fn: [][function]
_Returns:_ [][function] function or common.emptiness if fn is not
a function
Check function and make it safe
- fn: [][function]
_Returns:_ [][function]|[][null] function or null if fn is
not a function
Check function
- x: incoming value which will be returned
_Returns:_ incoming value
Identity function
- x: incoming value which will be returned into the callbackcallback
- : [][function] callback to be called with first argumenterr
- : [][null]data
- :
Async identity function
- value:
_Returns:_ [][boolean]
Check if value is scalar
- ds: [
_Returns:_ [
Copy dataset (copy objects to new array)
- obj: [
_Returns:_ [
Clone object or array
- obj: [
_Returns:_ [
Duplicate object or array (properly handles prototype and circular links)
- data: [
_Returns:_ value
Read property by dot-separated path
- data: [
Set property by dot-separated path
- data: [
_Returns:_ [][boolean]
Delete property by dot-separated path
- args: [][array] arrays with elements to be merged
_Returns:_ [][array]
Distinctly merge multiple arrays
- merger: [][function]key
- : [][string] current merging key...values
- : values under keyobjs
- : [
_Returns:_ [
Merge multiple objects with merger
#### Enum.NaE
- Not an Enum
#### Enum.from(...args)
#### Enum.prototype.constructor()
- from: [][eventemitter] to listen for eventto
- : [][eventemitter] to emit event onevents
- : [][string]|[
Forward events from one EventEmitter to another
_Example:_
`js`
forwardEvents(from, to);
_Example:_
`js`
forwardEvents(from, to, 'eventName');
_Example:_
`js`
forwardEvents(from, to, { eventName: 'newEventName' });
_Example:_
`js`
forwardEvents(from, to, ['eventName1', 'eventName2']);
_Returns:_ [][eventemitter]
Create EnhancedEmitter, enhanced EventEmitter
with wildcard and forward method
#### EnhancedEmitter.prototype.constructor()
#### EnhancedEmitter.prototype.emit(...args)
- args: [][array] arguments to be passed
Call listener with provided arguments
#### EnhancedEmitter.prototype.forward(to, events)
- to: [][eventemitter] to emit event onevents
- : [][string]|[
Forward events from one EventEmitter to another
#### Flags.from(...args)
#### Flags.prototype.constructor(...args)
- fn: [][function]args
- : [][array] arguments to be applied
_Returns:_ [][function] function(...rest)
- rest: [][array] arguments
Partially apply arguments to function
- mapFn: [][function] to apply to every field valueobj
- : [
_Returns:_ [
Map object fields with provided function
- fns: [][array] functions to be composed
_Returns:_ [][function] function(...args), composed
- args: [][array] arguments to be passed to the first function
Compose multiple functions into one
- fn: [][function]defVal
- : default valuevalue
- : (optional), value
_Returns:_ result of fn or defVal
Apply given function to value or default value
- arrays: [][array] arrays to be zipped
_Returns:_ [][array] length is minimal of input arrays length, element
with index i of resulting array is array with elements with index i from input
array
Zip several arrays into one
- count: [][number] new array lengthelem
- : value to replicate
_Returns:_ [][array] replicated
Create array of replicated values
- fn: [][function] for zipping elements with index iarrays
- : [][array] arrays to be zipped
_Returns:_ [][array] zipped, element with index i of resulting array is
result of fn called with arguments from arrays
Zip arrays using specific function
- condition: [][function] returns: [][boolean]argsI
- : [][array] arguments for i-th curryingargsParts
- : [][array] of args given for currying from first tofn
i-th currying
- : [][function] to be curriedargs
- : [][array] arguments for fn
_Returns:_ [][function] function(...args), curried
- args: [][array] arguments
Curry function until the condition is met
- fn: [][function] to be curriedcount
- : [][number] of times function should be curriedargs
- : [][array] arguments for first currying
_Returns:_ [][function] curried given times count
Curry fn count times, first curry uses args for first currying
- fn: [][function] to be curried
_Returns:_ [][function] to pass arguments that returns curried fn
Curry function curry with fn
- fn: [][function] to be curriedparam
- : [][array] arguments to the function
_Returns:_ [][function] function(...args), curried
Curry function with given arguments
- args: [][array] arguments to save in closure
_Returns:_ [][function] returns: , result of fn(...args)
- fn: [][function] to be applied saved arguments
Apply arguments
- fn: [][function] to be called
_Returns:_ [][function] function(...args), returns: , resultfn(arg)
of , where arg - first valid element of args
- args: [][array] arguments to iterate
Get first not errored result of fn
_Throws:_ [][error] if fn throws it
- fn: [][function] function(args, ...namedArgs, callback)args
- : [][array] rest of spreadArgs created by excluding namedArgsnamedArgs
- : [][array] first values of spreadArgs, length is basedcallback
upon interface of fn
- : [][function] callback, last argument of spreadArgs
_Returns:_ [][function] function(...spreadArgs)
- spreadArgs: [][array] arguments to be added
Rest left, transform function
- path: [][string] path to a file or directory to be removedcallback
- : [][function] callback
Recursively remove directory
- path: [][string] path to a file or directory to be removed
_Returns:_ [][promise]
Recursively remove directory
- length: [][number] key lengthpossible
- : [][string] with possible characters
_Returns:_ [][string] key
Generate random key
_Returns:_ [][string] GUID
Generate an RFC4122-compliant GUID (UUID v4)
- secret: [][string]characters
- : [][string]length
- : [][number]
_Returns:_ [][string] token
Generate random Token
- secret: [][string]key
- : [][string]
_Returns:_ [][string] crc
Calculate Token crc
- secret: [][string]token
- : [][string]
_Returns:_ [][boolean]
Validate Token
- password: [][string]salt
- : [][string]
_Returns:_ [][string] hash
Calculate hash with salt
- hashValue: [][string]password
- : [][string]salt
- : [][string]
_Returns:_ [][boolean]
Validate hash
_Returns:_ [][string] [folder1, folder2, code]
Generate file storage key
- id: [][number]
_Returns:_ [][array] minimal length is 2 which contains hex strings
with length of 4
Convert id to array of hex strings
- id: [][number]
_Returns:_ [][string]
Convert id to file path
- path: [][string]
_Returns:_ [][number]
Convert file path to id
#### Int64.add(a, b)
#### Int64.and(a, b)
#### Int64.cmp(a, b)
#### Int64.div(a, b)
#### Int64.mod(a, b)
#### Int64.mult(a, b)
#### Int64.not(a)
#### Int64.one()
#### Int64.or(a, b)
#### Int64.shiftLeft(a, b)
#### Int64.shiftRight(a, b)
#### Int64.sub(a, b)
#### Int64.xor(a, b)
#### Int64.zero()
#### Int64.prototype.constructor(value)
#### Int64.prototype.add(b)
#### Int64.prototype.and(b)
#### Int64.prototype.dec()
#### Int64.prototype.inc()
#### Int64.prototype.not()
#### Int64.prototype.or(b)
#### Int64.prototype.shiftLeft(b)
#### Int64.prototype.shiftRight(b)
#### Int64.prototype.shiftRightArithmetic(b)
#### Int64.prototype.shiftRightLogical(b)
#### Int64.prototype.sub(b)
#### Int64.prototype.toInt32()
#### Int64.prototype.toJSON()
#### Int64.prototype.toPostgres()
#### Int64.prototype.toString(radix = 10)
#### Int64.prototype.toUint32()
#### Int64.prototype.xor(b)
#### Iterator.indices(arr)
- arr: [][array] array-like object to create indices from
_Returns:_
Create iterator over indices of an array
#### Iterator.range(start, stop\[, step\])
- start: [][number]stop
- : [][number]step
- : [][number] (optional), default: 1
_Returns:_
Create iterator iterating over the range
#### Iterator.zip(...iterators)
- iterators: [][array]
_Returns:_
Create iterator by zipping multiple provided iterators into one
#### Iterator.prototype.constructor(base)
#### Iterator.prototype.apply(fn)
- fn: [][function]this
- :
_Returns:_ the result of fn(this) call.
Call a function with this. Will be equivalent to calling fn(it).
#### Iterator.prototype.chain(...iterators)
#### Iterator.prototype.chainApply(fn)
- fn: [][function]this
- :
_Returns:_ result of fn(this) wrapped in an Iterator.
Call a function with this and wrap the result in an Iterator.
_Example:_
`js`
iter([1, 2])
.chainApply(([a, b]) => [a + b, a - b])
.join(', ');
_Result:_
`js`
'3, -1';
#### Iterator.prototype.collectTo(CollectionClass)
#### Iterator.prototype.collectWith(obj, collector)
#### Iterator.prototype.count()
#### Iterator.prototype.each(fn, thisArg)
#### Iterator.prototype.enumerate()
#### Iterator.prototype.every(predicate, thisArg)
#### Iterator.prototype.filter(predicate, thisArg)
#### Iterator.prototype.filterMap(mapper\[, thisArg\[, filterValue\]\])
- mapper: [][function] function that maps values and returnsfilterValue
either new value that will be the next value of the new iterator or
that will be ignored.value
- : iterator elementthisArg
- : value to be used as this when calling mapperfilterValue
- : value to filter out mapper results.
Creates an iterator that both filters and maps with the passed mapper.
This iterator will call mapper on each element and if mapper returns NOTfilterValue it will be returned, otherwise it is ignored.
#### Iterator.prototype.find(predicate, thisArg)
#### Iterator.prototype.findCompare(comparator\[, accessor\[, thisArg\]\])
- comparator: [][function] returns true if new value should becurrValue
accepted
- : current value, starts with undefinednextValue
- : next value
- _Returns:_ [][boolean] true if next value should be acceptedaccessor
- : [][function] gets value to compare by, currentvalue
iterator value is used by default
- : current iterator value
- _Returns:_ value to compare bythisArg
- : value to be used as this when calling accessor andcomparator
_Returns:_ last iterator value where comparator returned true,
[][undefined] by default
Find value in this iterator by comparing every value with
the found one using comparator
#### Iterator.prototype.firstNonNullable(\[defaultValue\])
- defaultValue: value to return if this iterator doesn't have
non-nullable values
- _Returns:_ first non-nullable value or
Finds first non-nullable value in this iterator
#### Iterator.prototype.flat(depth = 1)
#### Iterator.prototype.flatMap(mapper, thisArg)
#### Iterator.prototype.forEach(fn, thisArg)
#### Iterator.prototype.groupBy(classifier\[, thisArg\])
- classifier: [][function] gets value to group byvalue
- : current iterator value
- _Returns:_ value to group bythisArg
- : value to be used as this when calling classifier
- _Returns:_ [
Consumes an iterator grouping values by keys
#### Iterator.prototype.includes(element)
#### Iterator.prototype.join(sep = ', ', prefix = '', suffix = '')
#### Iterator.prototype.last(\[defaultValue\])
- defaultValue: value to be used if iterator is empty
_Returns:_ |[][undefined] last value of this iterator or
[][undefined]
Consumes an iterator returning last iterator value
#### Iterator.prototype.map(mapper, thisArg)
#### Iterator.prototype.max(\[accessor\[, thisArg\]\])
- accessor: [][function] gets value to compare by, currentvalue
iterator value is used by default
- : current iterator value
- _Returns:_ value to compare bythisArg
- : value to be used as this when calling accessor
_Returns:_ element with maximum value or [][undefined] if iterator
is empty
Find the maximum value in this iterator
#### Iterator.prototype.min(\[accessor\[, thisArg\]\])
- accessor: [][function] gets value to compare by, currentvalue
iterator value is used by default
- : current iterator value
- _Returns:_ value to compare bythisArg
- : value to be used as this when calling accessor
_Returns:_ element with minimum value or [][undefined] if iterator
is empty
Find the minimum value in this iterator
#### Iterator.prototype.next()
#### Iterator.prototype.partition(predicate\[, thisArg\])
- predicate: [][function] function returns a value to partitionvalue
this iterator
- : current iterator element
- _Returns:_ [][boolean]|[][number] key denotingthisArg
resulting partition this value will be assigned to. Number denotes index in
the resulting array. Boolean will be cast to number
- : value to be used as this when calling predicate
- _Returns:_ [][array] array of partitions (arrays), will always have
at least 2 arrays in it
Consumes an iterator, partitioning it into Arrays
#### Iterator.prototype.reduce(reducer, initialValue)
#### Iterator.prototype.skip(amount)
#### Iterator.prototype.skipWhile(predicate, thisArg)
#### Iterator.prototype.some(predicate, thisArg)
#### Iterator.prototype.someCount(predicate, count, thisArg)
#### Iterator.prototype.take(amount)
#### Iterator.prototype.takeWhile(predicate, thisArg)
#### Iterator.prototype.toArray()
#### Iterator.prototype.toObject()
Transforms an iterator of key-value pairs into an object.
This is similar to what [Object.fromEntries()][object.fromentries()] would
offer.
#### Iterator.prototype.zip(...iterators)
- bufSize: [][number] size in bytes of the buffer to preallocatevalueSize
- : [][number] size in bytes of the produced chunks
Create prefetcher to use when crypto.randomBytes is required to generate
multiple same-size values. bufSize must be a multiple of valueSize for this
to work.
- min: [][number] range startmax
- : [][number] range end
_Returns:_ [][number]
Generate random integer value in given range
_Returns:_ [][number]
Generate random number in the range from 0 inclusive up to
but not including 1 (same as Math.random), using crypto-secure number generator.
- iface: [
_Returns:_ [][string] method names
List method names
- iface: [
_Returns:_ [][string] property names
List property names
- ip: [][string] (optional), default: '127.0.0.1', IP address
_Returns:_ [][number]
Convert IP string to number
_Returns:_ [][string]
Get local network interfaces
- host: [][string] host or empty string, may contain :port
_Returns:_ [][string] host without port but not empty
Parse host string
- obj: [
Override method: save old to fn.inherited
Previous function will be accessible by obj.fnName.inherited
- target: [
Mixin for ES6 classes without overriding existing methods
#### Pool.prototype.constructor(factory = null)
#### Pool.prototype.get()
#### Pool.prototype.put(value)
- priority: [][string] with prioritys1
- : [][string] to compares2
- : [][string] to compare
_Returns:_ [][number]
Compare for array.sort with priority
_Example:_
`js`
files.sort(common.sortComparePriority);
- a: [][string] to compareb
- : [][string] to compare
_Returns:_ [][number]
Compare for array.sort, directories first
_Example:_
`js`
files.sort(sortCompareDirectories);
- a: [][object] { name } to compareb
- : [][object] { name } to compare
_Returns:_ [][number]
Compare for array.sort
_Example:_
`js`
files.sort(sortCompareByName);
#### MemoryWritable.prototype.constructor(\[sizeLimit\])
- sizeLimit: [][number]|[][string] limit of the internalcommon.bytesToSize()
buffer size specified as number in bytes or as string in format supported by
. Defaults to 8 MB
#### async MemoryWritable.prototype.getData(\[encoding\])
- encoding: [][string] encoding to convert the resulting data to,
must be a valid [][buffer] encoding
_Returns:_ [][promise]
Return a Promise that will be resolved with all the written data once it
becomes available.
- tpl: [][string] template bodydata
- : [][object] hash, data structure to visualizedataPath
- : [][string] current position in data structureescapeHtml
- : [][boolean] escape html special characters if true
_Returns:_ [][string]
Substitute variables
- content: [][string] to escape
_Returns:_ [][string]
Escape html characters
_Example:_
`js`
htmlEscape('5>=5') = '5<=5';
- fileName: [][string] file name
_Returns:_ [][string]
Extract file extension in lower case without dot
_Example:_
`js`
fileExt('/dir/file.txt');
_Result:_
`js`
'txt';
- fileName: [][string] file name
_Returns:_ [][string]
Remove file extension from file name
_Example:_
`js`
fileExt('file.txt');
_Result:_
`js`
'file';
- name: [][string]
_Returns:_ [][string]
Convert spinal case to camel case
- s: [][string]
_Returns:_ [][string]
Escape regular expression control characters
_Example:_
`js`
escapeRegExp('/path/to/res?search=this.that');
- s: [][string]
_Returns:_ [][regexp]
Generate escaped regular expression
- s: [][string]
_Returns:_ [][string]
Add trailing slash at the end if there isn't one
- s: [][string]
_Returns:_ [][string]
Remove trailing slash from string
- filePath: [][string]
_Returns:_ [][string]
Get directory name with trailing slash from path
- s: [][string]
_Returns:_ [][string]
Capitalize string
- s: [][string] sourceprefix
- : [][string] before needed fragmentsuffix
- : [][string] after needed fragment
_Returns:_ [][string]
Extract substring between prefix and suffix
- s: [][string] possibly starts with BOM
_Returns:_ [][string]
Remove UTF-8 BOM
- items: [][string]
_Returns:_ [][regexp]
Generate RegExp from array with '*' wildcards
_Example:_
`js`
['/css/*', '/index.html'];
- s: [][string]separator
- : [][string] or char
_Returns:_ [][string]
Split string by the first occurrence of separator
_Example:_
`js`
rsection('All you need is JavaScript', 'is');
_Result:_
`js`
['All you need ', ' JavaScript'];
- s: [][string]separator
- : [][string] or char
_Returns:_ [][string]
Split string by the last occurrence of separator
_Example:_
`js`
rsection('All you need is JavaScript', 'a');
_Result:_
`js`
['All you need is Jav', 'Script'];
- s: [][string]separator
- : [][string] (optional), default: ','limit
- : [][number] (optional), default: -1, max length of result
array
_Returns:_ [][string]
Split string by multiple occurrence of separator
_Example:_
`js`
split('a,b,c,d');
_Result:_
`js`
['a', 'b', 'c', 'd'];
_Example:_
`js`
split('a,b,c,d', ',', 2);
_Result:_
`js`
['a', 'b'];
- s: [][string]separator
- : [][string] (optional), default: ','limit
- : [][number] (optional), default: -1, max length of result
array
_Returns:_ [][string]
Split string by multiple occurrences of separator
_Example:_
`js`
split('a,b,c,d', ',', 2);
_Result:_
`js`
['c', 'd'];
- email: [][string] email address to normalize
_Returns:_ [][string] normalized email address
Normalize email address according to OWASP recommendations
- time1: [][string] time or millisecondstime2
- : [][string] time or milliseconds
_Returns:_ [][boolean]
Compare time1 and time2
_Example:_
`js`
isTimeEqual(sinceTime, buffer.stats.mtime);
- date: [][date] (optional), default: new Date()
_Returns:_ [][string]
Get current date in YYYY-MM-DD format
- date: [][date] (optional), default: new Date()
_Returns:_ [][string]
Get current date in YYYY-MM-DD hh:mm format
#### Uint64.add(a, b)
#### Uint64.and(a, b)
#### Uint64.cmp(a, b)
#### Uint64.div(a, b)
#### Uint64.mod(a, b)
#### Uint64.mult(a, b)
#### Uint64.not(a)
#### Uint64.or(a, b)
#### Uint64.shiftLeft(a, b)
#### Uint64.shiftRight(a, b)
#### Uint64.sub(a, b)
#### Uint64.xor(a, b)
#### Uint64.prototype.constructor(value)
#### Uint64.prototype.add(b)
#### Uint64.prototype.and(b)
#### Uint64.prototype.dec()
#### Uint64.prototype.inc()
#### Uint64.prototype.not()
#### Uint64.prototype.or(b)
#### Uint64.prototype.shiftLeft(b)
#### Uint64.prototype.shiftRight(b)
#### Uint64.prototype.sub(b)
#### Uint64.prototype.toJSON()
#### Uint64.prototype.toPostgres()
#### Uint64.prototype.toString(radix = 10)
#### Uint64.prototype.toUint32()
#### Uint64.prototype.xor(b)
- s: [][string] duration syntax
_Returns:_ [][number] milliseconds
Parse duration to seconds
_Example:_
`js`
duration('1d 10h 7m 13s');
- n: [][number] duration
_Returns:_ [][string]
Convert integer duration to string
- bytes: [][number] size
_Returns:_ [][string]
Convert integer to string, representing data size in Kb, Mb, Gb, and Tb
- size: [][string] size
_Returns:_ [][number]
Convert string with data size to integer
- fn: [][function]
_Returns:_ [][function] function(...args), wrapped with try/catch
interception
- args: [][array] arguments to be passed to wrapped function
Make function raise-safe
- depth: [][number]|[][regexp] initial stack slice orstack
filter regular expression, 0 by default.
- : [
Try to detect the filepath of a caller of this function.
See github for full contributors list
[object]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object
[date]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
[function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function
[regexp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
[promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
[map]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
[array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
[error]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
[typeerror]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError
[boolean]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type
[null]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Null_type
[undefined]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Undefined_type
[number]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type
[string]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type
[object.fromentries()]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries
[buffer]: https://nodejs.org/api/buffer.html#buffer_class_buffer
[eventemitter]: https://nodejs.org/api/events.html#events_class_eventemitter
[writable]: https://nodejs.org/api/stream.html#stream_class_stream_writable