slug-craft
v1.0.1
Published
A lightweight, easy-to-use npm package for generating URL-friendly slugs from strings. Perfect for blogs, e-commerce platforms, and any web application that requires readable URLs.
Downloads
3
Readme
Slug-Craft
A lightweight, easy-to-use npm package for generating URL-friendly slugs from strings. Perfect for blogs, e-commerce platforms, and any web application that requires readable URLs.
Features
- String Sanitization: Removes or replaces characters not allowed in URLs.
- Case Conversion: Supports transforming strings to lowercase, uppercase, or maintaining original case.
- Custom Separators: Allows specification of custom character separators.
- Slug Uniqueness: Option to ensure slugs are unique by appending identifiers.
- Slug Truncation: Supports setting maximum lengths for slugs.
- Slug Validation: Validates slugs against a set of predefined rules.
- Slug Normalization: Ensures consistency in slug format.
- Customizable Rules: Supports defining custom rules for slug generation.
Installation
Install via npm:
npm install slug-craft
or yarn
yarn add slug-craft
Usage
To use slug-craft
in your project, first import or require it at the top of your file:
const { generateSlug } = require('slug-craft');
const title = "How to Create a Slug Craft in JavaScript";
const options = {
caseStyle: 'lowercase', // Converts the slug to lowercase. This is the default behavior.
separator: '-', // Uses a hyphen as the separator between words in the slug.
maxLength: 50, // Limits the slug to 50 characters.
};
const slug = generateSlug(title, options);
console.log(slug); // Output: "how-to-create-a-slug-craft-in-javascript"
Contributing
Contributions are welcome! If you have an idea for improving slug-craft, please follow these steps:
- Fork the repo on GitHub.
- Clone your forked repo and run
npm install
. - Create a new branch for your feature or fix.
- Make your changes, ensuring the project's coding standards are followed.
- Write or update tests as necessary.
- Submit a pull request detailing your changes.
Please refer to CONTRIBUTING.md for more detailed information.
License
slug-craft is licensed under the MIT License - see the LICENSE file for details.