@vnodesign/slugify v1.0.1
@vnodesign/slugify
Description
@vnodesign/slugify is a lightweight and efficient utility for converting strings into clean, URL-friendly slugs. It is specially designed to handle Vietnamese diacritics and special characters, making it ideal for projects that require localization or SEO optimization.
Features
- Vietnamese Diacritics Removal: Converts characters like
ắ,ế,ở, andđinto their base form (e.g.,a,e,o,d). - Special Character Stripping: Removes all non-alphanumeric characters, leaving only letters, numbers, spaces, and hyphens.
- Space-to-Hyphen Conversion: Converts spaces into hyphens to create slugs suitable for URLs.
- Redundant Hyphen Handling: Removes consecutive or trailing hyphens for a clean result.
- Case Insensitive: Converts all input to lowercase for uniformity.
Installation
Install the package via npm or pnpm:
npm install @vnodesign/slugify
# or
pnpm add @vnodesign/slugifyUsage
Here’s how to use @vnodesign/slugify in your project:
Example
import { slugify } from '@vnodesign/slugify'
const title = 'Chào bạn! Đây là bài viết của tôi.'
const slug = slugify(title)
console.log(slug) // Output: "chao-ban-day-la-bai-viet-cua-toi"Input and Output Examples
| Input | Output |
|---|---|
Chào bạn! | chao-ban |
Ngày hôm nay trời rất đẹp. | ngay-hom-nay-troi-rat-dep |
Hello @World!!! | hello-world |
Test--Case | test-case |
API
slugify(str: string): string
Converts a given string into a URL-friendly slug.
Parameters
str(string): The input string to be converted.
Returns
- (string): The cleaned and formatted slug.
Testing
This package includes unit tests powered by Vitest.
Run tests with:
pnpm testDevelopment
Build
To build the package, run:
pnpm buildLint
Lint the code using:
pnpm lintType Checking
Ensure all types are valid:
pnpm typecheckContributing
Contributions are welcome! Please feel free to submit a pull request or open an issue on GitHub.
License
This project is licensed under the MIT License.
Funding
If you find this package helpful, consider sponsoring me on GitHub ❤️. Your support helps maintain and improve this project!