Text Utilities

Text

Case conversion, slugify, word/char counting, reverse, and more text utilities.

Import

Import
import { text } from 'toolmetry';

API Reference

FunctionParametersReturnsDescription
toCamelCaseinput: stringstringConvert to camelCase
toPascalCaseinput: stringstringConvert to PascalCase
toSnakeCaseinput: stringstringConvert to snake_case
toKebabCaseinput: stringstringConvert to kebab-case
toConstantCaseinput: stringstringConvert to CONSTANT_CASE
slugifyinput: stringstringGenerate a URL-safe slug
wordCountinput: stringnumberCount words in a string
charCountinput: string, includeSpaces?: booleannumberCount characters
reverseinput: stringstringReverse a string
truncateinput: string, maxLength: number, suffix?: stringstringTruncate with ellipsis
removeExtraWhitespaceinput: stringstringCollapse multiple spaces
removeLineBreaksinput: stringstringRemove all line breaks
escapeRegexinput: stringstringEscape for use in regex

Examples

Case Conversion
import { toCamelCase, toPascalCase, toSnakeCase, toKebabCase, toConstantCase } from 'toolmetry';

toCamelCase('hello world example');  // "helloWorldExample"
toPascalCase('hello world example'); // "HelloWorldExample"
toSnakeCase('helloWorldExample');    // "hello_world_example"
toKebabCase('helloWorldExample');    // "hello-world-example"
toConstantCase('hello world');       // "HELLO_WORLD"
Slugify
import { slugify } from 'toolmetry';

slugify('My Blog Post Title!');
// "my-blog-post-title"
Counting & Truncation
import { wordCount, charCount, truncate } from 'toolmetry';

wordCount('Hello world example'); // 3
charCount('Hello'); // 5
truncate('A very long string here', 10); // "A ver..."

Try It Live