String

String

Source:

Methods

capitalize() → {string}

Capitalizes string.

Source:

Capitalizes string.

Example
'bendy zhang'.capitalize();
// => "Bendy Zhang"
Returns:
Type
string

cut(len, ellipsisopt) → {string}

Cuts the string.

Source:

Cuts the string.

Example
'Bendy'.cut(3);
// => "Ben..."
'Bendy'.cut(3, '---');
// => "Ben---"
Parameters:
Name Type Attributes Default Description
len number

The length needs to cut.

ellipsis string <optional>
...

The ellipsis if the len larger than string length.

Returns:

A cutted string with ellipsis or self.

Type
string

dasherize() → {string}

Dasherizes string.

Source:

Dasherizes string.

Example
'Bendy Zhang 1949.10'.dasherize();
// => "bendy-zhang-1949-10"
Returns:
Type
string

ltrim() → {string}

Removes whitespace from the left of a string.

Source:

Removes whitespace from the left of a string.

Example
' bendy '.ltrim();
// => "bendy  "
Returns:
Type
string

md2Html() → {string}

Converts markdown text to html.

Source:
Since:
  • 1.0.53

Converts markdown text to html.

Example
'## Hello **World**'.md2Html();
Requires:
Returns:

The html text.

Type
string

padLeft(targetLength, padString) → {string}

Pads string at start.

Source:

Pads string at start.

Example
'abc'.padLeft(10);         // "       abc"
'abc'.padLeft(10, "foo");  // "foofoofabc"
'abc'.padLeft(6,"123465"); // "123abc"
'abc'.padLeft(8, "0");     // "00000abc"
'abc'.padLeft(1);          // "abc"
Parameters:
Name Type Description
targetLength number

The total length.

padString string

The padding string.

Returns:

The padded string.

Type
string

padRight(targetLength, padString) → {string}

Pads string at end.

Source:

Pads string at end.

Example
'abc'.padRight(10);         // "abc       "
'abc'.padRight(10, "foo");  // "abcfoofoof"
'abc'.padRight(6,"123465"); // "abc123"
'abc'.padRight(8, "0");     // "abc00000"
'abc'.padRight(1);          // "abc"
Parameters:
Name Type Description
targetLength number

The total length.

padString string

The padding string.

Returns:

The padded string.

Type
string

regexReplace(pattern, replacement) → {string}

Replaces using regex.

Source:

Replaces using regex.

Example
'Bendy Zhang'.regexReplace('\sZh', '-');
// => "Bendy-ndy"
'Bendy Zhang'.regexReplace(/\sZh/ig, '-');
// => "Bendy-ndy"
Parameters:
Name Type Description
pattern *

The regex pattern object or string. If expression string, will ignore case and global replacement.

replacement *

The replacement needs to replace.

Returns:

The replaced string.

Type
string

repeat(count) → {string}

Repeats the specific string.

Source:

Repeats the specific string.

Example
'abc'.repeat(0);    // ''
'abc'.repeat(1);    // 'abc'
'abc'.repeat(2);    // 'abcabc'
Parameters:
Name Type Description
count number

The repeat count.

Returns:

The repeated string.

Type
string

replaceAll() → {string}

Replaces text inside a string.

Source:

Replaces text inside a string.

Example
'Bendy Zhang'.replaceAll('n', '-');
// => "Be-dy Zha-g"
Returns:
Type
string

rtrim() → {string}

Removes whitespace from the right of a string.

Source:

Removes whitespace from the right of a string.

Example
' bendy '.rtrim();
// => "  bendy"
Returns:
Type
string

stripHtmlTag() → {string}

Strips html tags.

Source:

Strips html tags.

Example
'<div>Hello <span>World!</span></div>'.stripHtmlTag();
// => "Hello World!""
Returns:

The string which does not include any html tags.

Type
string

title2Url(title) → {string}

Make title which can as one part in url.

Source:

Make title which can as one part in url. like hello-world.

Example
'Hello World!'.title2Url();
// => hello-world-
Parameters:
Name Type Description
title string

The title.

Returns:

The string is one part of url.

Type
string

toObject() → {object}

Converts a string to Json object.

Source:

Converts a string to Json object.

Returns:

The parsed object.

Type
object

trim() → {string}

Removes whitespace from both ends of a string.

Source:

Removes whitespace from both ends of a string. Whitespace in this context is all the whitespace characters (space, tab, no-break space, etc.) and all the line terminator characters (LF, CR, etc.).

Example
' bendy '.trim();
// => "bendy"
Returns:
  • A new string representing the calling string stripped of whitespace from both ends.
Type
string