🔤 String Utilities ​
String utilities provide essential tools to transform, compare, and format strings in a type-safe, ergonomic way. Use these helpers for case conversion, similarity checks, truncation, and more.
📚 Quick Reference ​
| Method | Description |
|---|---|
camelCase | Convert a string to camelCase. |
kebabCase | Convert a string to kebab-case. |
pascalCase | Convert a string to PascalCase. |
snakeCase | Convert a string to snake_case. |
truncate | Truncate a string to a given length with an optional suffix. |
similarity | Compute the similarity score (0 to 1) between two strings. |
💡 Practical Examples ​
Case Conversion ​
ts
import { camelCase, kebabCase, pascalCase, snakeCase } from '@vielzeug/toolkit';
const input = 'Hello World-from Vielzeug';
camelCase(input); // 'helloWorldFromVielzeug'
kebabCase(input); // 'hello-world-from-vielzeug'
pascalCase(input); // 'HelloWorldFromVielzeug'
snakeCase(input); // 'hello_world_from_vielzeug'Formatting & Comparison ​
ts
import { truncate, similarity } from '@vielzeug/toolkit';
// Truncate
const longText = 'Vielzeug is a Swiss-army knife for TypeScript developers.';
truncate(longText, 20); // 'Vielzeug is a Swi...'
// Similarity
similarity('apple', 'apply'); // 0.8
similarity('hello', 'world'); // 0.2