Util
General purpose utilities
- License:
- Apache-2.0Copyright 2020 Satoshi Soma
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. - Source:
- lib/Util.js, line 20
Methods
arr(x) → any[]
Coerces the given value to an array
Parameters:
Name | Type | Description |
---|---|---|
x
|
any |
- Source:
- lib/Util.js, line 36
Returns:
- Type:
- any[]
base(int, digits) → string
Converts base of the given integer.
Parameters:
Name | Type | Description |
---|---|---|
int
|
number | |
digits
|
string | Digits to use |
- Source:
- lib/Util.js, line 94
Returns:
- Type:
- string
clone(x) → object
Clones the given object (deep-clone). The given object won't be modified.
Parameters:
Name | Type | Description |
---|---|---|
x
|
object | Object to clone |
- Source:
- lib/Util.js, line 74
Returns:
Cloned object
- Type:
- object
error(msg, name) → Error
Parameters:
Name | Type | Description |
---|---|---|
msg
|
string | |
name
|
string |
- Source:
- lib/Util.js, line 26
Returns:
- Type:
- Error
escRegExp(str) → string
Escapes regex's special characters in the given string.
Parameters:
Name | Type | Description |
---|---|---|
str
|
string |
- Source:
- lib/Util.js, line 223
- See:
- https://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript/3561711#3561711
Returns:
Modified str
- Type:
- string
ext(file) → string
Parameters:
Name | Type | Description |
---|---|---|
file
|
string |
- Source:
- lib/Util.js, line 122
Returns:
- Type:
- string
map(x, table, defopt) → any
Parameters:
Name | Type | Description |
---|---|---|
x
|
any | |
table
|
object | |
def opt
|
any | Default value |
- Source:
- lib/Util.js, line 53
Returns:
- Type:
- any
merge(x, y, recurse) → object
Merges the 2nd object into the 1st object recursively (deep-merge). The 1st object will be modified.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
x
|
object | The 1st object |
|
y
|
object | The 2nd object |
|
recurse
|
number |
8
|
Recurstion limit |
- Source:
- lib/Util.js, line 63
Returns:
The 1st object
- Type:
- object
splitFirst(str, sep) → string[]
Splits a string at the first occurence of the given separator
Parameters:
Name | Type | Description |
---|---|---|
str
|
string | |
sep
|
string |
- Source:
- lib/Util.js, line 133
Returns:
- Type:
- string[]
splitLast(str, sep) → string[]
Splits a string at the last occurence of the given separator
Parameters:
Name | Type | Description |
---|---|---|
str
|
string | |
sep
|
string |
- Source:
- lib/Util.js, line 145
Returns:
- Type:
- string[]
splitWords(str, optsopt) → string[]
Splits the given string into words, numbers and symbols.
Parameters:
Name | Type | Description |
---|---|---|
str
|
string | |
opts opt
|
object |
- Source:
- lib/Util.js, line 155
Returns:
- Type:
- string[]
str(x) → string
Coerces the given value to a string
Parameters:
Name | Type | Description |
---|---|---|
x
|
any |
- Source:
- lib/Util.js, line 44
Returns:
- Type:
- string
toLiteral(x, optsopt) → string
Converts the given value into a literal string.
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
x
|
any | Value to convert |
||||||||||||
opts opt
|
object | Options Properties
|
- Source:
- lib/Util.js, line 196
Returns:
Literal string
- Type:
- string
unique() → number
Returns a unique integer number.
- Source:
- lib/Util.js, line 114
Returns:
- Type:
- number