Skip to content

text

normalizeString

Signature

javascript
normalizeString(str, options)

Description

Normalize a string before comparison by applying transformations based on the provided options. Used internally by text.isEqual and text.compare.

Parameters

NameTypeRequiredDescription
strstringyesThe string to normalize
optionsobjectnoNormalization options
options.ignoreSpacesbooleannoTrim leading and trailing whitespace (default: false)
options.ignoreAccentsbooleannoStrip accent characters (default: false)
options.ignoreCasebooleannoConvert to lowercase (default: false)

Returns

TypeDescription
stringThe normalized string

Examples

javascript
normalizeString('  Hello  ', { ignoreSpaces: true })
// 'Hello'
normalizeString('Héllo', { ignoreAccents: true })
// 'Hello'
normalizeString('Hello', { ignoreCase: true })
// 'hello'
normalizeString('  Héllo  ', { ignoreSpaces: true, ignoreAccents: true, ignoreCase: true })
// 'hello'

isEqual

Signature

javascript
text.isEqual(text1, text2, options)

Description

Check if two strings are equal after optional normalization.

Parameters

NameTypeRequiredDescription
text1stringyesThe first string
text2stringyesThe second string
optionsobjectnoNormalization options (see normalizeString)

Returns

TypeDescription
booleanTrue if both strings are equal after normalization

Examples

javascript
text.isEqual('hello', 'hello')
// true
text.isEqual('Hello', 'hello', { ignoreCase: true })
// true
text.isEqual('  hello', 'hello', { ignoreSpaces: true })
// true
text.isEqual('héllo', 'hello', { ignoreAccents: true })
// true
text.isEqual('hello', 'world')
// false

isEqualFile

Signature

javascript
text.isEqualFile(content, filePath, options)

Description

Check if a string is equal to the content of a file after optional normalization.

Parameters

NameTypeRequiredDescription
contentstringyesThe string to compare
filePathstringyesPath to the file
optionsobjectnoNormalization options (see normalizeString)

Returns

TypeDescription
booleanTrue if the string match the file content

Examples

javascript
text.isEqualFile('hello world', './fixtures/expected.txt')
// true or false
text.isEqualFile('Hello World', './fixtures/expected.txt', { ignoreCase: true })
// true or false

isEqualFiles

Signature

javascript
text.isEqualFiles(path1, path2, options)

Description

Check if two files have equal content after optional normalization.

Parameters

NameTypeRequiredDescription
path1stringyesPath to the first file
path2stringyesPath to the second file
optionsobjectnoNormalization options (see normalizeString)

Returns

TypeDescription
booleanTrue if both files have equal content

Examples

javascript
text.isEqualFiles('./fixtures/actual.txt', './fixtures/expected.txt')
// true or false
text.isEqualFiles('./fixtures/actual.txt', './fixtures/expected.txt', { ignoreCase: true })
// true or false