Skip to content

🔤 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 ​

MethodDescription
camelCaseConvert a string to camelCase.
kebabCaseConvert a string to kebab-case.
pascalCaseConvert a string to PascalCase.
snakeCaseConvert a string to snake_case.
truncateTruncate a string to a given length with an optional suffix.
similarityCompute 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

🔗 All String Utilities ​