Text Parser
A collection of utilities for parsing and formatting text, including case transformations, byte formatting, and more.
A collection of utilities for parsing and formatting text, including case transformations, byte formatting, and more.
This library provides a comprehensive set of functions for string manipulation. It includes methods to transform, sanitize, truncate, and format strings, making it versatile for various text processing tasks in web and application development.
Transforms a string based on the specified transformation type.
Parameters:
transform: "uppercase" | "capitalize-first" | "capitalize" | "lowercase"
Defines the type of transformation.words: string | undefined
The input string to be transformed.Returns: A transformed string.
Example:
transform.uppercase("hello-world");
// "HELLO WORLD"
transform.capitalize("hello-world");
// "Hello World"
Truncates a string to a specified maximum length, preserving word boundaries and adding an ellipsis if truncated.
Parameters:
word: string
The string to truncate.maxWord: number (default: 30)
The maximum length of the string.Returns: A truncated string.
Example:
truncate("This is a long sentence that needs truncating.", 20);
// "This is a long..."
Converts a string to lowercase, removes punctuation, and replaces spaces with hyphens.
Parameters:
str: string
The input string.Returns: A sanitized and formatted string.
Example:
lowerCasePunctuation("Hello, World!");
// "hello-world"
Sanitizes a string by converting to lowercase, removing special characters, and replacing spaces with hyphens.
Parameters:
words: string | undefined
The input string to sanitize.Returns: A sanitized string.
Example:
sanitizedWord("Hello, World!");
// "hello-world"
Converts a sanitized string back to a readable format, capitalizing words while preserving conjunctions.
Parameters:
words: string | undefined
The input string to desanitize.
separator: string | RegExp (default: " " )
The word separator in the input string.
Returns: A desanitized string.
Example:
desanitizeWord("hello-world");
// "Hello World"
Compares two strings for equality, ignoring case and special characters.
Parameters:
word1: string | undefined | null
word2: string | undefined | null
Returns: boolean - Whether the strings are equal.
Example:
compareWords("Hello!", "hello");
// true
Extracts the first word from a string, split by spaces, hyphens, or tildes.
Parameters:
name: string
The input string.Returns: The first word in the string.
Example:
getFirstString("John-Doe");
// "John"
Converts a camelCase string to kebab-case or snake_case.
Parameters:
words: string
The input camelCase string.
kebab: "underscores" | "hyphens" (default: "hyphens")
The desired output style.
Returns: A kebab-case or snake_case string.
Example:
camelToKebab("helloWorld");
// "hello-world"
camelToKebab("helloWorld", "underscores");
// "hello_world"
Converts a kebab-case string to camelCase.
Parameters:
words: string
The input kebab-case string.
Returns: A camelCase string.
Example:
kebabToCamel("hello-world");
// "helloWorld"
Converts a kebab-case string to PascalCase.
Parameters:
words: string
The input kebab-case string.Returns: A PascalCase string.
Example:
toPascal("hello-world");
// "HelloWorld"
Formats a numeric input as a string. Returns the input unchanged if it contains non-numeric characters.
Parameters:
input: string | undefined
The input string.Returns: A formatted string or null if input is undefined.
Example:
formatedProgress("42");
// "42"
Splits a string into an array of objects, each containing a word as text.
Parameters:
words: string
The input string.Returns: An array of objects with the structure { text: string }
.
Example:
splitWordsToArray("hello world");
// [{ text: "hello" }, { text: "world" }]
Provides a list of mappings for HTML character entities.
Example:
htmlCharacterEntities.find(entity => entity.char === "<");
// { char: "<", entity: "<" }