karmia-utility-string
v0.11.0
Published
Karmia string utility module.
Downloads
19
Readme
karmia-utility-string
Karmia utility string module
Usage
const karmia_utility_string = require('karmia-utility-string').default,
kstring = new karmia_utility_string();
strip
- string
<string>
- mask_character
<string>
Default: " \t\n\r\0\x0B"
// Strip whitespaces
const string = ' Hello, world. ';
kstring.strip(string);
// Strip specified characters
const string = '"Hello, world."';
kstring.strip(string, '"');
lstrip
- string
<string>
- mask_character
<string>
Default: " \t\n\r\0\x0B"
// Strip whitespaces
const string = ' Hello, world.';
kstring.lstrip(string);
// Strip specified characters
const string = '"Hello, world.';
kstring.lstrip(string, '"');
rstrip
- string
<string>
- mask_character
<string>
Default: " \t\n\r\0\x0B"
// Strip whitespaces
const string = 'Hello, world. ';
kstring.rstrip(string);
// Strip specified characters
const string = 'Hello, world."';
kstring.rstrip(string, '"');
normalize
- string
<string>
- form
<string>
Default: "NFKC"
const string = '\u202b123\r\nABC\rdef\nアイウエオガ';
kstring.normalize(string); // Return: '123\nABC\ndef\nアイウエオガ'
unquote
- string
<string>
const string = '"Hello, world."';
kstring.unquote(string);
zfill
- string
<string>
- width
<number>
- encoding
<string>
const string = '1';
kstring.zfill(string, 3);
camelCase
- string
<string>
- capitalize
<boolean>
Default: false
const string = 'snake_case_string';
kstring.camelCase(string);
snakeCase
- string
<string>
const string = 'camelCaseString';
kstring.snakeCase(string);
kebabCase
- string
<string>
const string = 'camelCaseString';
kstring.kebabCase(string);
parse
- string
<string>
- delimiter
<string/regexp>
Default: /,? / - separator
<string/regexp>
Default: =
const string = 'key1=value1, key2=value2';
kstring.parse(string, /,? /, '=');
toBoolean
- string
<string>
// Should be true
kstring.toBoolean('true');
kstring.toBoolean('True');
kstring.toBoolean('TRUE');
kstring.toBoolean('0');
kstring.toBoolean(1);
kstring.toBoolean(true);
kstring.toBoolean('false_1');
// Should be false
kstring.toBoolean('false');
kstring.toBoolean('False');
kstring.toBoolean('FALSE');
kstring.toBoolean('');
kstring.toBoolean(0);
kstring.toBoolean(false);