Module: string

Provides an API for enabling extra string functions.

Author:
  • Henry Brown
Source:

Methods


<static> disableIndent()

Detaches the indent function from the String prototypes.

Source:

<static> disablePadLeft()

Detaches the padLeft function from the String prototypes.

Source:

<static> disablePadRight()

Detaches the padRight function from the String prototypes.

Source:

<static> disablePrepend()

Detaches the prepend function from the String prototypes.

Source:

<static> enableAll()

Enables all of the string functions including:

Source:
Throws:

If String has already implemented any of the above functions

Type
Error

<static> enableIndent()

Attaches the indent function to the String prototypes so that it can be used on any String objects in the application.

Source:
Throws:

If String has already implemented indent.

Type
Error

<static> enablePadLeft()

Attaches the padLeft function to the String prototypes so that it can be used on any String objects in the application.

Source:
Throws:

If String has already implemented padLeft.

Type
Error

<static> enablePadRight()

Attaches the padRight function to the String prototypes so that it can be used on any String objects in the application.

Source:
Throws:

If String has already implemented padRight.

Type
Error

<static> enablePrepend()

Attaches the prepend function to the String prototypes so that it can be used on any String objects in the application.

Source:
Throws:

If String has already implemented prepend.

Type
Error

<static> indent(indentSize)

Indents this string by a number of spaces characters equal to the indentSize parameter.

Parameters:
Name Type Description
indentSize Number

The number of spaces to indent each line

Source:
Returns:

The indented string.

Type
String
Example
//outputs:
//    {
//      "name": "Fred",
//      "role": "Superhero",
//      "mascot": "Platypus"
//    }
console.log(JSON.stringify({
  "name": "Fred",
  "role": "Superhero",
  "mascot": "Platypus"
}, null, 2).indent(4));

<static> padCount()

A helper function that's used to get the number of repeats of padValue needed to pad string's length to padLength without exceeding padLength while only repeating whole portions of padValue.

Source:
Example
//returns 2 because the length of "freddyblabla" is 12, and additional
// repetitions of bla would cause us to exceed the specified padLength of 13
padCount("freddy", "bla", 13);

<static> padLeft(padValue, padLength)

Pads the left hand side of this string with copies of padValue until another would cause the string's length to exceed padLength.

Parameters:
Name Type Description
padValue String

The value to repeat

padLength String

The max length of the string after padding

Source:
Returns:

A padded string

Type
String
Example
//returns "00007"
"7".padLeft("0", 5)

<static> padRight(padValue, padLength)

Pads the right hand side of this string with copies of padValue until another would cause the string's length to exceed padLength.

Parameters:
Name Type Description
padValue String

The value to repeat

padLength String

The max length of the string after padding

Source:
Returns:

A padded string

Type
String
Example
//returns "Noooo"
"N".padRight("o", 5)

<static> prepend(prefix)

Concatenates the prefix parameter and this string together.

Parameters:
Name Type Description
prefix String

The value to prepend.

Source:
Returns:

The concatenated string.

Type
String
Example
//returns "prefix"
"fix".prepend("pre");