Skip to content

String Utils

Terminal window
pnpm add @theholocron/string-utils

All casing functions take a string and return a string:

import {
toCamelCase,
toConstantCase,
toDotCase,
toKebabCase,
toLowerCase,
toPascalCase,
toPathCase,
toSentenceCase,
toSnakeCase,
toTitleCase,
toUpperCase,
} from "@theholocron/string-utils";
toCamelCase("hello world"); // "helloWorld"
toKebabCase("Hello World"); // "hello-world"
toSnakeCase("Hello World"); // "hello_world"
toPascalCase("hello world"); // "HelloWorld"
toConstantCase("hello world"); // "HELLO_WORLD"
toTitleCase("hello world"); // "Hello World"
toSentenceCase("hello world"); // "Hello world"
toDotCase("hello world"); // "hello.world"
toPathCase("hello world"); // "hello/world"
toLowerCase("Hello"); // "hello"
toUpperCase("hello"); // "HELLO"
import { toArray, toBoolean } from "@theholocron/string-utils";
toArray("foo"); // ["foo"]
toArray(["foo", "bar"]); // ["foo", "bar"]
toBoolean("true"); // true
toBoolean("false"); // false
toBoolean(undefined); // false
import { toPlural } from "@theholocron/string-utils";
toPlural(1, "item"); // "item"
toPlural(2, "item"); // "items"
toPlural(2, "box"); // "boxes"
toPlural(2, "city"); // "cities"
toPlural(2, "person", "people"); // "people"

The full API reference is generated from the package’s TSDoc comments.