@razomy/string-case
v0.0.1-beta.4
Published
Utility functions for advanced string casing conversions and manipulations
Maintainers
Readme
@razomy/string-case
Utility functions for advanced string casing conversions and manipulations
🚀 Start
Install
npm i @razomy/string-caseImport
import * as stringCase from '@razomy/string-case';
// or
import { abbreviation } from '@razomy/string-case';📑 Table of Contents
Functions
- abbreviation
- alternatingCase
- camelCase
- capitalize
- constantCase
- dotCase
- headerCase
- humanize
- isAlpha
- isAlphanumeric
- isLowerCase
- isUpperCase
- kebabCase
- lowerCase
- pascalCase
- pathCase
- reverse
- sentenceCase
- slugify
- snakeCase
- swapCase
- titleCase
- upperCase
📚 Documentation
Functions
abbreviation
abbreviation(text: string): string
Get abbreviation from string. Takes a string of words separated by spaces, hyphens, or underscores, and returns an abbreviation formed by concatenating the first letter of each word.
Examples
abbreviation('Hello World'); // HWabbreviation('node package manager'); // npmabbreviation('Read-Only_Memory'); // ROMalternatingCase
alternatingCase(text: string): string
Convert string to aLtErNaTiNg cAsE (SpongeBob case). Alternates cases based on the index of the character (ignoring spaces is optional, this implementation alternates strictly by character position).
Examples
alternatingCase('hello world'); // hElLo wOrLdalternatingCase('typescript'); // tYpEsCrIpTcamelCase
camelCase(text: string): string
Converts a string to camel case. Takes an input string in any common format (space-separated, kebab-case, snake_case, PascalCase, etc.) and converts it to camelCase. The function first normalizes the string by identifying word boundaries (including transitions between acronyms, letters/numbers, and common delimiters like spaces, hyphens, dots, and underscores), then joins the segments together with the first segment in lowercase and each subsequent segment capitalized.
Examples
camelCase('Foo Bar'); // fooBarcamelCase('--foo-bar--'); // fooBarcamelCase('__FOO_BAR__'); // fooBarcapitalize
capitalize(text: string): string
Converts the first character of string to upper case and the remaining to lower case. Takes an input string and returns a new string where the first character is converted to upper case and all remaining characters are converted to lower case. This is useful for normalizing the casing of words regardless of their original casing.
Examples
capitalize('razomy'); // Razomycapitalize('RAZOMY'); // Razomycapitalize('rAZOMY'); // RazomyconstantCase
constantCase(text: string): string
Convert string to CONSTANT_CASE (macro case). Converts a given string from any common casing convention (camelCase, kebab-case, snake_case, space-separated, etc.) to CONSTANT_CASE (also known as macro case or screaming snake case), where all letters are uppercased and words are separated by underscores.
Examples
constantCase('hello world'); // HELLO_WORLDconstantCase('camelCaseString'); // CAMEL_CASE_STRINGconstantCase('kebab-case-test'); // KEBAB_CASE_TESTdotCase
dotCase(text: string): string
Convert string to dot.case. Converts a given string into dot.case format by splitting the input on camelCase boundaries, non-alphanumeric characters, and whitespace, then joining the resulting lowercase words with dots.
Examples
dotCase('Hello World'); // hello.worlddotCase('camelCaseString'); // camel.case.stringdotCase('foo_bar'); // foo.barheaderCase
headerCase(text: string): string
Convert string to Header-Case (Train-Case). Converts a given string into Header-Case (also known as Train-Case), where each word is capitalized and separated by hyphens. The function handles various input formats including camelCase, snake_case, and strings with arbitrary delimiters by first splitting the text into individual words, capitalizing the first letter of each word, lowercasing the rest, and then joining them with hyphens.
Examples
headerCase('hello world'); // Hello-WorldheaderCase('camelCaseString'); // Camel-Case-StringheaderCase('session_id'); // Session-Idhumanize
humanize(text: string): string
Convert a string to a human-readable form. Transforms a string from common programming naming conventions (camelCase, snake_case, kebab-case) into a human-readable sentence. It splits words by detecting camelCase boundaries, underscores, and hyphens, normalizes whitespace, converts the result to lowercase, and capitalizes the first letter.
Examples
humanize('camelCase'); // Camel casehumanize('snake_case_string'); // Snake case stringhumanize('kebab-case-string'); // Kebab case stringisAlpha
isAlpha(text: string): boolean
Checks if the string contains only alphabetic characters.
Determines whether the given string consists exclusively of alphabetic characters (a-z, A-Z). Returns false for empty strings, strings containing digits, whitespace, special characters, or any non-alphabetic characters. The check is performed using a regular expression that matches one or more alphabetic characters spanning the entire string.
Examples
isAlpha('Razomy'); // trueisAlpha('R4zomy'); // falseisAlpha(''); // falseisAlphanumeric
isAlphanumeric(text: string): boolean
Check if the string contains only alphanumeric characters. Tests whether the given string consists exclusively of alphanumeric characters (letters a-z, A-Z and digits 0-9) using a regular expression. Returns false for empty strings, strings containing spaces, special characters, or any non-alphanumeric content.
Examples
isAlphanumeric('Razomy1'); // trueisAlphanumeric('Razomy-String'); // falseisAlphanumeric(' '); // falseisLowerCase
isLowerCase(text: string): boolean
Checks if the string is lower case. Determines whether the entire input string is in lower case by comparing it to its lower-cased equivalent. Non-alphabetic characters (such as digits, spaces, and symbols) do not affect the result, as they have no case and remain unchanged by the lower case conversion.
Examples
isLowerCase('razomy'); // trueisLowerCase('Razomy'); // falseisLowerCase('string with 123'); // trueisUpperCase
isUpperCase(text: string): boolean
Check if a string is upper case.
Determines whether the given string is entirely in upper case by comparing it to its upper-cased transformation. Returns true only if every character in the string is already upper case (i.e., the string is identical to the result of calling toUpperCase() on it).
Examples
isUpperCase('HELLO'); // trueisUpperCase('Hello'); // falseisUpperCase('hello'); // falsekebabCase
kebabCase(text: string): string
Convert string to kebab case. Converts a given string to kebab-case by handling acronyms, camelCase, letter-number boundaries, and various delimiters (spaces, underscores, hyphens, dots). Leading and trailing separators are stripped, and the result is lowercased.
Examples
kebabCase('fooBar'); // foo-barkebabCase('Foo Bar'); // foo-barkebabCase('__FOO_BAR__'); // foo-barlowerCase
lowerCase(text: string): string
Converts a string to lower case.
Converts all characters in the given string to their lower case equivalents using the built-in toLowerCase method. The original string is not modified; a new lower cased string is returned.
Examples
lowerCase('RAZOMY'); // razomylowerCase('Test'); // testlowerCase('FOO Bar'); // foo barpascalCase
pascalCase(text: string): string
Convert string to pascal case. Converts a given string to PascalCase by splitting it into words (handling spaces, underscores, and camelCase/UPPERCASE boundaries), capitalizing the first letter of each word, lowercasing the rest, and joining them together without any separator.
Examples
pascalCase('foo bar'); // FooBarpascalCase('foo_bar'); // FooBarpascalCase('FOO BAR'); // FooBarpathCase
pathCase(text: string): string
Convert string to path/case. Converts a given string into path/case format by splitting it on camelCase boundaries, non-alphanumeric characters, and whitespace, then joining the resulting lowercase words with forward slashes.
Examples
pathCase('Hello World'); // hello/worldpathCase('camelCaseString'); // camel/case/stringpathCase('foo_bar'); // foo/barreverse
reverse(text: string): string
Reverses the given string. Reverses the order of characters in the given string by spreading it into an array of individual characters, reversing the array, and joining the characters back into a string. This approach correctly handles multi-byte Unicode characters (such as emojis) by using the spread operator, which splits on code points rather than code units.
Examples
reverse('abc'); // cbareverse('qwerty'); // ytrewqreverse('123'); // 321sentenceCase
sentenceCase(text: string): string
Convert string to Sentence case. Only the first letter of the result is capitalized, the rest is lowercase.
Examples
sentenceCase('helloWorld'); // Hello worldsentenceCase('HELLO WORLD'); // Hello worldsentenceCase('foo_bar_baz'); // Foo bar bazslugify
slugify(text: string): string
Convert string to url friendly slug. Converts a given string into a URL-friendly slug by normalizing unicode characters (removing diacritics/accents), converting to lowercase, replacing non-alphanumeric characters with hyphens, and trimming leading/trailing hyphens.
Examples
slugify('Hello World'); // hello-worldslugify('Foo & Bar'); // foo-barslugify('Crème Brûlée'); // creme-bruleesnakeCase
snakeCase(text: string): string
Convert string to snake case. Converts a given string to snake_case format by handling acronyms, camelCase, letter-to-number and number-to-letter boundaries, and replacing common delimiters (spaces, hyphens, dots) with underscores. The result is trimmed of leading/trailing underscores and converted to lowercase.
Examples
snakeCase('fooBar'); // foo_barsnakeCase('Foo Bar'); // foo_barsnakeCase('FOO-BAR'); // foo_barswapCase
swapCase(text: string): string
Convert string by swapping the case of every character. Uppercase becomes lowercase, and lowercase becomes uppercase.
Examples
swapCase('Hello World'); // hELLO wORLDswapCase('camelCase'); // CAMELcASEswapCase('123 ABC xyz'); // 123 abc XYZtitleCase
titleCase(text: string): string
Convert string to title case.
Converts the input string to title case by first lowercasing the entire string,
then capitalizing the first letter of each word. Word boundaries are determined by the \b
regex anchor, so hyphenated words and other non-alphabetic separators only trigger
capitalization at the start of each word boundary segment.
Examples
titleCase('foo bar'); // Foo BartitleCase('HELLO WORLD'); // Hello WorldtitleCase('one-two'); // One-twoupperCase
upperCase(text: string): string
Convert string to upper case.
Converts all characters in the given string to their upper-case equivalents using the built-in String.prototype.toUpperCase method. The original string is not modified; a new upper-cased string is returned.
Examples
upperCase('test'); // TESTupperCase('Hello World'); // HELLO WORLDupperCase('razomy'); // RAZOMY🕊️ Vision
"Razomy" means Together—you and me.
We act as catalysts, turning natural chaos into clarity through open collaboration.
By building honest, reliable systems, we empower humanity and create a foundation for peace.
We foster a borderless environment driven by quality code and mutual support.
Join us to build this future—one commit at a time.
💖 Fuel Our Shared Future
We can't build this without you. If this library has saved you time or helped turn chaos into clarity in your own projects, please consider backing the developers behind it. Building reliable, open-source tools takes immense time and energy. Your sponsorship isn't just a donation; it’s the fuel that keeps this project actively maintained, bug-free, and thriving for everyone who relies on it.
Help us keep the momentum going. Choose how you want to light the way:
🤝 Contributing
Contributions, issues and feature requests are welcome! Feel free to check issues page.
📝 License
Copyright © 2026 Razomy. This project is MIT licensed.
🐛 Reporting Issues
We use GitHub Issues as the official bug tracker for this project.
Before opening a new issue, please check if your problem has already been reported. If it hasn't, please open a new issue here: GitHub Issues: razomy/js
When reporting a bug, please include:
- A brief description of the issue.
- Steps to reproduce the bug.
- Your current environment (Node version, OS, etc.).
