Methods
(inner) base64ToBlob(string, typeopt) → {Blob}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
string |
string | base64 or data URL |
|
type |
string |
<optional> |
MIME type. Shall be omitted if |
- Source:
Returns:
- Type
- Blob
(inner) camelize(kebab) → {string}
Convert kebab-case string into camelCase.
Parameters:
Name | Type | Description |
---|---|---|
kebab |
string |
- Source:
Returns:
- Type
- string
(inner) compareVersionNumbers(a, b) → {integer}
This only compares dot-separated-integer strings.
For more complicated cases, use semver
or compare-versions
.
Parameters:
Name | Type | Description |
---|---|---|
a |
string | |
b |
string |
- Source:
Returns:
- Type
- integer
(inner) dateFormat(format, date) → {string}
Simulate DateTime::format
of PHP.
Parameters:
Name | Type | Description |
---|---|---|
format |
string | |
date |
Date | string |
Returns:
- Type
- string
(inner) kebabize(camel) → {string}
Convert camelCase string into kebab-case
Parameters:
Name | Type | Description |
---|---|---|
camel |
string |
- Source:
- See:
-
- https://stackoverflow.com/a/67243723/1998874 CC BY-SA 4.0
Returns:
- Type
- string
(inner) modifyURLBySearchParams(url, searchParams) → {URL}
Parameters:
Name | Type | Description |
---|---|---|
url |
string | URL | Location | |
searchParams |
string | URLSearchParams | FormData |
- Source:
Returns:
- Type
- URL
Example
/// returns 'https://example.com/?page=3&foo=4'
modifyURLBySearchParams('https://example.com/?page=2', {page: 3, foo: 4}).toString();
(inner) numberFormat(number, optionsopt) → {string}
A shortcut to call a method of an anonymous Intl.NumberFormat
.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
number |
Number | BigInt | string | |||
options |
Object |
<optional> |
{} |
- Source:
Returns:
- Type
- string
(inner) parseChineseNumber(string, forceStringopt) → {number|string|NaN}
Both traditional and simplified chinese numbers are supported.
Not guaranteed to validate the string.
Returns string if the number reaches Number.MAX_SAFE_INTEGER
or forceString
is given true.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
string |
string | |||
forceString |
boolean |
<optional> |
false |
- Source:
Returns:
- Type
- number | string | NaN
(inner) parseCSV(csv, hasHeaderopt) → {Array}
Parse valid MIME type text/csv
string to array or object. Empty records are ignored.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
csv |
string | |||
hasHeader |
boolean |
<optional> |
true | If truthy, an array of objects with property names assigned by the first record is returned; if falsy, an array of arrays is returned. |
- Source:
Returns:
- Type
- Array
Examples
/// returns [{a: '3', b: '4'}, {a: '7,', b: '9"'}]
parseCSV('"a",b\r\n"3",4\r\n"7,","9"""\r\n')
/// returns [['3', '4'], ['7,', '9"']]
parseCSV('"3",4\r\r\n\n"7,","9"""\r\n', false)
(inner) toCSV(dataArray, fieldNames, eolopt) → {string}
Convert an array of non-nested objects to a text/csv
string with a header record.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
dataArray |
Array.<Object> | properties with keys not present in |
||
fieldNames |
Array.<string> | Only fields listed here would be in the result. |
||
eol |
string |
<optional> |
\r\n | end of line, also appended to the returned string |
- Source:
Returns:
- Type
- string
Example
/// returns 'a,b\r\n3,4\r\nx,"y\nz"\r\n'
toCSV([
{a: 3, b: 4, c: 5},
{a: 'x', b: 'y\nz'}
], ['a', 'b'])