@reaatech/core
Pure string-manipulation helpers: kebab-case, camelCase, truncate-with-ellipsis, slugify. Zero deps.
Installation
pnpm add @reaatech/core
API
toKebabCase
function toKebabCase(input: string): stringConverts camelCase, PascalCase, snake_case, and space-separated strings to kebab-case.
Throws TypeError if input is not a string. Returns '' for empty string input.
| Input | Output |
|---|---|
helloWorld | hello-world |
Hello World | hello-world |
snake_case | snake-case |
already-kebab | already-kebab |
HTMLElement | html-element |
ABC | a-b-c |
toCamelCase
function toCamelCase(input: string): stringConverts kebab-case, snake_case, and space-separated strings to camelCase.
Throws TypeError if input is not a string. Returns '' for empty string input. Leading delimiters are stripped before processing.
| Input | Output |
|---|---|
hello-world | helloWorld |
snake_case | snakeCase |
Hello World | helloWorld |
-leading-hyphen | leadingHyphen |
truncate
function truncate(input: string, maxLength: number, suffix = '…'): stringTruncates input to maxLength characters. Appends suffix (default …) when truncation occurs. If input fits within maxLength, returns it unchanged.
Throws TypeError if input is not a string or if maxLength is not an integer. Throws RangeError if maxLength is negative.
If maxLength is less than suffix.length, returns suffix.slice(0, maxLength) — the suffix itself is truncated to fit the limit.
| Input | Output |
|---|---|
hello world, 5 | hello… |
abcde, 3, ... | abc... |
hello, 5 | hello (no truncation) |
hello, 0, "" | "" |
hello, 2, ..... | .. |
slugify
function slugify(input: string): stringConverts input to a URL-safe slug: lowercase, alphanumeric + hyphens only. Diacritics are stripped via NFD normalization. Whitespace and hyphens are collapsed to single hyphens; leading/trailing hyphens are trimmed.
Throws TypeError if input is not a string. Returns '' for empty string input.
Emoji and other non-alphanumeric characters (except hyphen and space) are stripped entirely.
| Input | Output |
|---|---|
Hello World! | hello-world |
Hello World | hello-world |
café & restaurant | cafe-restaurant |
!@#$%^ | "" |
---hello--- | hello |
hello 😀 world | hello-world |
Usage example
import { toKebabCase, toCamelCase, truncate, slugify } from '@reaatech/core';
toKebabCase('helloWorld'); // 'hello-world'
toCamelCase('hello-world'); // 'helloWorld'
truncate('hello world', 5); // 'hello…'
slugify('Hello World!'); // 'hello-world'