Skip to main content

@terascope/utils / strings

strings

Index

Enumerations

EnumerationDescription
StringEntropy-

Type Aliases

StringEntropyFN()

StringEntropyFN: (input) => number

Parameters

ParameterType
inputunknown

Returns

number

Source

packages/utils/src/strings.ts:615

Variables

LOWER_CASE_CHARS

const LOWER_CASE_CHARS: object

Type declaration

a

readonly a: true = true

b

readonly b: true = true

c

readonly c: true = true

d

readonly d: true = true

e

readonly e: true = true

f

readonly f: true = true

g

readonly g: true = true

h

readonly h: true = true

i

readonly i: true = true

j

readonly j: true = true

k

readonly k: true = true

l

readonly l: true = true

m

readonly m: true = true

n

readonly n: true = true

o

readonly o: true = true

p

readonly p: true = true

q

readonly q: true = true

r

readonly r: true = true

s

readonly s: true = true

t

readonly t: true = true

u

readonly u: true = true

v

readonly v: true = true

w

readonly w: true = true

x

readonly x: true = true

y

readonly y: true = true

z

readonly z: true = true

Source

packages/utils/src/strings.ts:256


NUM_CHARS

const NUM_CHARS: object

Type declaration

0

readonly 0: true = true

1

readonly 1: true = true

2

readonly 2: true = true

3

readonly 3: true = true

4

readonly 4: true = true

5

readonly 5: true = true

6

readonly 6: true = true

7

readonly 7: true = true

8

readonly 8: true = true

9

readonly 9: true = true

Source

packages/utils/src/strings.ts:314


UPPER_CASE_CHARS

const UPPER_CASE_CHARS: object

Type declaration

A

readonly A: true = true

B

readonly B: true = true

C

readonly C: true = true

D

readonly D: true = true

E

readonly E: true = true

F

readonly F: true = true

G

readonly G: true = true

H

readonly H: true = true

I

readonly I: true = true

J

readonly J: true = true

K

readonly K: true = true

L

readonly L: true = true

M

readonly M: true = true

N

readonly N: true = true

O

readonly O: true = true

P

readonly P: true = true

Q

readonly Q: true = true

R

readonly R: true = true

S

readonly S: true = true

T

readonly T: true = true

U

readonly U: true = true

V

readonly V: true = true

W

readonly W: true = true

X

readonly X: true = true

Y

readonly Y: true = true

Z

readonly Z: true = true

Source

packages/utils/src/strings.ts:285


WORD_CHARS

const WORD_CHARS: object

Type declaration

0

readonly 0: true = true

1

readonly 1: true = true

2

readonly 2: true = true

3

readonly 3: true = true

4

readonly 4: true = true

5

readonly 5: true = true

6

readonly 6: true = true

7

readonly 7: true = true

8

readonly 8: true = true

9

readonly 9: true = true

A

readonly A: true = true

B

readonly B: true = true

C

readonly C: true = true

D

readonly D: true = true

E

readonly E: true = true

F

readonly F: true = true

G

readonly G: true = true

H

readonly H: true = true

I

readonly I: true = true

J

readonly J: true = true

K

readonly K: true = true

L

readonly L: true = true

M

readonly M: true = true

N

readonly N: true = true

O

readonly O: true = true

P

readonly P: true = true

Q

readonly Q: true = true

R

readonly R: true = true

S

readonly S: true = true

T

readonly T: true = true

U

readonly U: true = true

V

readonly V: true = true

W

readonly W: true = true

X

readonly X: true = true

Y

readonly Y: true = true

Z

readonly Z: true = true

a

readonly a: true = true

b

readonly b: true = true

c

readonly c: true = true

d

readonly d: true = true

e

readonly e: true = true

f

readonly f: true = true

g

readonly g: true = true

h

readonly h: true = true

i

readonly i: true = true

j

readonly j: true = true

k

readonly k: true = true

l

readonly l: true = true

m

readonly m: true = true

n

readonly n: true = true

o

readonly o: true = true

p

readonly p: true = true

q

readonly q: true = true

r

readonly r: true = true

s

readonly s: true = true

t

readonly t: true = true

u

readonly u: true = true

v

readonly v: true = true

w

readonly w: true = true

x

readonly x: true = true

y

readonly y: true = true

z

readonly z: true = true

Source

packages/utils/src/strings.ts:333


WORD_SEPARATOR_CHARS

const WORD_SEPARATOR_CHARS: object

Type declaration

readonly ** **: true = true

-

readonly -: true = true

_

readonly _: true = true

Source

packages/utils/src/strings.ts:327

Functions

contains()

contains(input, substring): input is string

Check whether a string includes another string

Parameters

ParameterType
inputunknown
substringstring

Returns

input is string

Source

packages/utils/src/strings.ts:504


containsFP()

containsFP(substring): (input) => input is string

A function version of contains

Parameters

ParameterType
substringstring

Returns

Function

Parameters
ParameterType
inputunknown
Returns

input is string

Source

packages/utils/src/strings.ts:511


endsWith()

endsWith(str, val): boolean

A native implementation of lodash endsWith

Parameters

ParameterType
strunknown
valunknown

Returns

boolean

Source

packages/utils/src/strings.ts:215


endsWithFP()

endsWithFP(val): (input) => boolean

A function version of startsWith

Parameters

ParameterType
valstring

Returns

Function

Parameters
ParameterType
inputunknown
Returns

boolean

Source

packages/utils/src/strings.ts:223


firstToLower()

firstToLower(str): string

Change first character in string to lower case

Parameters

ParameterType
strstring

Returns

string

Source

packages/utils/src/strings.ts:446


firstToUpper()

firstToUpper(str): string

Change first character in string to upper case

Parameters

ParameterType
strstring

Returns

string

Source

packages/utils/src/strings.ts:440


getFirstChar()

getFirstChar(input): string

Parameters

ParameterType
inputstring

Returns

string

Source

packages/utils/src/strings.ts:451


getWordParts()

getWordParts(input): string[]

Split a string and get the word parts

Parameters

ParameterType
inputstring

Returns

string[]

Source

packages/utils/src/strings.ts:342


isAlpha()

isAlpha(input, locale?): boolean

Parameters

ParameterType
inputunknown
locale?AlphaLocale

Returns

boolean

Source

packages/utils/src/strings.ts:548


isAlphaNumeric()

isAlphaNumeric(input, locale?): boolean

Parameters

ParameterType
inputunknown
locale?AlphanumericLocale

Returns

boolean

Source

packages/utils/src/strings.ts:552


isBase64()

isBase64(input): boolean

Parameters

ParameterType
inputunknown

Returns

boolean

Source

packages/utils/src/strings.ts:517


isCountryCode()

isCountryCode(input): boolean

Parameters

ParameterType
inputunknown

Returns

boolean

Source

packages/utils/src/strings.ts:536


isEmail()

isEmail(input): input is string

Parameters

ParameterType
inputunknown

Returns

input is string

Source

packages/utils/src/strings.ts:460


isFQDN()

isFQDN(input): boolean

Parameters

ParameterType
inputunknown

Returns

boolean

Source

packages/utils/src/strings.ts:532


isMACAddress()

isMACAddress(input, delimiter?): input is string

Parameters

ParameterType
inputunknown
delimiter?MACDelimiter

Returns

input is string

Source

packages/utils/src/strings.ts:472


isMACAddressFP()

isMACAddressFP(args?): (input) => input is string

A functional version of isMacAddress

Parameters

ParameterType
args?MACDelimiter

Returns

Function

Parameters
ParameterType
inputunknown
Returns

input is string

Source

packages/utils/src/strings.ts:487


isMIMEType()

isMIMEType(input): boolean

Parameters

ParameterType
inputunknown

Returns

boolean

Source

packages/utils/src/strings.ts:556


isPort()

isPort(input): boolean

Parameters

ParameterType
inputunknown

Returns

boolean

Source

packages/utils/src/strings.ts:544


isPostalCode()

isPostalCode(input, locale): boolean

Parameters

ParameterTypeDefault value
inputunknownundefined
locale"any" | PostalCodeLocale'any'

Returns

boolean

Source

packages/utils/src/strings.ts:540


isPrimitiveValue()

isPrimitiveValue(value): boolean

Check if a value is a JavaScript primitive value OR it is object with Symbol.toPrimitive

Parameters

ParameterType
valueunknown

Returns

boolean

Source

packages/utils/src/strings.ts:85


isString()

isString(val): val is string

A simplified implementation of lodash isString

Parameters

ParameterType
valunknown

Returns

val is string

Source

packages/utils/src/strings.ts:17


isURL()

isURL(input): boolean

Parameters

ParameterType
inputunknown

Returns

boolean

Source

packages/utils/src/strings.ts:493


isUUID()

isUUID(input): boolean

Parameters

ParameterType
inputunknown

Returns

boolean

Source

packages/utils/src/strings.ts:497


joinList()

joinList(input, sep, join): string

Create a sentence from a list (all items will be unique, empty values will be skipped)

Parameters

ParameterTypeDefault value
inputJoinListType[] | readonly JoinListType[]undefined
sepstring','
joinstring'and'

Returns

string

Source

packages/utils/src/strings.ts:585


parseList()

parseList(input): string[]

Maps an array of strings and and trims the result, or parses a comma separated list and trims the result

Parameters

ParameterType
inputunknown

Returns

string[]

Source

packages/utils/src/strings.ts:564


primitiveToString()

primitiveToString(value): string

Convert a JavaScript primitive value to a string. (Does not covert object like entities unless Symbol.toPrimitive is specified)

Parameters

ParameterType
valueunknown

Returns

string

Source

packages/utils/src/strings.ts:100


shannonEntropy()

shannonEntropy(input): number

Performs a Shannon entropy calculation on string inputs

Parameters

ParameterType
inputunknown

Returns

number

Source

packages/utils/src/strings.ts:619


startsWith()

startsWith(str, val): boolean

A native implementation of lodash startsWith

Parameters

ParameterType
strunknown
valunknown

Returns

boolean

Source

packages/utils/src/strings.ts:197


startsWithFP()

startsWithFP(val): (input) => boolean

A function version of startsWith

Parameters

ParameterType
valstring

Returns

Function

Parameters
ParameterType
inputunknown
Returns

boolean

Source

packages/utils/src/strings.ts:205


stringEntropy()

stringEntropy(algo): StringEntropyFN

returns a function to perform entropy calculations, currently only supports the "shannon" algorithm

Parameters

ParameterTypeDefault value
algoshannonStringEntropy.shannon

Returns

StringEntropyFN

Source

packages/utils/src/strings.ts:657


toCamelCase()

toCamelCase(input): string

Parameters

ParameterType
inputstring

Returns

string

Source

packages/utils/src/strings.ts:386


toKebabCase()

toKebabCase(input): string

Parameters

ParameterType
inputstring

Returns

string

Source

packages/utils/src/strings.ts:394


toLowerCase()

toLowerCase(input): string

Converts a value to lower case

Parameters

ParameterType
inputunknown

Returns

string

Example

toLowerCase('lowercase'); // 'lowercase'
toLowerCase('MixEd'); // 'mixed'
toLowerCase('UPPERCASE'); // 'uppercase'

Source

packages/utils/src/strings.ts:172


toPascalCase()

toPascalCase(input): string

Parameters

ParameterType
inputstring

Returns

string

Source

packages/utils/src/strings.ts:390


toSafeString()

toSafeString(input): string

Make a string url/elasticsearch safe. safeString converts the string to lower case, removes any invalid characters, and replaces whitespace with _ (if it exists in the string) or - Warning this may reduce the str length

Parameters

ParameterType
inputstring

Returns

string

Source

packages/utils/src/strings.ts:413


toSnakeCase()

toSnakeCase(input): string

Parameters

ParameterType
inputstring

Returns

string

Source

packages/utils/src/strings.ts:398


toString()

toString(val): string

Safely convert any input to a string

Parameters

ParameterType
valunknown

Returns

string

Example

toString(1); // '1'
toString(0.01); // '0.01'
toString(true); // 'true'
toString(BigInt(2) ** BigInt(64)); // '18,446,744,073,709,551,616'
toString(new Date('2020-09-23T14:54:21.020Z')) // '2020-09-23T14:54:21.020Z'

Source

packages/utils/src/strings.ts:32


toTitleCase()

toTitleCase(input): string

Parameters

ParameterType
inputstring

Returns

string

Source

packages/utils/src/strings.ts:402


toUpperCase()

toUpperCase(input): string

Converts a value to upper case

Parameters

ParameterType
inputunknown

Returns

string

Example

toUpperCase('lowercase'); // 'LOWERCASE'
toUpperCase('MixEd'); // 'MIXED'
toUpperCase('UPPERCASE'); // 'UPPERCASE'

Source

packages/utils/src/strings.ts:158


trim()

trim(input, char?): string

safely trims whitespace from an input

Parameters

ParameterType
inputunknown
char?string

Returns

string

Source

packages/utils/src/strings.ts:109


trimAndToLower()

trimAndToLower(input?): string

safely trim and to lower a input, useful for string comparison

Parameters

ParameterType
input?string

Returns

string

Source

packages/utils/src/strings.ts:140


trimAndToUpper()

trimAndToUpper(input?): string

safely trim and to lower a input, useful for string comparison

Parameters

ParameterType
input?string

Returns

string

Source

packages/utils/src/strings.ts:145


trimEnd()

trimEnd(input, char?): string

Parameters

ParameterType
inputunknown
char?string

Returns

string

Source

packages/utils/src/strings.ts:129


trimEndFP()

trimEndFP(char?): (input) => string

Parameters

ParameterType
char?string

Returns

Function

Parameters
ParameterType
inputunknown
Returns

string

Source

packages/utils/src/strings.ts:133


trimFP()

trimFP(char?): (input) => string

Parameters

ParameterType
char?string

Returns

Function

Parameters
ParameterType
inputunknown
Returns

string

Source

packages/utils/src/strings.ts:113


trimStart()

trimStart(input, char?): string

Parameters

ParameterType
inputunknown
char?string

Returns

string

Source

packages/utils/src/strings.ts:119


trimStartFP()

trimStartFP(char?): (input) => string

Parameters

ParameterType
char?string

Returns

Function

Parameters
ParameterType
inputunknown
Returns

string

Source

packages/utils/src/strings.ts:123


truncate()

truncate(value, len, ellipsis): string

Truncate a string value, by default it will add an ellipsis (...) if truncated.

Parameters

ParameterTypeDefault value
valueunknownundefined
lennumberundefined
ellipsisbooleantrue

Returns

string

Source

packages/utils/src/strings.ts:235


truncateFP()

truncateFP(len, ellipsis): (value) => string

A functional version of truncate

Parameters

ParameterTypeDefault value
lennumberundefined
ellipsisbooleantrue

Returns

Function

Parameters
ParameterType
valueunknown
Returns

string

Source

packages/utils/src/strings.ts:250


unescapeString()

unescapeString(str): string

Unescape characters in string and avoid double escaping

Parameters

ParameterTypeDefault value
strstring''

Returns

string

Source

packages/utils/src/strings.ts:178