tiinvo

tiinvo / Exports / Str

Namespace: Str

Table of contents

Type Aliases

Guardables

Comparables

Functions

Natives

Serializables

Type Aliases

T

Ƭ T: string

The type alias for string

Since

4.0.0

Defined in

src/Str.ts:10


StringReplacer

Ƭ StringReplacer: T | RegExp | Unary<T, T>

A replacer argument.

It could be either:

Since

4.0.0

Defined in

src/Str.ts:22


StringSearcher

Ƭ StringSearcher: T | { [search]: (string: string) => number }

A string searcher argument

Since

4.0.0

Defined in

src/Str.ts:28


StringSplitter

Ƭ StringSplitter: T | { [split]: (string: string, limit?: number) => string[] }

A string splitter argument

Since

4.0.0

Defined in

src/Str.ts:36

Guardables

guard

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

Parameters

Name Type Description
x unknown the value to check

Returns

x is string

Defined in

src/Functors.ts:338

Comparables

cmp

cmp(a, b): ComparableResult

Compares two strings a and b.

Returns:

Important: 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

Parameters

Name Type Description
a string the first string
b string the last string

Returns

ComparableResult

Defined in

src/Str.ts:100

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

Parameters

Name Type Description
a string the left-hand compared string

Returns

Unary<T, ComparableResult>

the unary function

Defined in

src/Str.ts:123


eq

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

Parameters

Name Type Description
a string the first string
b string -

Returns

boolean

Defined in

src/Str.ts:157

eq(a): Unary<T, boolean>

Returns 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

Parameters

Name Type Description
a string the first string

Returns

Unary<T, boolean>

the unary function

Defined in

src/Str.ts:176

Functions

asc

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

Parameters

Name Type
a string
b string

Returns

ComparableResult

Defined in

src/Str.ts:209

asc(a): Unary<T, ComparableResult>

Parameters

Name Type
a string

Returns

Unary<T, ComparableResult>

Defined in

src/Str.ts:210


desc

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

Parameters

Name Type
a string
b string

Returns

ComparableResult

Defined in

src/Str.ts:239

desc(a): Unary<T, ComparableResult>

Parameters

Name Type
a string

Returns

Unary<T, ComparableResult>

Defined in

src/Str.ts:240


toInt32Array

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

Parameters

Name Type
t string

Returns

Int32Array

Defined in

src/Str.ts:1400

Natives

camel

camel(a): string

Formats a string to camel case.

Example

import { Str } from 'tiinvo';

Str.camel('hello world'); // 'helloWorld'

Since

4.0.0

Parameters

Name Type Description
a string the string

Returns

string

the camelCased string

Defined in

src/Fn.ts:22


charAt

charAt(a, b): T<T>

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

Parameters

Name Type Description
a string the string
b number the char index

Returns

T<T>

Defined in

src/Str.ts:295

charAt(a): Unary<T, T<T>>

Returns 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

Parameters

Name Type Description
a number the index

Returns

Unary<T, T<T>>

the unary function

Defined in

src/Str.ts:314


charCodeAt

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

Parameters

Name Type Description
a string the string
b number the index

Returns

T<number>

Defined in

src/Str.ts:359

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

Parameters

Name Type Description
a number the index

Returns

Unary<T, T<number>>

the unary function

Defined in

src/Str.ts:379


chars

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

Parameters

Name Type Description
a string the string

Returns

string[]

the array of characters

Defined in

src/Fn.ts:22


concat

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

Parameters

Name Type Description
a string the first string
b string the last string

Returns

T

the concatenated string

Defined in

src/Str.ts:434

concat(a): Unary<T, T>

Returns a unary function which concatenates two strings in one.

Example

import { Str } from 'tiinvo';

Str.concat("world")("hello")         // "helloworld"

Since

4.0.0

Parameters

Name Type Description
a string the last string

Returns

Unary<T, T>

the unary function

Defined in

src/Str.ts:451


endsWith

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

Parameters

Name Type Description
a string the string
b string the ending string

Returns

boolean

Defined in

src/Str.ts:481

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

Parameters

Name Type Description
a string the ending string

Returns

Unary<T, boolean>

the unary function

Defined in

src/Str.ts:501


includes

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

Parameters

Name Type Description
a string the string
b string the string to search

Returns

boolean

Defined in

src/Str.ts:532

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

Parameters

Name Type Description
a string the string

Returns

Unary<T, boolean>

the unary function

Defined in

src/Str.ts:552


indexOf

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

Parameters

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.

Returns

T<number>

Defined in

src/Str.ts:586

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

Parameters

Name Type Description
a string the string

Returns

fn

the binary function

▸ (b, i?): T<number>

Parameters
Name Type
b T
i? number
Returns

T<number>

Defined in

src/Str.ts:606


lastIndexOf

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

Parameters

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.

Returns

T<number>

Defined in

src/Str.ts:638

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

Parameters

Name Type Description
a string the string to search

Returns

fn

the binary function

▸ (b, p?): T<number>

Parameters
Name Type
b T
p? number
Returns

T<number>

Defined in

src/Str.ts:655


length

length(a): number

Returns a string length

Example

import { Str } from 'tiinvo';

Str.length('hello'); // 5

Since

4.0.0

Parameters

Name Type Description
a string the string

Returns

number

the length of the string a

Defined in

src/Fn.ts:22


lines

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

Parameters

Name Type
a string

Returns

string[]

the array containing the lines

Defined in

src/Fn.ts:22


lower

lower(a): string

Returns a lowercased string

Example

import { Str } from 'tiinvo';

Str.lower('HELLO'); // "hello"

Since

4.0.0

Parameters

Name Type Description
a string the string

Returns

string

the lowercased string

Defined in

src/Fn.ts:22


match

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

Parameters

Name Type Description
a string the string
b string | RegExp the string or regular expression to search

Returns

T<RegExpMatchArray>

Defined in

src/Str.ts:739

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

Parameters

Name Type Description
a string | RegExp the string or regular expression to search

Returns

Unary<T, T<RegExpMatchArray>>

the unary function

Defined in

src/Str.ts:759


padEnd

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

Parameters

Name Type Description
a string the string
b number the pad size
c? string the string to use to pad

Returns

T

the padded string

Defined in

src/Str.ts:792

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

Parameters

Name Type Description
a number the padsize

Returns

fn

the binary function

▸ (b, d?): T

Parameters
Name Type
b T
d? T
Returns

T

Defined in

src/Str.ts:815

padEnd(a, b?): (b: T) => 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

Parameters

Name Type
a number
b? string

Returns

fn

▸ (b): T

Parameters
Name Type
b T
Returns

T

Defined in

src/Str.ts:838


pascal

pascal(a): string

Formats a string to pascal case.

Example

import { Str } from 'tiinvo';

Str.pascal('hello world'); // 'HelloWorld'

Since

4.0.0

Parameters

Name Type Description
a string the string

Returns

string

the PascalCased string

Defined in

src/Fn.ts:22


padStart

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

Parameters

Name Type Description
a string the string
b number the pad size
c? string the fill string

Returns

T

the padded string

Defined in

src/Str.ts:889

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

Parameters

Name Type Description
a number the pad size

Returns

fn

the binary function

▸ (c, d?): T

Parameters
Name Type
c T
d? T
Returns

T

Defined in

src/Str.ts:913

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

Parameters

Name Type Description
a number the pad size
b? string -

Returns

fn

the binary function

▸ (c): T

Parameters
Name Type
c T
Returns

T

Defined in

src/Str.ts:936


repeat

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

Parameters

Name Type Description
a string the string to repeat
b number the repetition count

Returns

T

the repeated string

Defined in

src/Str.ts:966

repeat(a): (b: T) => T

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

Parameters

Name Type Description
a number the repetition count

Returns

fn

the unary function

▸ (b): T

Parameters
Name Type
b T
Returns

T

Defined in

src/Str.ts:985


replace

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

Parameters

Name Type Description
a string the string
b string the the string to replace
c StringReplacer the replacer

Returns

T

the replaced string

Defined in

src/Str.ts:1014

replace(a, b): (b: T) => T

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

Parameters

Name Type Description
a string the the string to replace
b StringReplacer the replacer

Returns

fn

the unary function

▸ (b): T

Parameters
Name Type
b T
Returns

T

Defined in

src/Str.ts:1033


reverse

reverse(a): string

Reverses a string.

Example

import { Str } from 'tiinvo';

Str.reverse('hello'); // 'olleh'

Since

4.0.0

Parameters

Name Type Description
a string the string to reverse

Returns

string

the reversed string

Defined in

src/Fn.ts:22


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

Parameters

Name Type Description
a string the string
b StringSearcher the string searcher

Returns

T<number>

Defined in

src/Str.ts:1085

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

Parameters

Name Type Description
a StringSearcher the string searcher

Returns

fn

the unary function

▸ (b): T<number>

Parameters
Name Type
b T
Returns

T<number>

Defined in

src/Str.ts:1109


slice

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

Parameters

Name Type Description
a string the string
b number the starting index
c? number the ending index (optional)

Returns

string

the sliced string

Defined in

src/Str.ts:1141

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

Parameters

Name Type Description
a number the starting index
b? number the ending index (optional)

Returns

fn

the unary function

▸ (b): string

Parameters
Name Type
b T
Returns

string

Defined in

src/Str.ts:1160


split

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

Parameters

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)

Returns

T[]

the resulting array

Defined in

src/Str.ts:1191

split(a, b?): Unary<T, T[]>

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

Parameters

Name Type Description
a StringSplitter the string splitter
b? number a value used to limit the number of elements returned in the array (optional)

Returns

Unary<T, T[]>

the unary function

Defined in

src/Str.ts:1211


trim

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

Parameters

Name Type Description
a string the string

Returns

string

the trimmed string

Defined in

src/Fn.ts:22


trimEnd

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

Parameters

Name Type Description
a string the string

Returns

string

the trimmed string

Defined in

src/Fn.ts:22


trimStart

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

Parameters

Name Type Description
a string the string

Returns

string

the trimmed string

Defined in

src/Fn.ts:22


upper

upper(a): string

Returns a uppercased string

Example

import { Str } from 'tiinvo';

Str.upper('hello'); // "HELLO"

Since

4.0.0

Parameters

Name Type Description
a string the string

Returns

string

the uppercased string

Defined in

src/Fn.ts:22


words

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

Parameters

Name Type Description
a string the string

Returns

string[]

the array containing the words in string a

Defined in

src/Fn.ts:22

Serializables

toArray

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

Parameters

Name Type Description
t string the string

Returns

string[]

Defined in

src/Str.ts:1330


toBinArray

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

Parameters

Name Type Description
t string the string

Returns

string[]

Defined in

src/Str.ts:1348


toCharCodeArray

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

Parameters

Name Type Description
t string the string

Returns

number[]

Defined in

src/Str.ts:1366


toHexArray

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

Parameters

Name Type Description
t string the string

Returns

string[]

Defined in

src/Str.ts:1384


toOctArray

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

Parameters

Name Type Description
t string the string

Returns

string[]

Defined in

src/Str.ts:1418