Skip to main content
Home

Built and signed on GitHub Actions

Lightweight TypeScript utility to convert strings to kebab-case, supporting Unicode normalization and handling various input formats.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
a year ago (0.1.4)

Kebab Case Converter

A lightweight TypeScript utility for converting strings into kebab-case format. This package is ideal for generating URL-friendly slugs, CSS class names, and other scenarios where a consistent, human-readable string format is desired.

Features

  • Converts strings from various formats to kebab-case.
  • Supports Unicode normalization and removes diacritical marks from accented characters.
  • Handles spaces, underscores, and special characters effectively.
  • Minimal dependencies and easy integration into any TypeScript or JavaScript project.

Installation

Install the package via npm:

bunx jsr add @emilien/kebab-case

Usage

Import the kebabCase function and convert strings easily:

import { kebabCase } from "@emilien/kebab-case";

const slug = kebabCase("Hello World");
console.log(slug); // Outputs: 'hello-world'

const className = kebabCase("C'est un éléphant");
console.log(className); // Outputs: 'c-est-un-elephant'

const cssName = kebabCase("backgroundColor");
console.log(cssName); // Outputs: 'background-color'

Example

Convert various strings into kebab-case:

console.log(kebabCase("SimpleString")); // simple-string
console.log(kebabCase("PascalCaseExample")); // pascal-case-example
console.log(kebabCase("string_with_underscores")); // string-with-underscores
console.log(kebabCase("A String with spaces and !special* characters?")); // a-string-with-spaces-and-special-characters

API

kebabCase(input: string): string

  • Parameters:

    • input (string): The string to be converted to kebab-case.
  • Returns:

    • A new string formatted in kebab-case, with accents removed and special characters replaced by hyphens.

Contributing

Contributions are welcome! Please feel free to open an issue or submit a pull request if you have any improvements or bug fixes.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Examples

Example 1

import { kebabCase } from './StringCaseConverter';

const slug = kebabCase('Hello World'); // Returns: 'hello-world'
console.log(slug);

const className = kebabCase("éléphant"); // Returns: 'elephant'
console.log(className);
Built and signed on
GitHub Actions

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@emilien/kebab-case

Import symbol

import * as kebab_case from "@emilien/kebab-case";
or

Import directly with a jsr specifier

import * as kebab_case from "jsr:@emilien/kebab-case";

Add Package

pnpm i jsr:@emilien/kebab-case
or (using pnpm 10.8 or older)
pnpm dlx jsr add @emilien/kebab-case

Import symbol

import * as kebab_case from "@emilien/kebab-case";

Add Package

yarn add jsr:@emilien/kebab-case
or (using Yarn 4.8 or older)
yarn dlx jsr add @emilien/kebab-case

Import symbol

import * as kebab_case from "@emilien/kebab-case";

Add Package

vlt install jsr:@emilien/kebab-case

Import symbol

import * as kebab_case from "@emilien/kebab-case";

Add Package

npx jsr add @emilien/kebab-case

Import symbol

import * as kebab_case from "@emilien/kebab-case";

Add Package

bunx jsr add @emilien/kebab-case

Import symbol

import * as kebab_case from "@emilien/kebab-case";