Skip to content
reaatechREAATECH

@reaatech/core

pending npm

Provides a collection of zero-dependency string manipulation functions for case conversion, truncation, and URL-safe slug generation. These utilities are exported as individual functions for use in any JavaScript or TypeScript environment.

@reaatech/core

Pure string-manipulation helpers: kebab-case, camelCase, truncate-with-ellipsis, slugify. Zero deps.

Installation

code
pnpm add @reaatech/core

API

toKebabCase

typescript
function toKebabCase(input: string): string

Converts camelCase, PascalCase, snake_case, and space-separated strings to kebab-case.

Throws TypeError if input is not a string. Returns '' for empty string input.

InputOutput
helloWorldhello-world
Hello Worldhello-world
snake_casesnake-case
already-kebabalready-kebab
HTMLElementhtml-element
ABCa-b-c

toCamelCase

typescript
function toCamelCase(input: string): string

Converts 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.

InputOutput
hello-worldhelloWorld
snake_casesnakeCase
Hello WorldhelloWorld
-leading-hyphenleadingHyphen

truncate

typescript
function truncate(input: string, maxLength: number, suffix = '…'): string

Truncates 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.

InputOutput
hello world, 5hello…
abcde, 3, ...abc...
hello, 5hello (no truncation)
hello, 0, """"
hello, 2, .......

slugify

typescript
function slugify(input: string): string

Converts 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.

InputOutput
Hello World!hello-world
Hello World hello-world
café & restaurantcafe-restaurant
!@#$%^""
---hello---hello
hello 😀 worldhello-world

Usage example

typescript
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'