A utility function to convert a string into a URL-friendly slug with support for string sanitization, normalization, and transformation. This package is designed to create slugs from text for usage in URLs, making it easy to ensure your slugs are clean, readable, and SEO-friendly.
- Supports ASCII characters only: Automatically normalizes characters and removes any unwanted symbols.
- URL-friendly: Converts spaces to dashes, removes special characters, and ensures the string is lowercase.
- Optimized for TypeScript: Fully typed with TypeScript support to integrate seamlessly into your codebase.
- Works with ESM and CommonJS: Flexible exports for both modern and legacy systems.
You can install @a95z/slugify
via npm, yarn, or pnpm.
npm install @a95z/slugify
yarn add @a95z/slugify
pnpm add @a95z/slugify
Once installed, you can import the slugify
function into your project.
import { slugify } from '@a95z/slugify';
const text = 'Hello World! This is a test.';
const slug = slugify(text);
console.log(slug); // Output: "hello-world-this-is-a-test"
To contribute to this package or make changes locally, you'll need to clone the repository and install the dependencies.
git clone https://github.com/a95z/slugify.git
cd slugify
Using pnpm (recommended):
pnpm install
We use Vitest for testing. To run the tests, use the following command:
pnpm install
To ensure your code is properly formatted, use the prettier command:
pnpm format:fix
You can run TypeScript type-checking with:
pnpm lint
We welcome contributions! Please fork the repository and submit a pull request. Before submitting, ensure you run the tests and format the code according to the project standards.
- Fork the repository.
- Clone your fork locally.
- Create a feature branch:
git checkout -b feature-branch-name
. - Make your changes.
- Run tests to make sure everything works.
- Commit your changes with clear, concise messages.
- Push to your fork and submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
For a list of changes, please refer to the CHANGELOG.
This package is created and maintained by Abdurezak Farah (abdurezak.com, Twitter (X)).