@a95z/slugify v0.9.1
@a95z/slugify - Documentation
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.
Features
- 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.
Installation
You can install @a95z/slugify via npm, yarn, or pnpm.
Using npm:
npm install @a95z/slugifyUsing yarn:
yarn add @a95z/slugifyUsing pnpm:
pnpm add @a95z/slugifyUsage
Once installed, you can import the slugify function into your project.
Example
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"Development
To contribute to this package or make changes locally, you'll need to clone the repository and install the dependencies.
Clone the repository:
git clone https://github.com/a95z/slugify.git
cd slugifyInstall dependencies:
Using pnpm (recommended):
pnpm installRun the tests:
We use Vitest for testing. To run the tests, use the following command:
pnpm installFormat the code:
To ensure your code is properly formatted, use the prettier command:
pnpm format:fixLint the code:
You can run TypeScript type-checking with:
pnpm lintContributing
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.
Steps:
- 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.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
For a list of changes, please refer to the CHANGELOG.
This package is created and maintained by Abdurezak Farah (abdurezak.com, Twitter (X)).
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago