@prexjs/toidentifier
v1.0.0
Published
Convert phrases and strings containing spaces or punctuation into PascalCase JavaScript identifiers.
Readme
@prexjs/toIdentifier
Convert phrases and strings containing spaces or punctuation into PascalCase JavaScript identifiers.
@prexjs/toIdentifier converts human-readable strings, error codes, and phrases (e.g. 'bad request', 'Not Found') into valid PascalCase JavaScript identifiers (e.g. 'BadRequest', 'NotFound').
Features
- Capitalizes words and strips non-alphanumeric/underscore characters.
- Fast string transformation with minimal allocations.
- Dual ES Module (
.mjs) and CommonJS (.cjs) support with TypeScript definitions. - Zero runtime dependencies.
Installation
Install using your preferred package manager:
# npm
npm install @prexjs/toIdentifier
# pnpm
pnpm add @prexjs/toIdentifier
# Yarn
yarn add @prexjs/toIdentifier
# Bun
bun add @prexjs/toIdentifierQuick start
import toIdentifier from '@prexjs/toIdentifier';
console.log(toIdentifier('bad request')); // 'BadRequest'
console.log(toIdentifier('not found')); // 'NotFound'
console.log(toIdentifier('I\'m a teapot')); // 'ImATeapot'Both default and named exports are supported:
import toIdentifier, { toIdentifier as namedToIdentifier } from '@prexjs/toIdentifier';Compatibility
@prexjs/toIdentifier runs anywhere ECMAScript executes (Node.js, Deno, Bun, browser).
License
This project is licensed under the MIT License. See LICENSE for the full license text.
Related projects
- prex.js — prex.js monorepo and ecosystem.
