JSPM

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

Convert into a text with the separator denoted by kebab-case (lowercase words separated by hyphens)

Package Exports

  • text-kebab-case
  • text-kebab-case/dist.es2015/index.js
  • text-kebab-case/dist/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 (text-kebab-case) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Kebab Case

NPM version NPM downloads Bundle size

Transform text into kebab-case format with lowercase words separated by hyphens.

Installation

Install the package using your preferred package manager:

# npm
npm install text-kebab-case

# yarn
yarn add text-kebab-case

# pnpm
pnpm add text-kebab-case

# bun
bun add text-kebab-case

Usage

import { kebabCase } from "text-kebab-case";

console.log(kebabCase("hello world")); // "hello-world"

CommonJS

const { kebabCase } = require("text-kebab-case");

console.log(kebabCase("hello world")); // "hello-world"

TypeScript

import { kebabCase, kebabCaseTransformMerge, Options } from "text-kebab-case";

const result: string = kebabCase("hello world");
console.log(result); // "hello-world"

Examples

Basic Usage

import { kebabCase } from "text-kebab-case";

// Simple transformations
kebabCase("hello world"); // "hello-world"
kebabCase("Hello World"); // "hello-world"
kebabCase("HELLO WORLD"); // "hello-world"

// From other cases
kebabCase("camelCase"); // "camel-case"
kebabCase("PascalCase"); // "pascal-case"
kebabCase("snake_case"); // "snake-case"
kebabCase("dot.case"); // "dot-case"

// Complex examples
kebabCase("XMLHttpRequest"); // "xml-http-request"
kebabCase("iPhone"); // "i-phone"
kebabCase("version 1.2.3"); // "version-1-2-3"

Advanced Options

import { kebabCase, kebabCaseTransformMerge } from "text-kebab-case";

// Custom transform to merge numbers without separator
kebabCase("version 1.2.3", {
  transform: kebabCaseTransformMerge,
}); // "version-123"

// With custom separator handling
kebabCase("hello_world.test", {
  stripRegexp: /[_.]/g,
}); // "hello-world-test"

Real-world Examples

import { kebabCase } from "text-kebab-case";

// CSS class names
kebabCase("primaryButton"); // "primary-button"
kebabCase("navigation_bar"); // "navigation-bar"
kebabCase("form-input"); // "form-input"

// HTML attributes
kebabCase("dataToggle"); // "data-toggle"
kebabCase("ariaLabel"); // "aria-label"
kebabCase("tabIndex"); // "tab-index"

// URL slugs
kebabCase("My Blog Post Title"); // "my-blog-post-title"
kebabCase("Product Category Name"); // "product-category-name"
kebabCase("Special Characters!"); // "special-characters"

// File names
kebabCase("userProfile.component"); // "user-profile-component"
kebabCase("api_service"); // "api-service"
kebabCase("configUtils"); // "config-utils"

API

kebabCase(input, options?)

Converts a string to kebab-case.

Parameters

  • input (string): The string to convert
  • options (Options, optional): Configuration options

Returns

  • string: The kebab-case formatted string

Options

interface Options {
  // Custom transform function for word processing
  transform?: (word: string, index: number, words: string[]) => string;

  // Regex to strip characters before processing
  stripRegexp?: RegExp;

  // Custom split function
  split?: (value: string) => string[];
}

kebabCaseTransformMerge

A transform function that merges numeric characters without separation.

import { kebabCase, kebabCaseTransformMerge } from "text-kebab-case";

kebabCase("version 1.2.3", { transform: kebabCaseTransformMerge }); // "version-123"

Development

Type Checking

# Check types
pnpm typecheck

# Check types in watch mode
pnpm typecheck:watch

Linting

# Run linter
pnpm lint

# Auto-fix linting issues
pnpm lint --fix

Testing

# Run tests
pnpm test

# Run tests in watch mode
pnpm test --watch

# Run tests with coverage
pnpm test --coverage

Building

# Build the package
pnpm build

# Build and watch for changes
pnpm build --watch

Bundle Size

This package is optimized for minimal bundle size:

  • Minified: ~350 B
  • Gzipped: ~180 B
  • Tree-shakeable: Yes
  • Side effects: None

TypeScript Support

This package includes comprehensive TypeScript definitions and supports:

  • Full type safety
  • IntelliSense autocompletion
  • Type inference
  • Generic type parameters

Browser Support

  • Modern browsers: ES2015+
  • Node.js: 12+
  • Bundle formats: UMD, ESM, CommonJS

License

MIT

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Support