Returns true
if x
is a string.
String.isString('123') === true;
String.isString(123) === false;
Capitalizes this string.
const s = 'foo bar';
s.capitalize() === 'Foo bar';
Returns true
if the given pattern
matches a slice of a string. Returns false
if it does not.
const s = 'bananas';
s.contains('nana') === true;
s.contains('apples') === false;
Returns the first index in this string.
const s = 'foobar';
s.firstIndex() === 0;
Returns the first characer in this string.
'foobar'.firstItem() === 'f';
''.firstItem() === '';
Inserts a string into this string at specified index
.
const s = '';
s.insert(0, 'f') === 'f';
s === '';
Returns true
if this string has a length of zero, and false otherwise.
''.isEmpty() === true;
's'.isEmpty() === false;
Returns the last index in this string.
'foobar'.lastIndex() === 5;
''.lastIndex() === 0;
Returns the last character in this string.
'foobar'.lastItem() === 'r';
''.lastItem() === '';
Returns the length of this string.
'foo'.len() === 3;
Returns an array containing lines of a string. Lines are ended with either a newline (\n
) or a carrige return with a line feed (\r\n
). The final line ending is optional.
const a = 'foo\r\nbar\n\nbaz\n';
const al = a.lines();
al[0] === 'foo';
al[1] === 'bar';
al[2] === '';
al[3] === 'baz';
const b = 'foo\nbar\n\r\nbaz';
const bl = b.lines();
bl[0] === 'foo';
bl[1] === 'bar';
bl[2] === '';
bl[3] === 'baz';
Retains only the characters specified by the predicate
.
const s = 'f_o_ob_ar';
s.retain(c => c !== '_') === 'foobar';
s === 'f_o_ob_ar';
Splits a string by whitespace.
'A few words'.splitWhitespace(); /** ['A', 'few', 'words'] */
' Mary had\ta\u{2009}little \n\t lamb'.splitWhitespace(); /** ['Mary', 'had', 'a', 'little', 'lamb'] */
Converts this string to camelCase
.
'foo-bar'.toCamelCase() === 'fooBar';
Converts this string to kebab-case
.
'foo_bar'.toKebabCase() === 'foo-bar';
Converts this string to PascalCase
.
'foo-bar'.toPascalCase() === 'FooBar';
Converts this string to snake_case
.
'foo-bar'.toSnakeCase() === 'foo_bar';
Converts this string to Start Case
.
'foo_bar'.toStartCase() === 'Foo Bar';