Namespace String
String utilities for validation, formatting, transformation, and parsing.
Install
Use this namespace only:
bash
npm i @litert/utils-stringOr install the full bundle:
bash
npm i @litert/utilsAnd then import from it.
ts
import * as LibUtils from '@litert/utils';
LibUtils.String.nameCase(str);
// or
import { String as LibString } from '@litert/utils';
LibString.nameCase(str);Exports
Classes
| Name | Description |
|---|---|
UnitParser | Extracts a numeric value and a unit name from a string using a configurable format. |
Functions
| Name | Description |
|---|---|
includeEvilWhitespaceChars | Checks if a string contains invisible "evil" whitespace characters. |
replaceEvilWhitespaceChars | Replaces invisible "evil" whitespace characters. |
includeEvilSpaceChars | ⚠️ Deprecated alias for includeEvilWhitespaceChars. |
replaceEvilSpaceChars | ⚠️ Deprecated alias for replaceEvilWhitespaceChars. |
htmlEscape | Escapes HTML special characters in a string. |
isEmailAddress | Validates an email address string. |
splitIntoLines | Splits a string by EOL characters into an array of lines. |
toUnixString | Converts all line endings to Unix-style (\n). |
toWindowsString | Converts all line endings to Windows-style (\r\n). |
toMacString | Converts all line endings to Mac-style (\r). |
isUpperSnakeCase | Checks if a string is in UPPER_SNAKE_CASE format. |
isLowerSnakeCase | Checks if a string is in lower_snake_case format. |
isUpperCamelCase | Checks if a string is in UpperCamelCase format. |
isPascalCase | Alias for isUpperCamelCase. Checks PascalCase format. |
isLowerCamelCase | Checks if a string is in lowerCamelCase format. |
random | Generates a random string of specified length from a charset. |
regexpEscape | Escapes special characters for use inside a RegExp. |
toChunks | Splits a string into equal-sized chunks (left to right). |
toChunksBackward | Splits a string into equal-sized chunks (right to left). |
Constants
| Name | Description |
|---|---|
ERandomStringCharset | Enum of predefined character sets for random string generation. |
DEFAULT_RANDOM_CHARSET | Default charset combining upper/lower alpha and digits. |
Typings
| Name | Description |
|---|---|
IEmailValidationOptions | Options for the isEmailAddress function. |
IUnitInfo | Options for a single unit in UnitParser. |
IUnitParserOptions | Constructor options for UnitParser. |
IUnitParserResult | Return type of UnitParser.parse(). |