@terascope/utils / strings
strings
Enumerations
Enumeration | Description |
---|---|
StringEntropy | - |
Type Aliases
StringEntropyFN()
StringEntropyFN: (
input
) =>number
Defined in: packages/utils/src/strings.ts:615
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
number
Variables
LOWER_CASE_CHARS
const
LOWER_CASE_CHARS:object
Defined in: packages/utils/src/strings.ts:256
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
NUM_CHARS
const
NUM_CHARS:object
Defined in: packages/utils/src/strings.ts:314
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
UPPER_CASE_CHARS
const
UPPER_CASE_CHARS:object
Defined in: packages/utils/src/strings.ts:285
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
WORD_CHARS
const
WORD_CHARS:object
Defined in: packages/utils/src/strings.ts:333
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
A
readonly
A:true
=true
b
readonly
b:true
=true
B
readonly
B:true
=true
c
readonly
c:true
=true
C
readonly
C:true
=true
d
readonly
d:true
=true
D
readonly
D:true
=true
e
readonly
e:true
=true
E
readonly
E:true
=true
f
readonly
f:true
=true
F
readonly
F:true
=true
g
readonly
g:true
=true
G
readonly
G:true
=true
h
readonly
h:true
=true
H
readonly
H:true
=true
i
readonly
i:true
=true
I
readonly
I:true
=true
j
readonly
j:true
=true
J
readonly
J:true
=true
k
readonly
k:true
=true
K
readonly
K:true
=true
l
readonly
l:true
=true
L
readonly
L:true
=true
m
readonly
m:true
=true
M
readonly
M:true
=true
n
readonly
n:true
=true
N
readonly
N:true
=true
o
readonly
o:true
=true
O
readonly
O:true
=true
p
readonly
p:true
=true
P
readonly
P:true
=true
q
readonly
q:true
=true
Q
readonly
Q:true
=true
r
readonly
r:true
=true
R
readonly
R:true
=true
s
readonly
s:true
=true
S
readonly
S:true
=true
t
readonly
t:true
=true
T
readonly
T:true
=true
u
readonly
u:true
=true
U
readonly
U:true
=true
v
readonly
v:true
=true
V
readonly
V:true
=true
w
readonly
w:true
=true
W
readonly
W:true
=true
x
readonly
x:true
=true
X
readonly
X:true
=true
y
readonly
y:true
=true
Y
readonly
Y:true
=true
z
readonly
z:true
=true
Z
readonly
Z:true
=true
WORD_SEPARATOR_CHARS
const
WORD_SEPARATOR_CHARS:object
Defined in: packages/utils/src/strings.ts:327
Type declaration
readonly
** **:true
=true
_
readonly
_:true
=true
-
readonly
-:true
=true
Functions
contains()
contains(
input
,substring
):input is string
Defined in: packages/utils/src/strings.ts:504
Check whether a string includes another string
Parameters
Parameter | Type |
---|---|
input | unknown |
substring | string |
Returns
input is string
containsFP()
containsFP(
substring
): (input
) =>input is string
Defined in: packages/utils/src/strings.ts:511
A function version of contains
Parameters
Parameter | Type |
---|---|
substring | string |
Returns
Function
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
input is string
endsWith()
endsWith(
str
,val
):boolean
Defined in: packages/utils/src/strings.ts:215
A native implementation of lodash endsWith
Parameters
Parameter | Type |
---|---|
str | unknown |
val | unknown |
Returns
boolean
endsWithFP()
endsWithFP(
val
): (input
) =>boolean
Defined in: packages/utils/src/strings.ts:223
A function version of startsWith
Parameters
Parameter | Type |
---|---|
val | string |
Returns
Function
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
boolean
firstToLower()
firstToLower(
str
):string
Defined in: packages/utils/src/strings.ts:446
Change first character in string to lower case
Parameters
Parameter | Type |
---|---|
str | string |
Returns
string
firstToUpper()
firstToUpper(
str
):string
Defined in: packages/utils/src/strings.ts:440
Change first character in string to upper case
Parameters
Parameter | Type |
---|---|
str | string |
Returns
string
getFirstChar()
getFirstChar(
input
):string
Defined in: packages/utils/src/strings.ts:451
Parameters
Parameter | Type |
---|---|
input | string |
Returns
string
getWordParts()
getWordParts(
input
):string
[]
Defined in: packages/utils/src/strings.ts:342
Split a string and get the word parts
Parameters
Parameter | Type |
---|---|
input | string |
Returns
string
[]
isAlpha()
isAlpha(
input
,locale
?):boolean
Defined in: packages/utils/src/strings.ts:548
Parameters
Parameter | Type |
---|---|
input | unknown |
locale ? | AlphaLocale |
Returns
boolean
isAlphaNumeric()
isAlphaNumeric(
input
,locale
?):boolean
Defined in: packages/utils/src/strings.ts:552
Parameters
Parameter | Type |
---|---|
input | unknown |
locale ? | AlphanumericLocale |
Returns
boolean
isBase64()
isBase64(
input
):boolean
Defined in: packages/utils/src/strings.ts:517
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
boolean
isCountryCode()
isCountryCode(
input
):boolean
Defined in: packages/utils/src/strings.ts:536
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
boolean
isEmail()
isEmail(
input
):input is string
Defined in: packages/utils/src/strings.ts:460
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
input is string
isFQDN()
isFQDN(
input
):boolean
Defined in: packages/utils/src/strings.ts:532
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
boolean
isMACAddress()
isMACAddress(
input
,delimiter
?):input is string
Defined in: packages/utils/src/strings.ts:472
Parameters
Parameter | Type |
---|---|
input | unknown |
delimiter ? | MACDelimiter |
Returns
input is string
isMACAddressFP()
isMACAddressFP(
args
?): (input
) =>input is string
Defined in: packages/utils/src/strings.ts:487
A functional version of isMacAddress
Parameters
Parameter | Type |
---|---|
args ? | MACDelimiter |
Returns
Function
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
input is string
isMIMEType()
isMIMEType(
input
):boolean
Defined in: packages/utils/src/strings.ts:556
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
boolean
isPort()
isPort(
input
):boolean
Defined in: packages/utils/src/strings.ts:544
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
boolean
isPostalCode()
isPostalCode(
input
,locale
):boolean
Defined in: packages/utils/src/strings.ts:540
Parameters
Parameter | Type | Default value |
---|---|---|
input | unknown | undefined |
locale | "any" | PostalCodeLocale | 'any' |
Returns
boolean
isPrimitiveValue()
isPrimitiveValue(
value
):boolean
Defined in: packages/utils/src/strings.ts:85
Check if a value is a JavaScript primitive value OR it is object with Symbol.toPrimitive
Parameters
Parameter | Type |
---|---|
value | unknown |
Returns
boolean
isString()
isString(
val
):val is string
Defined in: packages/utils/src/strings.ts:17
A simplified implementation of lodash isString
Parameters
Parameter | Type |
---|---|
val | unknown |
Returns
val is string
isURL()
isURL(
input
):boolean
Defined in: packages/utils/src/strings.ts:493
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
boolean
isUUID()
isUUID(
input
):boolean
Defined in: packages/utils/src/strings.ts:497
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
boolean
joinList()
joinList(
input
,sep
,join
):string
Defined in: packages/utils/src/strings.ts:585
Create a sentence from a list (all items will be unique, empty values will be skipped)
Parameters
Parameter | Type | Default value |
---|---|---|
input | JoinListType [] | readonly JoinListType [] | undefined |
sep | string | ',' |
join | string | 'and' |
Returns
string
parseList()
parseList(
input
):string
[]
Defined in: packages/utils/src/strings.ts:564
Maps an array of strings and and trims the result, or parses a comma separated list and trims the result
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
string
[]
primitiveToString()
primitiveToString(
value
):string
Defined in: packages/utils/src/strings.ts:100
Convert a JavaScript primitive value to a string. (Does not covert object like entities unless Symbol.toPrimitive is specified)
Parameters
Parameter | Type |
---|---|
value | unknown |
Returns
string
shannonEntropy()
shannonEntropy(
input
):number
Defined in: packages/utils/src/strings.ts:619
Performs a Shannon entropy calculation on string inputs
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
number
startsWith()
startsWith(
str
,val
):boolean
Defined in: packages/utils/src/strings.ts:197
A native implementation of lodash startsWith
Parameters
Parameter | Type |
---|---|
str | unknown |
val | unknown |
Returns
boolean
startsWithFP()
startsWithFP(
val
): (input
) =>boolean
Defined in: packages/utils/src/strings.ts:205
A function version of startsWith
Parameters
Parameter | Type |
---|---|
val | string |
Returns
Function
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
boolean
stringEntropy()
stringEntropy(
algo
):StringEntropyFN
Defined in: packages/utils/src/strings.ts:657
returns a function to perform entropy calculations, currently only supports the "shannon" algorithm
Parameters
Parameter | Type | Default value |
---|---|---|
algo | shannon | StringEntropy.shannon |
Returns
toCamelCase()
toCamelCase(
input
):string
Defined in: packages/utils/src/strings.ts:386
Parameters
Parameter | Type |
---|---|
input | string |
Returns
string
toKebabCase()
toKebabCase(
input
):string
Defined in: packages/utils/src/strings.ts:394
Parameters
Parameter | Type |
---|---|
input | string |
Returns
string
toLowerCase()
toLowerCase(
input
):string
Defined in: packages/utils/src/strings.ts:172
Converts a value to lower case
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
string
Example
toLowerCase('lowercase'); // 'lowercase'
toLowerCase('MixEd'); // 'mixed'
toLowerCase('UPPERCASE'); // 'uppercase'
toPascalCase()
toPascalCase(
input
):string
Defined in: packages/utils/src/strings.ts:390
Parameters
Parameter | Type |
---|---|
input | string |
Returns
string
toSafeString()
toSafeString(
input
):string
Defined in: packages/utils/src/strings.ts:413
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
Parameter | Type |
---|---|
input | string |
Returns
string
toSnakeCase()
toSnakeCase(
input
):string
Defined in: packages/utils/src/strings.ts:398
Parameters
Parameter | Type |
---|---|
input | string |
Returns
string
toString()
toString(
val
):string
Defined in: packages/utils/src/strings.ts:32
Safely convert any input to a string
Parameters
Parameter | Type |
---|---|
val | unknown |
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'
toTitleCase()
toTitleCase(
input
):string
Defined in: packages/utils/src/strings.ts:402
Parameters
Parameter | Type |
---|---|
input | string |
Returns
string
toUpperCase()
toUpperCase(
input
):string
Defined in: packages/utils/src/strings.ts:158
Converts a value to upper case
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
string
Example
toUpperCase('lowercase'); // 'LOWERCASE'
toUpperCase('MixEd'); // 'MIXED'
toUpperCase('UPPERCASE'); // 'UPPERCASE'
trim()
trim(
input
,char
?):string
Defined in: packages/utils/src/strings.ts:109
safely trims whitespace from an input
Parameters
Parameter | Type |
---|---|
input | unknown |
char ? | string |
Returns
string
trimAndToLower()
trimAndToLower(
input
?):string
Defined in: packages/utils/src/strings.ts:140
safely trim and to lower a input, useful for string comparison
Parameters
Parameter | Type |
---|---|
input ? | string |
Returns
string
trimAndToUpper()
trimAndToUpper(
input
?):string
Defined in: packages/utils/src/strings.ts:145
safely trim and to lower a input, useful for string comparison
Parameters
Parameter | Type |
---|---|
input ? | string |
Returns
string
trimEnd()
trimEnd(
input
,char
?):string
Defined in: packages/utils/src/strings.ts:129
Parameters
Parameter | Type |
---|---|
input | unknown |
char ? | string |
Returns
string
trimEndFP()
trimEndFP(
char
?): (input
) =>string
Defined in: packages/utils/src/strings.ts:133
Parameters
Parameter | Type |
---|---|
char ? | string |
Returns
Function
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
string
trimFP()
trimFP(
char
?): (input
) =>string
Defined in: packages/utils/src/strings.ts:113
Parameters
Parameter | Type |
---|---|
char ? | string |
Returns
Function
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
string
trimStart()
trimStart(
input
,char
?):string
Defined in: packages/utils/src/strings.ts:119
Parameters
Parameter | Type |
---|---|
input | unknown |
char ? | string |
Returns
string
trimStartFP()
trimStartFP(
char
?): (input
) =>string
Defined in: packages/utils/src/strings.ts:123
Parameters
Parameter | Type |
---|---|
char ? | string |
Returns
Function
Parameters
Parameter | Type |
---|---|
input | unknown |
Returns
string
truncate()
truncate(
value
,len
,ellipsis
):string
Defined in: packages/utils/src/strings.ts:235
Truncate a string value, by default it will add an ellipsis (...) if truncated.
Parameters
Parameter | Type | Default value |
---|---|---|
value | unknown | undefined |
len | number | undefined |
ellipsis | boolean | true |
Returns
string
truncateFP()
truncateFP(
len
,ellipsis
): (value
) =>string
Defined in: packages/utils/src/strings.ts:250
A functional version of truncate
Parameters
Parameter | Type | Default value |
---|---|---|
len | number | undefined |
ellipsis | boolean | true |
Returns
Function
Parameters
Parameter | Type |
---|---|
value | unknown |
Returns
string
unescapeString()
unescapeString(
str
):string
Defined in: packages/utils/src/strings.ts:178
Unescape characters in string and avoid double escaping
Parameters
Parameter | Type | Default value |
---|---|---|
str | string | '' |
Returns
string