UNPKG

@puq/names

Version:

The library provides a useful function to create all casing variants of a given string value such as title-case, pascal-case, snake-case and so more.

37 lines (36 loc) 954 B
import { lowerCaseFirst, normalizeName, upperCaseFirst } from './normalize-name.js'; function toPascal(name) { return name.split(' ').map(upperCaseFirst).join(''); } function toCamel(name) { return lowerCaseFirst(toPascal(name)); } function toKebab(name) { return name.replace(/\s{1,}/g, '-'); } function toSnake(name) { return name.replace(/\s{1,}/g, '_'); } function toTitle(name) { return name.split(' ').map(upperCaseFirst).join(' '); } export function names(name) { name = normalizeName(name); const camel = toCamel(name); const pascal = toPascal(name); const kebab = toKebab(name); const snake = toSnake(name); const screamingSnake = snake.toUpperCase(); const sentence = upperCaseFirst(name); const title = toTitle(name); return { camel, kebab, pascal, screamingSnake, sentence, snake, title }; } //# sourceMappingURL=names.js.map