Skip to content

Latest commit

 

History

History
273 lines (182 loc) · 8.67 KB

DOCS.md

File metadata and controls

273 lines (182 loc) · 8.67 KB

String

JavaScript build-in string object

Kind: global variable

string.startsWith(query, [index]) ⇒ boolean

Determines whether a string begins with the characters of a specified string.

Kind: instance method of String
Returns: boolean - Boolean output

Param Type Default Description
query string Specified string
[index] int 0 Index determines where to start lookup

Example

"Hello, world!".startsWith("Hello"); // true

string.endsWith(query, [index]) ⇒ boolean

Determines whether a string ends with the characters of a specified string.

Kind: instance method of String
Returns: boolean - Boolean output

Param Type Default Description
query string Specified string
[index] int 0 Index determines where to start lookup counted from the end of the string

Example

"Hello, world!".endsWith("world!"); // true

string.strip() ⇒ string

Strips all non-word or non-whitespace characters from the string.

Kind: instance method of String
Returns: string - Stripped string
Example

"Hello, world!".strip(); // "Hello world"

string.parts() ⇒ Array.<string>

Splits string by the whitespace

Kind: instance method of String
Returns: Array.<string> - Stripped string
Example

"Hello, world!".parts(); // ["Hello,", "world!"]

string.words() ⇒ Array.<string>

Extracts words from the string

Kind: instance method of String
Returns: Array.<string> - Extracted words
Example

"Hello, world!".words(); // ["Hello", "world"]

string.capitalize(lowerRest) ⇒ string

Capitalizes first letter of the string

Kind: instance method of String
Returns: string - Capitalized string

Param Type Description
lowerRest boolean Lowercase rest of the string if true

Example

"hello World".capitalize(); // "Hello World"
"hello world".capitalize(true); // "Hello world"

string.decapitalize(lowerRest) ⇒ string

Decapitalizes first letter of the string

Kind: instance method of String
Returns: string - Decapitalized string

Param Type Description
lowerRest boolean Lowercase rest of the string if true

Example

"Hello World".capitalize(); // "hello World"

string.camelCase(upperRest) ⇒ string

Converts the string to camelCased.

Kind: instance method of String
Returns: string - camelCased string

Param Type Description
upperRest boolean Uppercase rest of the string if true

Example

"Hello World".camelCase(); // "helloWorld"
"Hello, World!".camelCase(); // "helloWorld"

string.snakeCase() ⇒ string

Converts the string to snake_case.

Kind: instance method of String
Returns: string - snake_cased string
Example

"Hello World".snakeCase(); // "hello_world"
"Hello, World!".snakeCase(); // "hello_world"

string.kebabCase() ⇒ string

Converts the string to kebab-case.

Kind: instance method of String
Returns: string - kebab-cased string
Example

"Hello World".kebabCase(); // "hello-world"
"Hello, World!".kebabCase(); // "hello-world"

string.titleCase() ⇒ string

Converts the string to Title Case.

Kind: instance method of String
Returns: string - kebab-cased string
Example

"hello world".titleCase(); // "Hello World"
"hello, world!".titleCase(); // "Hello, World!"

string.format(arguments) ⇒ string

String formatting function. Can be used with object or positional arguments.

Kind: instance method of String
Returns: string - kebab-cased string

Param Type Description
arguments object | string Positional or unpositional arguments

Example

// Unpositional named arguments
"rgb({r}, {g}, {b})".format({ r: 10, g: 20, b: 30 }); // "rbg(10, 20, 30)"

// Positional named arguments
"rgb({r}, {g}, {b})".format(10, 20, 30); // "rbg(10, 20, 30)"

// Positional arguments
"rgb({}, {}, {})".format(10, 20, 30); // "rbg(10, 20, 30)"

string.linkify([target]) ⇒ string

String linkify function. Replaces text links with HTML links.

Kind: instance method of String
Returns: string - linkified string

Param Type Default Description
[target] string "&quot;_blank&quot;" Specifies where to open link. Options are "_target", "_self", "_parent", "_top" or name of the frame.

Example

"My email address is john@doe.com".linkify();
// "My email address is <a ref="mailto:john@doe.com" target="_blank">john@doe.com</a>"

"This is link to google: www.google.com".linkify();
// "This is link to google: <a ref="http://www.google.com" target="_blank">www.google.com</a>"

string.stripTags() ⇒ string

Strips all HTML tags from the string

Kind: instance method of String
Returns: string - Stripped string
Example

'<div>This is <b style="color: red;">HTML</b></div>'.stripTags();
// "This is HTML"