Str

Str

Source:

String utilities

Methods

(static) escapeRegex(str) → {string}

Source:

Escape a string for including in regular expressions

Parameters:
Name Type Description
str string

string to escape

Returns:

escaped string

Type
string

(static) invertCase(str) → {string}

Source:

Inverts the case of a string

Example
Str.invertCase('Hello iPhone'); // => 'hELLO IpHONE'
Parameters:
Name Type Description
str string
Returns:
Type
string

(static) isConsonant(char) → {boolean}

Source:

is the character given is a consonant?

Example
Str.isConsonant('a') // => false
Str.isConsonant('f') // => true
Str.isConsonant('ff') // => false
Parameters:
Name Type Description
char string
Returns:
Type
boolean

(static) isVowel(char) → {boolean}

Source:

is the character given is a vowel?

Example
Str.isVowel('a') // => true
Str.isVowel('f') // => false
Str.isVowel('ae') // => false
Parameters:
Name Type Description
char string
Returns:
Type
boolean

(static) numberFormat(number, optionsopt) → {string}

Source:

Format a number according to a particular locale
Similar to Number.toLocaleFormat, except being significantly faster

Parameters:
Name Type Attributes Default Description
number number

the number to format

options numberFormatOpts | string <optional>
{}

string of locale or options object {locale: 'en', decimals: 0, currency: 'INR', abbr: 'auto'}

Returns:

formatted number

Type
string

(static) numberToWords(number) → {string}

Source:

Convert a number into words

Parameters:
Name Type Description
number number
Returns:
Type
string

(static) plural(str) → {string}

Source:

Get the plural of a string

Parameters:
Name Type Description
str string
Returns:
Type
string

(static) pluralize(str, countopt) → {string}

Source:

Pluralize a character if the count is greater than 1

Parameters:
Name Type Attributes Default Description
str string
count number <optional>
2
Returns:
Type
string

(static) rot13(str) → {string}

Source:

Rotate a string by 13 characters

Parameters:
Name Type Description
str string

the string to be rotated

Returns:

rotated string

Type
string

(static) rot47(str) → {string}

Source:

Rotate a string by 47 characters

Parameters:
Name Type Description
str string

the string to be rotated

Returns:

rotated string

Type
string

(static) spaceClean(str) → {string}

Source:

Space clean a string
Converts consecutive multiple spaces / tabs / newlines in the string into a single space

Parameters:
Name Type Description
str string
Returns:
Type
string

(static) stripTags(str, options) → {string}

Source:

Strip html tags from a string

Parameters:
Name Type Description
str string

the string to remove tags from

options object

object containing:
allowed: array of allowed tags eg. ['p', 'b', 'span'], default: []
blocked: array of blocked tags eg. ['p'], default: []
replaceWith: replace the removed tags with this string, default: ''

if allowed is not given and blocked is given
then by default all tags not mentioned in blocked are allowed

Returns:

resulting string by removing all tags mentioned

Type
string

(static) transform(str, from, to) → {string}

Source:

transform a string by replacing characters from from string to to string

Example
Str.transform('abc', 'bc', 'de') // => 'ade'
Parameters:
Name Type Description
str string

string to transform

from string

characters to replace in the string

to string

characters to replace with in the string

Returns:

transformed string

Type
string

(static) trimToNext(str, pos, charopt) → {string}

Source:

Break String From Next Given Character After A Given Position

Parameters:
Name Type Attributes Default Description
str string
pos number
char string <optional>
' '
Returns:
Type
string

(static) tryParseJson(str) → {object|null}

Source:

Parses a json string, returns null if string is invalid (instead of throwing error)
If the input is not a string (already parsed), returns the input itself

Parameters:
Name Type Description
str any
Returns:
Type
object | null

(static) tryStringifyJson(obj) → {string}

Source:

Stringifies an object only if it is not already a string
If it is already a string returns the string itself
If it is undefined, returns 'null'

Parameters:
Name Type Description
obj any
Returns:
Type
string