JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4914
  • Score
    100M100P100Q127814F
  • License MIT

the tiny case transformer — effortlessly transform strings between naming conventions

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 komoji

Usage

Transform to PascalCase

import { toPascalCase } from 'komoji';

toPascalCase('hello-world');      // HelloWorld
toPascalCase('user_name');        // UserName
toPascalCase('api response');     // ApiResponse
toPascalCase('my-component_v2');  // MyComponentV2

Transform 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);      // invalid

Validate 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

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 transform
  • stripLeadingNonAlphabetChars - Remove leading non-alphabetic characters (default: false)

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

  1. Clone the repository:
git clone https://github.com/hyperweb-io/dev-utils.git
  1. Install dependencies:
cd dev-utils
pnpm install
pnpm build
  1. Test the package of interest:
cd packages/<packagename>
pnpm test:watch

Credits

Built for developers, with developers.
👉 https://launchql.com | https://hyperweb.io

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.