Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@sindresorhus/slugify
Advanced tools
@sindresorhus/slugify is a simple and efficient npm package used to convert strings into URL-friendly slugs. It handles various edge cases, such as special characters, spaces, and diacritics, making it a reliable choice for generating slugs from user input or other text data.
Basic Slugification
This feature converts a basic string into a URL-friendly slug by replacing spaces with hyphens and converting the text to lowercase.
const slugify = require('@sindresorhus/slugify');
const slug = slugify('Hello World!');
console.log(slug); // 'hello-world'
Custom Replacement Characters
This feature allows you to customize the separator character used in the slug, such as using an underscore instead of a hyphen.
const slugify = require('@sindresorhus/slugify');
const slug = slugify('Hello World!', { separator: '_' });
console.log(slug); // 'hello_world'
Handling Diacritics
This feature removes diacritics from characters, ensuring that the resulting slug is composed of standard ASCII characters.
const slugify = require('@sindresorhus/slugify');
const slug = slugify('Crème brûlée');
console.log(slug); // 'creme-brulee'
Custom Replacement Map
This feature allows you to define custom replacements for specific characters or strings, providing greater control over the slugification process.
const slugify = require('@sindresorhus/slugify');
const slug = slugify('foo@bar', { customReplacements: [['@', 'at']] });
console.log(slug); // 'foo-at-bar'
The 'slug' package is another popular choice for generating URL-friendly slugs. It offers similar functionality to @sindresorhus/slugify, including handling special characters and diacritics. However, it provides more configuration options and supports transliteration for non-Latin characters.
The 'speakingurl' package is designed to create human-readable slugs from strings. It supports a wide range of languages and character sets, making it a versatile choice for internationalization. Compared to @sindresorhus/slugify, it offers more extensive language support and customization options.
The 'limax' package is a slug generator that focuses on transliteration and supports multiple languages. It is similar to @sindresorhus/slugify in terms of basic functionality but provides additional features for handling non-Latin scripts and complex transliterations.
Slugify a string
Useful for URLs, filenames, and IDs.
$ npm install @sindresorhus/slugify
const slugify = require('@sindresorhus/slugify');
slugify('I ♥ Dogs');
//=> 'i-love-dogs'
slugify(' Déjà Vu! ');
//=> 'deja-vu'
slugify('fooBar 123 $#%');
//=> 'foo-bar-123'
MIT © Sindre Sorhus
FAQs
Slugify a string
The npm package @sindresorhus/slugify receives a total of 992,216 weekly downloads. As such, @sindresorhus/slugify popularity was classified as popular.
We found that @sindresorhus/slugify demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.