capstring is a lightweight JavaScript library for text capitalization and transformation.
Zero dependencies, many styles, Unicode and emoji safe, ships a CLI and TypeScript types.
import capstring, { capstringAll } from 'capstring';
capstring('hello world', 'title'); // 'Hello World'
capstring('XMLHttpRequest', 'kebab'); // 'xml-http-request'
capstring('hello world', 'slug'); // 'hello-world'
capstringAll('hi').upper; // 'HI'npx capstring kebab "Hello World" # hello-world
echo hi | npx capstring --all # every stylecapstring(str, style = 'same', { strict = false } = {})str- String to transformstyle- Style name (default: 'same')strict- ThrowTypeError/RangeErrorinstead of returningfalse/ the input- Returns: Transformed string;
''for empty input;falseifstris not a string
import { capstringAll, getStyles, isValidStyle, STYLES, CATEGORIES } from 'capstring';
capstringAll('hi'); // { same: 'hi', none: '', ... } in STYLES order
getStyles(); // fresh copy of STYLES
isValidStyle('kebab'); // true
STYLES; // frozen array of all style names
CATEGORIES; // frozen { case, code, fun, encoding, art }| Category | Styles |
|---|---|
| case | same, none, proper, title, sentence, upper, lower, swap, capitalize, lowerfirst |
| code | camel, pascal, snake, kebab, slug, constant, python, dot, path, train, hashtag, acronym, ada, cobol, initials |
| fun | reverse, sponge, mock, alternate, crazy, random, clap, piglatin, spaced, squish, nato |
| encoding | leet, rot13, morse, binary, hex, base64 |
| art | flip, smallcaps, bubble, wide, strike, bold, italic, script |
index.js- the whole library. Must stay browser-safe: nonode:imports, noprocess.cli.js- CLI logic asmain(argv, io);bin/capstring.jsis the executable shim.index.d.ts- hand-written types.test/types.test.jsfails if theStyleunion drifts fromSTYLES.
web/- playground,web/docs/Developer Docs (Swagger API Reference is served at/apiby the function); imports./capstring.js(copied fromindex.jsat Netlify build time)netlify/functions/api.js- HTTP API athttps://capstring.netlify.app/api(transform, all, batch, spell, count, lorem, badge, styles; json/txt/html/xml/yaml/csv/jsonp)npm run devruns both locally on http://localhost:8888
npm test # Run tests
npm run lint # Run linter
npm run test:coverage # Coverage report (100% thresholds enforced)