JavaScript build-in string object
Kind: global variable
- String
- .startsWith(query, [index]) ⇒
boolean
- .endsWith(query, [index]) ⇒
boolean
- .strip() ⇒
string
- .parts() ⇒
Array.<string>
- .words() ⇒
Array.<string>
- .capitalize(lowerRest) ⇒
string
- .decapitalize(lowerRest) ⇒
string
- .camelCase(upperRest) ⇒
string
- .snakeCase() ⇒
string
- .kebabCase() ⇒
string
- .titleCase() ⇒
string
- .format(arguments) ⇒
string
- .linkify([target]) ⇒
string
- .stripTags() ⇒
string
- .startsWith(query, [index]) ⇒
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
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
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"
Splits string by the whitespace
Kind: instance method of String
Returns: Array.<string>
- Stripped string
Example
"Hello, world!".parts(); // ["Hello,", "world!"]
Extracts words from the string
Kind: instance method of String
Returns: Array.<string>
- Extracted words
Example
"Hello, world!".words(); // ["Hello", "world"]
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"
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"
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"
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"
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"
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 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 function. Replaces text links with HTML links.
Kind: instance method of String
Returns: string
- linkified string
Param | Type | Default | Description |
---|---|---|---|
[target] | string |
""_blank"" |
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>"
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"