doslug
v0.0.3
Published
A lightweight utility for converting strings into URL-friendly slugs with CLI and API support
Maintainers
Readme
DoSlug
A lightweight utility for converting strings into URL-friendly slugs, with CLI and API support.
DoSlug is a simple Node.js tool that transforms strings into clean, URL-friendly slugs by removing accents, converting to lowercase, replacing spaces with hyphens, and more. It supports both programmatic usage via an API and a command-line interface for quick slug generation.
Features ✨
- 🔹 Simple API: Convert strings to slugs with a single function call.
- 🚀 CLI Ready: Generate slugs directly from the terminal with a single command.
- 🌐 Cross-Platform: Works in modern Node.js environments with TypeScript support.
- ⚡ Fast & Minimal: Lightweight with no external dependencies and robust error handling.
- 🔄 Robust Slugification: Handles accents, diacritics, special characters, and multiple spaces or hyphens.
Installation 💿
# Using npm
npm install doslug
# Using pnpm
pnpm add doslug
# Using yarn
yarn add doslugUsage 📦
API </>
The doslug module provides a single function, doslug, to convert strings into URL-friendly slugs. Below is the API with JSDoc documentation.
import { doSlug } from 'doslug';
// Convert a string to a slug
console.log(doSlug('Héllo Wörld!!!')); // 'hello-world'
// Handle special characters and spaces
console.log(doSlug(' Café & Croissants ')); // 'cafe-croissants'
// Empty string returns default slug
console.log(doSlug('')); // 'default-slug'
// Multiple hyphens and special characters
console.log(doSlug('Hello---World!!!')); // 'hello-world'API Details
doSlug(str: string): string- Input: A string to be converted into a slug.
- Output: A URL-friendly slug (lowercase, no accents, spaces replaced with hyphens, special characters removed).
- Throws: An error if the input is not a string.
- Default: Returns
'default-slug'if the result would be an empty string.
CLI 🖥️
#!/usr/bin/env node
doslug [string] [options]Example Commands
# Convert a string to a slug
doslug "Héllo Wörld!!!"
# Output: hello-world
# Handle empty string
doslug ""
# Output: default-slug
# Show version
doslug --version
# Output: doslug v1.0.0
# Show help
doslug --help
# Output: (see help message below)CLI Options
[string] Convert the provided string to a URL-friendly slug
--help Show this help message
--version Show versionCLI Help Output
Running doslug --help displays:
Usage: doslug [string] [options]
Commands:
[string] Convert the provided string to a URL-friendly slug
--help Show this help message
--version Show version
Examples:
doslug "Héllo Wörld!!!"
doslug --version
doslug --helpCLI Usage Example
Install doslug globally to use it from the command line:
npm install -g doslugThen run:
doslug "My Awesome Post!!!"
# Output: my-awesome-post
doslug "Café au Lait"
# Output: cafe-au-lait
doslug --version
# Output: doslug v1.0.0License 📄
MIT License – see LICENSE for details.
Author: Estarlin R (estarlincito.com)
