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

slug

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slug

slugifies even utf-8 chars!

  • 0.9.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
240K
decreased by-8.4%
Maintainers
1
Weekly downloads
 
Created

What is slug?

The 'slug' npm package is a utility for creating URL-friendly slugs from strings. It converts strings into a format that can be safely used in URLs by removing or replacing special characters, spaces, and other non-URL-safe characters.

What are slug's main functionalities?

Basic Slug Creation

This feature allows you to create a basic slug from a string. It converts the string to lowercase and replaces spaces and special characters with hyphens.

const slug = require('slug');
const title = 'Hello World!';
const urlSlug = slug(title);
console.log(urlSlug); // Output: 'hello-world'

Custom Separator

This feature allows you to specify a custom separator instead of the default hyphen. In this example, underscores are used as separators.

const slug = require('slug');
const title = 'Hello World!';
const urlSlug = slug(title, { replacement: '_' });
console.log(urlSlug); // Output: 'hello_world'

Remove Special Characters

This feature automatically removes special characters from the string, making it URL-safe.

const slug = require('slug');
const title = 'Hello, World!';
const urlSlug = slug(title);
console.log(urlSlug); // Output: 'hello-world'

Multi-language Support

This feature supports multiple languages, converting non-Latin characters to their Latin equivalents.

const slug = require('slug');
const title = '你好,世界';
const urlSlug = slug(title);
console.log(urlSlug); // Output: 'ni-hao-shi-jie'

Other packages similar to slug

Keywords

FAQs

Package last updated on 21 Feb 2019

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