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
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-caseUsage
ES Modules (Recommended)
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 convertoptions(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:watchLinting
# Run linter
pnpm lint
# Auto-fix linting issues
pnpm lint --fixTesting
# Run tests
pnpm test
# Run tests in watch mode
pnpm test --watch
# Run tests with coverage
pnpm test --coverageBuilding
# Build the package
pnpm build
# Build and watch for changes
pnpm build --watchBundle 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
Related Packages
text-camel-case- Convert to camelCasetext-pascal-case- Convert to PascalCasetext-snake-case- Convert to snake_casetext-param-case- Alias for kebab-case
License
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Support
- 📧 Email: selikhov.dmitrey@gmail.com
- 🐛 Issues: GitHub Issues
- 💬 Discussions: GitHub Discussions