Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

slugify

Package Overview
Dependencies
Maintainers
2
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slugify

Slugifies a String

  • 1.6.5
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created

What is slugify?

The slugify npm package is designed to convert strings into URL-friendly slugs. This is particularly useful for creating readable and SEO-friendly URLs from titles, names, or any text that may contain special characters, spaces, or uppercase letters. Slugify simplifies the process of generating slugs by replacing spaces and special characters with hyphens or other user-defined characters, making strings safe for URLs.

What are slugify's main functionalities?

Basic slugification

This feature demonstrates the basic usage of slugify to convert a string into a lowercase slug, replacing spaces and special characters with hyphens.

"use strict"; const slugify = require('slugify'); const title = 'Some Article Title!'; const slug = slugify(title); console.log(slug); // Output: 'some-article-title'

Custom replacement character

This feature shows how to use a custom replacement character (in this case, an underscore) instead of the default hyphen.

"use strict"; const slugify = require('slugify'); const title = 'Some Article Title!'; const slug = slugify(title, '_'); console.log(slug); // Output: 'some_article_title'

Locale-specific slugification

This feature illustrates the ability to handle locale-specific characters appropriately, converting them based on the specified locale.

"use strict"; const slugify = require('slugify'); const title = 'I ♥ Dogs'; const slug = slugify(title, { locale: 'de' }); console.log(slug); // Output: 'i-liebe-dogs'

Removing characters not allowed in URLs

This feature demonstrates the removal of specific characters not allowed or desired in the final slug, using a regular expression.

"use strict"; const slugify = require('slugify'); const title = 'New! Improved! Slugify!'; const slug = slugify(title, { remove: /[!]/g }); console.log(slug); // Output: 'new-improved-slugify'

Other packages similar to slugify

Keywords

FAQs

Package last updated on 03 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc