@architecturex/utils.slug
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

@architecturex/utils.slug

slug(str: string): string

The slug function is a simple utility designed to convert strings into URL-friendly slugs. This is especially useful when creating web pages with human-readable URLs, based on titles or names that can contain special characters, spaces, or uppercase letters.

Installation

npm install @architecturex/utils.slug

Usage

To use the slug function, import it into your project:

import slug from '@architecturex/utils.slug'

Then, call the function with a string argument:

const mySlug = slug('Your String Here')

Examples

Basic String:

slug('Hello World') // "hello-world"

String with special characters:

slug('Hello, World!') // "hello-world"

String with non-ASCII characters:

slug('Café con Leche') // "cafe-con-leche"

Function Behavior

  • The function converts the string to lowercase.
  • It removes diacritics (accents) from characters.
  • Non-alphanumeric characters (excluding hyphens) are replaced with spaces.
  • Continuous spaces or hyphens are replaced with a single hyphen.
  • The resulting string is trimmed of any leading or trailing spaces or hyphens.

Contribution

Feel free to suggest improvements, report issues, or contribute to enhancing the utility. Your feedback and contributions are welcome!

Readme

Keywords

Package Sidebar

Install

npm i @architecturex/utils.slug

Weekly Downloads

11

Version

1.0.4

License

MIT

Unpacked Size

3.79 kB

Total Files

5

Last publish

Collaborators

  • architecturex