Namespace: str

noypiJS.str

NOYPI string funcs
Source:

Methods

(static) chr(ascii) → {string}

Returns a character from the specified ASCII value. The ASCII value can be specified in decimal, octal, or hex values. Octal values are defined by a leading 0, while hex values are defined by a leading 0x.
Parameters:
Name Type Description
ascii number can be specified in decimal, octal, or hex values, any numeric value.
Source:
Returns:
- The ascii character in index `ascii`.
Type
string
Example
var chrascii = noypiJS.str.chr(42);

(static) implode(separatoropt, array) → {string}

Returns a string from the elements of an array, joined by a specified separator.
Parameters:
Name Type Attributes Default Description
separator string <optional>
"" Optional. Specifies what to put between the array elements. Default is an empty string.
array Array The array to join to a string.
Source:
Returns:
The string created by joining the array elements with the separator.
Type
string

(static) ireplace(search, replacement, string) → {string}

Replaces string `search` in string `string` to string `replacement`
Parameters:
Name Type Description
search string Needle
replacement string What to replace the needle (search)
string string Haystack
Source:
Returns:
- Replaced string
Type
string
Example
var replaced_str = noypiJS.str.ireplace("easy","tedious","This is very easy!"); 

(static) levenshtein(str1, str2) → {number}

Calculates distance between two strings
Parameters:
Name Type Description
str1 string String to be compared from
str2 string String to be compared to
Source:
Returns:
- Levenshtein distance
Type
number
Example
var distance = noypiJS.str.levenshtein("advice","Advise"); 

(static) pad(search, replacement, string) → {string}

Pads `inputString` to `length` using mode `padType`.
Parameters:
Name Type Description
search string Needle
replacement int What to replace the needle (search)
string string Three modes: "STR_PAD_LEFT" pads to left only; 'STR_PAD_RIGHT' right side only; 'STR_PAD_BOTH' means both sides be padded equally.
Source:
Returns:
- Padded string
Type
string
Example
var padded_str = noypiJS.str.pad("0",5,"STR_PAD_LEFT"); 

(static) repeat(inputString, repeat) → {string}

Repeats `inputString` to `repeat` times
Parameters:
Name Type Description
inputString string Needle
repeat number What to replace the needle (search)
Source:
Returns:
- Repeated string
Type
string
Example
var padded_str = noypiJS.str.pad("0",5,"STR_PAD_LEFT"); 

(static) replace(search, replacement, string) → {string}

Case sensitive replace of `search` to `replacement` using haystack `string`,
Parameters:
Name Type Description
search string Needle
replacement string What to replace the needle (search)
string string Haystack
Source:
Returns:
- Replaced string
Type
string
Example
var replaced_str = noypiJS.str.ireplace("easy","tedious","This is very easy!");  

(static) reverseString(string) → {string}

Reverses a string.
Parameters:
Name Type Description
string string The string to reverse.
Source:
Returns:
The reversed string.
Type
string

(static) rot13(inputString) → {string}

Encodes `inputString` to rot13,
Parameters:
Name Type Description
inputString string String to be encoded
Source:
Returns:
- Encoded string
Type
string
Example
var rot13_str = noypiJS.str.rot13("hello world"); 

(static) split(inputString, length) → {array}

Split `inputString` by chars. The function splits by one char on default.
Parameters:
Name Type Description
inputString string Haystack
length number How many chars in each chunk
Source:
Returns:
- Chunked array
Type
array
Example
var chunky_str = noypiJS.str.split("all the world's a stage",2);  

(static) strlen(string) → {number}

Returns the length of a string.
Parameters:
Name Type Description
string string The string to check.
Source:
Returns:
The length of the string (in bytes) on success, or 0 if the string is empty.
Type
number

(static) strtolower(inputString) → {string}

Converts a string to lowercase.
Parameters:
Name Type Description
inputString string The string to convert.
Source:
Returns:
The input string converted to lowercase.
Type
string

(static) strtoupper(inputString) → {string}

Converts a string to uppercase.
Parameters:
Name Type Description
inputString string The string to convert.
Source:
Returns:
The input string converted to uppercase.
Type
string

(static) substr_count(string, substring, startopt, lengthopt) → {number}

Counts the number of times a substring occurs in a string.
Parameters:
Name Type Attributes Default Description
string string The string to check.
substring string The substring to search for.
start number <optional>
0 Optional. Specifies where in the string to start searching. If negative, it starts counting from the end of the string.
length number <optional>
Optional. Specifies the length of the search.
Source:
Returns:
The count of occurrences of the substring in the string.
Type
number

(static) trim(string, charlistopt) → {string}

Removes whitespace and specified characters from both sides of a string.
Parameters:
Name Type Attributes Default Description
string string The string to trim.
charlist string <optional>
"\0\t\n\x0B\r " Optional. Specifies which characters to remove from the string.
Source:
Returns:
The trimmed string.
Type
string

(static) ucfirst(string) → {string}

Converts the first character of a string to uppercase.
Parameters:
Name Type Description
string string The string to convert.
Source:
Returns:
The string with the first character in uppercase.
Type
string

(static) word_count(inputString, returnTypeopt, charListopt) → {number|Array.<string>|Object}

Counts the number of words in a string and provides various return options.
Parameters:
Name Type Attributes Default Description
inputString string The string to check.
returnType number <optional>
0 Specifies the return value of the function: - 0 (default): Returns the number of words found. - 1: Returns an array with the words from the string. - 2: Returns an array where the key is the position of the word in the string, and the value is the actual word.
charList string <optional>
Specifies special characters to be considered as words.
Source:
Returns:
Depending on the returnType parameter: - If returnType is 0, returns the number of words found. - If returnType is 1, returns an array with the words from the string. - If returnType is 2, returns an object where the key is the position of the word in the string, and the value is the actual word.
Type
number | Array.<string> | Object

(static) wordwrap(string, widthopt, breakopt, cutopt) → {string}

Wraps a string into new lines when it reaches a specific length.
Parameters:
Name Type Attributes Default Description
string string The string to break up into lines.
width number <optional>
75 Optional. The maximum line width. Default is 75.
break string <optional>
"\n" Optional. The characters to use as breaks. Default is "\n".
cut boolean <optional>
false Optional. Whether words longer than the specified width should be wrapped. - `false` (Default): No-wrap. - `true`: Wrap.
Source:
Returns:
The word-wrapped string.
Type
string