Skip to content

API Reference ​

A complete overview of all utility functions provided by @rcpthongta/string-utils.

Case Conversion ​

Convert strings between various identifier casing conventions.

FunctionDescription
camelCaseConverts a string to camelCase.
constantCaseConverts a string to uppercase CONSTANT_CASE.
kebabCaseConverts a string to kebab-case.
pascalCaseConverts a string to PascalCase.
snakeCaseConverts a string to snake_case.

Casing & Capitalization ​

Transform the first character casing while preserving literal TypeScript types.

FunctionDescription
capitalizeCapitalizes the first character of a string.
uncapitalizeConverts the first character of a string to lowercase.

Formatting & Templating ​

Clean up, interpolate, and transform strings for display or URLs.

FunctionDescription
collapseWhitespaceNormalizes consecutive whitespace into single spaces and trims edges.
formatFormats a template string with positional or nested property placeholders.
createFormatterPrecompiles a reusable formatter function for high performance.
slugifyConverts a string into a URL-friendly slug.

Pattern Masking ​

Apply pattern masks to format phone numbers, dates, credit cards, and postal codes.

FunctionDescription
maskFormats a string against custom pattern templates.
createMaskPrecompiles a reusable mask function for high performance.

Validation & Fallback ​

Type guards and safe fallback utilities for strings.

FunctionDescription
hasLengthType guard checking whether a value is a non-empty string (length > 0).
hasTextType guard checking whether a string has non-whitespace characters.
defaultIfBlankReturns a fallback value when input is blank (empty or whitespace-only).
defaultIfEmptyReturns a fallback value when input is empty (length === 0).

Privacy & Redaction ​

Censor and mask sensitive information for security and privacy.

FunctionDescription
redactCensors sensitive string content with custom visible boundaries and replacement characters.

Released under the MIT License.