A lightweight, zero-dependency TypeScript utility for string case conversion, inspection, and manipulation. Convert strings between 18+ formats, detect case styles with validation guards, and use robust utilities for everyday string tasks. Works in both JavaScript and TypeScript projects.
- ✅ Zero dependencies — Extremely lightweight.
- ✅ Full TypeScript Support — Built-in type declarations included.
- ✅ Hybrid Package — Works seamlessly with ESM (
import) and CommonJS (require). - ✅ Robust Case Handling — Handles edge cases like multiple spaces, special characters, and mixed-case inputs.
- ✅ Case Detection — Identify case styles programmatically.
- ✅ Advanced Utilities — Built-in support for HTML stripping, palindromes, truncation, and more.
npm install string-convimport {
// Case transforms
toUpperCase,
toLowerCase,
toTitleCase,
toSentenceCase,
toCamelCase,
toPascalCase,
toSnakeCase,
toKebabCase,
toConstantCase,
toDotCase,
toSlug,
fromSlug,
toInverseCase,
toReverseCase,
toTrainCase,
toPathCase,
toFlatCase,
toHeaderCase,
toSpongeCase,
// Inspection
detectCase,
isCamelCase,
isPascalCase,
isSnakeCase,
isKebabCase,
isConstantCase,
isDotCase,
isTrainCase,
isPathCase,
// Utilities
truncate,
wordCount,
charCount,
countOccurrences,
reverseWords,
trimWords,
padStart,
padEnd,
stripHtml,
isPalindrome,
escapeHtml,
} from "string-conv";const {
toUpperCase,
toLowerCase,
toTitleCase,
toSentenceCase,
toCamelCase,
toPascalCase,
toSnakeCase,
toKebabCase,
toConstantCase,
toDotCase,
toSlug,
fromSlug,
toInverseCase,
toReverseCase,
toTrainCase,
toPathCase,
toFlatCase,
toHeaderCase,
toSpongeCase,
detectCase,
isCamelCase,
isPascalCase,
isSnakeCase,
isKebabCase,
isConstantCase,
isDotCase,
isTrainCase,
isPathCase,
truncate,
wordCount,
charCount,
countOccurrences,
reverseWords,
trimWords,
padStart,
padEnd,
stripHtml,
isPalindrome,
escapeHtml,
} = require("string-conv");Converts a string to UPPERCASE.
toUpperCase("hello world"); // => "HELLO WORLD"Converts a string to lowercase.
toLowerCase("HELLO WORLD"); // => "hello world"Converts to Title Case (first letter of each word capitalized).
toTitleCase("hello world"); // => "Hello World"Capitalizes only the first character.
toSentenceCase("hello world"); // => "Hello world"toCamelCase("hello world"); // => "helloWorld"toPascalCase("hello world"); // => "HelloWorld"toSnakeCase("hello world"); // => "hello_world"toKebabCase("hello world"); // => "hello-world"toConstantCase("hello world"); // => "HELLO_WORLD"toDotCase("hello world"); // => "hello.world"Inverts character casing.
toInverseCase("Hello World"); // => "hELLO wORLD"Reverses characters.
toReverseCase("hello"); // => "olleh"toTrainCase("hello world"); // => "Hello-World"toPathCase("hello world"); // => "hello/world"toFlatCase("Hello World"); // => "helloworld"toHeaderCase("content type"); // => "Content-Type"toSpongeCase("hello"); // => "hElLo" (random)Detects the case style of a string.
detectCase("helloWorld"); // => "camelCase"Possible values: "camelCase", "PascalCase", "snake_case", "kebab-case", "CONSTANT_CASE", "dot.case", "path/case", "Train-Case", "Title Case", "UPPERCASE", "lowercase", "unknown".
Boolean checks for specific styles: isCamelCase, isPascalCase, isSnakeCase, isKebabCase, isConstantCase, isDotCase, isTrainCase, isPathCase.
Removes HTML tags.
stripHtml("<p>Hello <b>World</b></p>"); // => "Hello World"isPalindrome("racecar"); // => trueescapeHtml("<b>Hi</b>"); // => "<b>Hi</b>"truncate("Hello, World!", 8); // => "Hello..."wordCount("hello world"); // => 2reverseWords("hello world"); // => "world hello"Collapses internal whitespace.
trimWords(" hello world "); // => "hello world"| Function | Input | Output |
|---|---|---|
toUpperCase |
"hello world" |
"HELLO WORLD" |
toLowerCase |
"HELLO WORLD" |
"hello world" |
toTitleCase |
"hello world" |
"Hello World" |
toSentenceCase |
"hello world" |
"Hello world" |
toCamelCase |
"hello world" |
"helloWorld" |
toPascalCase |
"hello world" |
"HelloWorld" |
toSnakeCase |
"hello world" |
"hello_world" |
toKebabCase |
"hello world" |
"hello-world" |
toConstantCase |
"hello world" |
"HELLO_WORLD" |
toDotCase |
"hello world" |
"hello.world" |
toInverseCase |
"Hello World" |
"hELLO wORLD" |
toTrainCase |
"hello world" |
"Hello-World" |
toPathCase |
"hello world" |
"hello/world" |
toFlatCase |
"Hello World" |
"helloworld" |
MIT © Chetan Nada