Package Exports
- komoji
- komoji/esm/index.js
- komoji/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (komoji) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
komoji ✨
the tiny case transformer
Effortlessly transform strings between naming conventions
Why komoji?
Named after the Japanese word 小文字 (komoji, "lowercase letters"), komoji is your friendly companion for working with naming conventions. It's tiny, focused, and does one thing exceptionally well: transforming strings between different cases with zero dependencies.
Perfect for:
- 🔄 Converting API responses to JavaScript conventions
- 🎨 Generating code from schemas and templates
- 🛠️ Building developer tools and CLI utilities
- 📦 Processing configuration files across formats
Install
npm install komojiUsage
Transform to PascalCase
import { toPascalCase } from 'komoji';
toPascalCase('hello-world'); // HelloWorld
toPascalCase('user_name'); // UserName
toPascalCase('api response'); // ApiResponse
toPascalCase('my-component_v2'); // MyComponentV2Transform to camelCase
import { toCamelCase } from 'komoji';
toCamelCase('hello-world'); // helloWorld
toCamelCase('user_name'); // userName
toCamelCase('api-response-data'); // apiResponseData
// Strip leading non-alphabetic characters
toCamelCase('__private_field', true); // privateField
toCamelCase('123-invalid', true); // invalidTransform to snake_case
import { toSnakeCase } from 'komoji';
toSnakeCase('helloWorld'); // hello_world
toSnakeCase('UserName'); // user_name
toSnakeCase('api-response-data'); // api_response_data
toSnakeCase('myComponentV2'); // my_component_v2
toSnakeCase('HTTPSConnection'); // https_connectionTransform to kebab-case
import { toKebabCase } from 'komoji';
toKebabCase('helloWorld'); // hello-world
toKebabCase('UserName'); // user-name
toKebabCase('api_response_data'); // api-response-data
toKebabCase('myComponentV2'); // my-component-v2
toKebabCase('HTTPSConnection'); // https-connectionTransform to CONSTANT_CASE
import { toConstantCase } from 'komoji';
toConstantCase('helloWorld'); // HELLO_WORLD
toConstantCase('UserName'); // USER_NAME
toConstantCase('api-response-data'); // API_RESPONSE_DATA
toConstantCase('myComponentV2'); // MY_COMPONENT_V2
toConstantCase('HTTPSConnection'); // HTTPS_CONNECTIONValidate Identifiers
import { isValidIdentifier, isValidIdentifierCamelized } from 'komoji';
// Check if string is a valid JavaScript identifier
isValidIdentifier('myVar'); // true
isValidIdentifier('my-var'); // false
isValidIdentifier('123abc'); // false
isValidIdentifier('_private'); // true
// Check if string can be camelized into valid identifier
isValidIdentifierCamelized('my-var'); // true (can become myVar)
isValidIdentifierCamelized('valid_id'); // true
isValidIdentifierCamelized('-invalid'); // false (starts with hyphen)API
Case Transformation Functions
toPascalCase(str: string): string
Converts a string to PascalCase by capitalizing the first letter of each word and removing separators.
Supported separators: hyphens (-), underscores (_), spaces ( )
toCamelCase(key: string, stripLeadingNonAlphabetChars?: boolean): string
Converts a string to camelCase with an optional flag to strip leading non-alphabetic characters.
Parameters:
key- The string to transformstripLeadingNonAlphabetChars- Remove leading non-alphabetic characters (default:false)
toSnakeCase(str: string): string
Converts a string to snake_case. Handles camelCase, PascalCase, kebab-case, and space-separated strings. Properly inserts underscores between words and before numbers.
toKebabCase(str: string): string
Converts a string to kebab-case. Handles camelCase, PascalCase, snake_case, and space-separated strings. Properly inserts hyphens between words and before numbers.
toConstantCase(str: string): string
Converts a string to CONSTANT_CASE (also known as SCREAMING_SNAKE_CASE). Perfect for environment variables and constants. Handles all common case formats and properly separates words and numbers.
Validation Functions
isValidIdentifier(key: string): boolean
Checks if a string is a valid JavaScript identifier (follows standard naming rules).
isValidIdentifierCamelized(key: string): boolean
Checks if a string can be transformed into a valid JavaScript identifier (allows internal hyphens that will be removed during camelization).
Design Philosophy
komoji embraces simplicity:
- 🎯 Zero dependencies
- 🪶 Tiny footprint
- 🚀 Fast and predictable
- 💎 Pure functions
- 📖 Clear, focused API
Development
Setup
- Clone the repository:
git clone https://github.com/constructive-io/dev-utils.git- Install dependencies:
cd dev-utils
pnpm install
pnpm build- Test the package of interest:
cd packages/<packagename>
pnpm test:watchCredits
🛠 Built by the Constructive team — creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on GitHub.
Disclaimer
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.