Strings

String Utilities module.

Methods

(inner) addPostfix(postfix, value) → {string}

Adds a postfix to a given value

Note:

  • This is a composed function, so check the example to know how to call it
Example
addPostfix(5)("%"); //=> '5%'
Parameters:
Name Type Description
postfix string | number

Postfix

value string | number

Value

Returns:
Type
string

(inner) addPrefix(prefix, value) → {string}

Adds a prefix to a given value

Note:

  • This is a composed function, so check the example to know how to call it
Example
addPrefix(5)(">"); //=> '>5'
Parameters:
Name Type Description
prefix string | number

Prefix

value string | number

Value

Returns:
Type
string

(inner) capitalize(word) → {string}

Set first charater to UpperCase and the rest to LowerCase

Example
capitalize("botas"); //=> 'Botas'
capitalize("this is a sentence"); //=> 'This is a sentence'
Parameters:
Name Type Description
word string

String to capitalize

Returns:
Type
string

(inner) leftpad(len, pattern, str) → {string}

Adds pattern to left of str until it fills len

Example
leftpad(5, "*", "hey"); //=> "**hey"
leftpad(10, "_*", "hey"); //=> "_*_*_*_hey"
Parameters:
Name Type Description
len number

Length of final string

pattern string | number

Pattern to fill in the blanks

str string | number

Value to be padded

Returns:
Type
string

(inner) separate(what, every, separator, from_r_to_lopt) → {string}

Adds separator every given number of characters

Separator applies from right to left by default, but it can be configured to apply from left to right too by setting from_r_to_l=false

Example
separate(12345678, 3, ","); //=> "12,345,678"
separate(12345678, 3, "-", false); //=> "123-456-78"
Parameters:
Name Type Attributes Default Description
what string | number

Value to separate

every number

Periocity of separation

separator string | number

Value to use in separation

from_r_to_l boolean <optional>
true

False to separate from left to right

Returns:
Type
string