Ƭ T: string
The type alias for string
Since
4.0.0
Ƭ StringReplacer: T | RegExp | Unary<T, T>
A replacer argument.
It could be either:
Since
4.0.0
Ƭ StringSearcher: T | { [search]: (string: string) => number }
A string searcher argument
Since
4.0.0
Ƭ StringSplitter: T | { [split]: (string: string, limit?: number) => string[] }
A string splitter argument
Since
4.0.0
▸ guard(x): x is string
Checks if a value x is a string T
Example
import { Str } from 'tiinvo'
Str.guard(10) // false
Str.guard({}) // false
Str.guard([]) // false
Str.guard(null) // false
Str.guard("hello world") // true
Since
4.0.0
| Name | Type | Description |
|---|---|---|
x |
unknown |
the value to check |
x is string
x is a string T▸ cmp(a, b): ComparableResult
Compares two strings a and b.
Returns:
a is greater than ba is same of bb is greater than aImportant: strings are compared as is, no lowercasing is applied
Example
import { Str } from 'tiinvo';
Str.cmp('a', 'a') // 0
Str.cmp('a', 'b') // -1
Str.cmp('b', 'a') // 1
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the first string |
b |
string |
the last string |
a is greater than b
a is same of bb is greater than a▸ cmp(a): Unary<T, ComparableResult>
Returns a unary function which compares two strings b and a.
Important: strings are compared as is, no lowercasing is applied
Example
import { Str } from 'tiinvo';
const cmpB = Str.cmp('b')
cmpB('a') // -1
cmpB('b') // 0
cmpB('c') // 1
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the left-hand compared string |
the unary function
▸ eq(a, b): boolean
Returns true if two strings are equal.
Important: strings are compared as is, no lowercasing is applied.
import { Str } from 'tiinvo';
Str.eq('a', 'a') // true
Str.eq('a', 'b') // false
Str.eq('b', 'a') // false
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the first string |
b |
string |
- |
boolean
true if a equals to bfalse otherwiseReturns a unary function which checks if two strings are equal.
Important: strings are compared as is, no lowercasing is applied.
import { Str } from 'tiinvo';
Str.eq('a', 'a') // true
Str.eq('a', 'b') // false
Str.eq('b', 'a') // false
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the first string |
the unary function
▸ asc(a, b): ComparableResult
Compares two strings a and b if b is defined, otherwise returns a
Unary<string, string> function which once called compares b and a
Great to sort a string array in ASC direction.
Example
import { Str } from 'tiinvo';
const collection = ['a', 'd', 'c', 'e', 'F', 'A'];
collection.sort(Str.asc) // [ "A", "F", "a", "c", "d", "e" ]
Since
4.0.0
| Name | Type |
|---|---|
a |
string |
b |
string |
▸ asc(a): Unary<T, ComparableResult>
| Name | Type |
|---|---|
a |
string |
▸ desc(a, b): ComparableResult
Compares two strings a and b if b is defined, otherwise returns a
Unary<string, string> function which once called compares b and a
Great to sort a string array in DESC direction.
Example
import { Str } from 'tiinvo';
const collection = ['a', 'd', 'c', 'e', 'F', 'A'];
collection.sort(Str.desc) // [ "e", "d", "c", "a", "F", "A" ]
Since
4.0.0
| Name | Type |
|---|---|
a |
string |
b |
string |
▸ desc(a): Unary<T, ComparableResult>
| Name | Type |
|---|---|
a |
string |
▸ toInt32Array(t): Int32Array
Serializes a string T to an Int32Array
Example
import { Str } from 'tiinvo'
Str.toInt32Array('hello') // Int32Array(5) [ 104, 101, 108, 108, 111 ]
Since
| Name | Type |
|---|---|
t |
string |
Int32Array
▸ camel(a): string
Formats a string to camel case.
Example
import { Str } from 'tiinvo';
Str.camel('hello world'); // 'helloWorld'
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string |
string
the camelCased string
Returns the character Option.t<string> at the specified index.
Important: if the index is out of range, then None is returned.
Example
import { Str } from 'tiinvo';
Str.charAt("hello", 0) // "h"
Str.charAt("hello", 10) // null
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string |
b |
number |
the char index |
Option.Some<T> if a char is found at position bOption.None otherwiseReturns a Unary<string, string> function which returns the char at position a
Important: if the index is out of range, then None is returned.
Example
import { Str } from 'tiinvo';
Str.charAt(0)("hello") // "h"
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
number |
the index |
the unary function
▸ charCodeAt(a, b): T<number>
Returns the char code Option.t<string> at the specified index.
If a and b parameters are passed, b is the char position for string a.
If b parameter is not passed, returns a Unary<string, string> function and a is the char code position for string b.
Important: if the index is out of range, then None is returned.
Example
import { Str } from 'tiinvo';
Str.charCodeAt("hello", 0) // 104
Str.charCodeAt("hello", 10) // null
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string |
b |
number |
the index |
T<number>
Option.Some<number> the char code at position b if anyOption.None otherwise▸ charCodeAt(a): Unary<T, T<number>>
Returns a Unary<string, string> function which checks and returns the
char code Option.Some<number> at position a if any.
Important: if the index is out of range, then None is returned.
Example
import { Str } from 'tiinvo';
Str.charCodeAt(0)("hello") // 104
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
number |
the index |
the unary function
▸ chars(a): string[]
Returns an array of characters.
Example
import { Str } from 'tiinvo';
Str.chars('hello'); // ['h','e','l','l','o']
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string |
string[]
the array of characters
▸ concat(a, b): T
Concatenates two strings in one.
Example
import { Str } from 'tiinvo';
Str.concat("hello", "world") // "helloworld"
Str.concat("world")("hello") // "helloworld"
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the first string |
b |
string |
the last string |
the concatenated string
Returns a unary function which concatenates two strings in one.
Example
import { Str } from 'tiinvo';
Str.concat("world")("hello") // "helloworld"
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the last string |
the unary function
▸ endsWith(a, b): boolean
Checks if a string terminates with another one.
Example
import { Str } from 'tiinvo';
Str.endsWith("hello", "o") // true
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string |
b |
string |
the ending string |
boolean
a includes b at it’s end▸ endsWith(a): Unary<T, boolean>
Returns a unary function which checks if a string terminates with another one.
Example
import { Str } from 'tiinvo';
const endsWithO = Str.endsWith("o")
endsWithO("hello") // true
endsWithO("world") // false
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the ending string |
the unary function
▸ includes(a, b): boolean
Returns if a string includes another one.
Example
import { Str } from 'tiinvo';
Str.includes("hello", "o") // true
Str.includes("o")("hello") // true
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string |
b |
string |
the string to search |
boolean
true if a includes bfalse otherwise▸ includes(a): Unary<T, boolean>
Returns a unary function which checks if a string includes another one.
Example
import { Str } from 'tiinvo';
const includesO = Str.includes("o")
includesO("hello") // true
includesO("barbaz") // false
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string |
the unary function
▸ indexOf(a, b, i?): T<number>
Returns the position of the first occurrence of a in b.
Example
import { Str } from 'tiinvo';
Str.indexOf("hello", "l") // 2
Str.indexOf("hello", "l", 3) // 3
Str.indexOf("l")("hello") // 2
Str.indexOf("l")("hello", 3) // 3
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string |
b |
string |
the string to search |
i? |
number |
The index at which to begin searching the String object. If omitted, search starts at the beginning of the string. |
T<number>
Option.Some<number> if foundOption.None if not found▸ indexOf(a): (b: T, i?: number) => T<number>
Returns a binary function which returns the position of the first occurrence of a in b.
Example
import { Str } from 'tiinvo';
const lpos = Str.indexOf("l");
lpos("hello") // 2
lpos("hello", 3) // 3
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string |
fn
the binary function
▸ (b, i?): T<number>
| Name | Type |
|---|---|
b |
T |
i? |
number |
T<number>
▸ lastIndexOf(a, b, p?): T<number>
Returns last position of a string ‘b’ in string ‘a’.
Example
import { Str } from 'tiinvo';
Str.lastIndexOf("hello", "l") // 3
Str.lastIndexOf("l")("hello") // 3
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string |
b |
string |
the string to search |
p? |
number |
The index at which to begin searching. If omitted, the search begins at the end of the string. |
T<number>
Option.Some<number> if foundOption.None otherwise▸ lastIndexOf(a): (b: T, p?: number) => T<number>
Returns a binary function which checks the last position of a string ‘a’ in string ‘b’.
Example
import { Str } from 'tiinvo';
Str.lastIndexOf("l")("hello") // 3
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string to search |
fn
the binary function
▸ (b, p?): T<number>
| Name | Type |
|---|---|
b |
T |
p? |
number |
T<number>
▸ length(a): number
Returns a string length
Example
import { Str } from 'tiinvo';
Str.length('hello'); // 5
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string |
number
the length of the string a
▸ lines(a): string[]
Returns an array of lines in a string.
import { Str } from 'tiinvo';
Str.lines('hello\nworld'); // ['hello', 'world']
Since
4.0.0
| Name | Type |
|---|---|
a |
string |
string[]
the array containing the lines
▸ lower(a): string
Returns a lowercased string
Example
import { Str } from 'tiinvo';
Str.lower('HELLO'); // "hello"
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string |
string
the lowercased string
▸ match(a, b): T<RegExpMatchArray>
Returns if a string a includes another string b.
Example
import { Str } from 'tiinvo';
Str.match("hello", "o") // ['o']
Str.match("hello", "k") // null
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string |
b |
string | RegExp |
the string or regular expression to search |
T<RegExpMatchArray>
Option.Some<RegExpMatchArray> if some is foundOption.None otherwise▸ match(a): Unary<T, T<RegExpMatchArray>>
Returns a unary function which checks if a string a includes another string b.
Example
import { Str } from 'tiinvo';
const matcho = Str.match("o");
matcho("hello") // ['o']
matcho("pizza") // null
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string | RegExp |
the string or regular expression to search |
the unary function
▸ padEnd(a, b, c?): T
Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length.
The padding is applied from the end (right) of the current string.
Example
import { Str } from 'tiinvo';
Str.padEnd("a", 5) // "a "
Str.padEnd("a", 5, "b") // "abbbb"
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string |
b |
number |
the pad size |
c? |
string |
the string to use to pad |
the padded string
▸ padEnd(a): (b: T, d?: T) => T
Returns a binary function which pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length.
The padding is applied from the end (right) of the current string.
Example
import { Str } from 'tiinvo';
const padEnd5 = Str.padEnd(5);
padEnd5("a") // "a "
padEnd5("a", "b") // "abbbb"
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
number |
the padsize |
fn
the binary function
▸ (b, d?): T
| Name | Type |
|---|---|
b |
T |
d? |
T |
Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length. The padding is applied from the end (right) of the current string.
If a and b parameters are passed, then the result is a padded by b.
If b parameter is not passed, returns a Unary<string, string> function and the result is b padded by a.
Example
import { Str } from 'tiinvo';
Str.padEnd("a", 5) // "a "
Str.padEnd("a", 5, "b") // "abbbb"
Str.padEnd(5)("a") // "a "
Str.padEnd(5, "b")("a") // "abbbb"
Str.padEnd(5)("a", "b") // "abbbb"
Since
4.0.0
| Name | Type |
|---|---|
a |
number |
b? |
string |
fn
▸ (b): T
| Name | Type |
|---|---|
b |
T |
▸ pascal(a): string
Formats a string to pascal case.
Example
import { Str } from 'tiinvo';
Str.pascal('hello world'); // 'HelloWorld'
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string |
string
the PascalCased string
▸ padStart(a, b, c?): T
Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length.
The padding is applied from the start (left) of the current string.
Example
import { Str } from 'tiinvo';
Str.padStart("a", 5) // " a"
Str.padStart("a", 5, "b") // "bbbba"
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string |
b |
number |
the pad size |
c? |
string |
the fill string |
the padded string
▸ padStart(a): (c: T, d?: T) => T
Returns a binary function which pads the current string with a given string (possibly repeated) so that * the resulting string reaches a given length.
The padding is applied from the start (left) of the current string.
Example
import { Str } from 'tiinvo';
const padStart5 = Str.padStart(5);
padStart5("a") // " a"
padStart5("a", "b") // "bbbba"
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
number |
the pad size |
fn
the binary function
▸ (c, d?): T
| Name | Type |
|---|---|
c |
T |
d? |
T |
▸ padStart(a, b?): (c: T) => T
Returns a binary function which pads the current string with a given string (possibly repeated) so that * the resulting string reaches a given length.
The padding is applied from the start (left) of the current string.
Example
import { Str } from 'tiinvo';
const padStart5 = Str.padStart(5, "b");
padStart5("a") // "bbbba"
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
number |
the pad size |
b? |
string |
- |
fn
the binary function
▸ (c): T
| Name | Type |
|---|---|
c |
T |
▸ repeat(a, b): T
Returns a String value that is made from count copies appended together. If count is 0, an empty string is returned.
Example
import { Str } from 'tiinvo';
Str.repeat("a", 5) // "aaaaa"
Str.repeat(5)("a") // "aaaaa"
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string to repeat |
b |
number |
the repetition count |
the repeated string
Returns a unary function which repeats a string b many times as specified in a.
If count is 0, an empty string is returned.
Example
import { Str } from 'tiinvo';
Str.repeat("a", 5) // "aaaaa"
Str.repeat(5)("a") // "aaaaa"
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
number |
the repetition count |
fn
the unary function
▸ (b): T
| Name | Type |
|---|---|
b |
T |
▸ replace(a, b, c): T
Replaces text in a string, using a regular expression or search string.
Example
import { Str } from 'tiinvo';
Str.replace("hello", "l", "e") // "heelo"
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string |
b |
string |
the the string to replace |
c |
StringReplacer |
the replacer |
the replaced string
Returns a unary function which replaces text in a string, using a regular expression or search string.
Example
import { Str } from 'tiinvo';
Str.replace("l", "e")("hello") // "heelo"
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the the string to replace |
b |
StringReplacer |
the replacer |
fn
the unary function
▸ (b): T
| Name | Type |
|---|---|
b |
T |
▸ reverse(a): string
Reverses a string.
Example
import { Str } from 'tiinvo';
Str.reverse('hello'); // 'olleh'
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string to reverse |
string
the reversed string
▸ search(a, b): T<number>
Finds the first substring match in a regular expression search.
Important: it differs from plain js String.prototype.search,
since it will return None if the index is below 0
Example
import { Str } from 'tiinvo';
Str.search("hello", "l") // 2
Str.search("hello", "k") // null
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string |
b |
StringSearcher |
the string searcher |
T<number>
Option.Some<number> if is in boundOption.None otherwise▸ search(a): (b: T) => T<number>
Returns a unary function which finds the first substring match in a regular expression search.
Important: it differs from plain js String.prototype.search,
since it will return None if the index is below 0
Example
import { Str } from 'tiinvo';
const searchl = Str.search("l");
searchl("hello") // 2
searchl("foo_bar_baz") // null
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
StringSearcher |
the string searcher |
fn
the unary function
▸ (b): T<number>
| Name | Type |
|---|---|
b |
T |
T<number>
▸ slice(a, b, c?): string
Returns a section of a string.
Example
import { Str } from 'tiinvo';
Str.slice("hello", 1) // "ello"
Str.slice("hello", 1, 3) // "el"
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string |
b |
number |
the starting index |
c? |
number |
the ending index (optional) |
string
the sliced string
▸ slice(a, b?): (b: T) => string
Returns a unary function which slices a string.
Example
import { Str } from 'tiinvo';
Str.slice(1)("hello") // "ello"
Str.slice(1, 3)("hello") // "el"
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
number |
the starting index |
b? |
number |
the ending index (optional) |
fn
the unary function
▸ (b): string
| Name | Type |
|---|---|
b |
T |
string
▸ split(a, b, c?): T[]
Split a string into substrings using the specified separator and return them as an array.
Example
import { Str } from 'tiinvo';
Str.split("hello world", " ") // ["hello", "world"]
Str.split("hello world", " ", 1) // ["hello"]
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string |
b |
StringSplitter |
the string splitter |
c? |
number |
a value used to limit the number of elements returned in the array (optional) |
T[]
the resulting array
Returns a unary function which splits a string into substrings using the specified separator and return them as an array.
Example
import { Str } from 'tiinvo';
Str.split(" ")("hello world") // ["hello", "world"]
Str.split(" ", 1)("hello world") // ["hello"]
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
StringSplitter |
the string splitter |
b? |
number |
a value used to limit the number of elements returned in the array (optional) |
the unary function
▸ trim(a): string
Trims a string both at start an the end of it.
Example
import { Str } from 'tiinvo';
Str.trim(' hello world '); // 'hello world'
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string |
string
the trimmed string
▸ trimEnd(a): string
Trims a string at it’s end.
Example
import { Str } from 'tiinvo';
Str.trimEnd(' hello world '); // ' hello world'
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string |
string
the trimmed string
▸ trimStart(a): string
Trims a string at it’s start.
Example
import { Str } from 'tiinvo';
Str.trimStart(' hello world '); // 'hello world '
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string |
string
the trimmed string
▸ upper(a): string
Returns a uppercased string
Example
import { Str } from 'tiinvo';
Str.upper('hello'); // "HELLO"
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string |
string
the uppercased string
▸ words(a): string[]
Returns an array of words in a string.
import { Str } from 'tiinvo';
Str.words('hello world'); // ['hello', 'world']
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
string |
the string |
string[]
the array containing the words in string a
▸ toArray(t): string[]
Returns an array of chars
Example
import { Str } from 'tiinvo'
Str.toArray("hello") // ["h", "e", "l", "l", "o"]
Returs
the resulting char array
Since
4.0.0
| Name | Type | Description |
|---|---|---|
t |
string |
the string |
string[]
▸ toBinArray(t): string[]
Returns an array of binarized char codes
Example
import { Str } from 'tiinvo'
Str.toBinArray("hello") // ["0b1101000", "0b1100101", "0b1101100", "0b1101100", "0b1101111"]
Returs
the resulting binary strings array
Since
4.0.0
| Name | Type | Description |
|---|---|---|
t |
string |
the string |
string[]
▸ toCharCodeArray(t): number[]
Returns an array of char codes
Example
import { Str } from 'tiinvo'
Str.toCharCodeArray("hello") // [104, 101, 108, 108, 111]
Returs
the resulting char code array
Since
4.0.0
| Name | Type | Description |
|---|---|---|
t |
string |
the string |
number[]
▸ toHexArray(t): string[]
Returns an array of hexadecimals string
Example
import { Str } from 'tiinvo'
Str.toHexArray("hello") // ["0x68", "0x65", "0x6c", "0x6c", "0x6f"]
Returs
the resulting hex char code array
Since
4.0.0
| Name | Type | Description |
|---|---|---|
t |
string |
the string |
string[]
▸ toOctArray(t): string[]
Returns an array of octal strings
Example
import { Str } from 'tiinvo'
Str.toHexArray("hello") // ["0o150", "0o145", "0o154", "0o154", "0o157"]
Returs
the resulting oct char code array
Since
4.0.0
| Name | Type | Description |
|---|---|---|
t |
string |
the string |
string[]