Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
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.
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'
The 'speakingurl' package is another utility for creating slugs from strings. It offers more customization options, such as transliteration, custom character maps, and support for multiple languages. Compared to 'slug', 'speakingurl' provides more flexibility and control over the slug generation process.
The 'slugify' package is a straightforward utility for converting strings into URL-friendly slugs. It is similar to 'slug' but focuses on simplicity and ease of use. 'slugify' is a good choice if you need a lightweight solution without many configuration options.
The 'url-slug' package provides a simple way to create URL-friendly slugs from strings. It offers basic functionality similar to 'slug', with options for custom separators and character replacement. 'url-slug' is a good alternative if you need a minimalistic approach to slug generation.
slugifies every string, even when it contains unicode!
Make strings url-safe.
npm install slug
var slug = require('slug')
var print = console.log.bind(console, '>')
print(slug('i ♥ unicode'))
// > i-love-unicode
print(slug('unicode ♥ is ☢')) // yes!
// > unicode-love-is-radioactive
print(slug('i ♥ unicode', '_')) // If you prefer something else then `-` as seperator
// > i_love_unicode
slug.charmap['♥'] = 'freaking love' // change default charmap or use option {charmap:{…}} as 2. argument
print(slug('I ♥ UNICODE'))
// > I-freaking-love-UNICODE
print(slug('☏-Number', {lower: true})) // If you prefer lower case
// > telephone-number
print(slug('i <3 unicode'))
// > i-love-unicode
// options is either object or replacement (sets options.replacement)
slug('string', [{options} || 'replacement']);
slug.defaults.mode ='pretty';
slug.defaults.modes['rfc3986'] = {
replacement: '-', // replace spaces with replacement
symbols: true, // replace unicode symbols or not
remove: null, // (optional) regex to remove characters
lower: true, // result in lower case
charmap: slug.charmap, // replace special characters
multicharmap: slug.multicharmap // replace multi-characters
};
slug.defaults.modes['pretty'] = {
replacement: '-',
symbols: true,
remove: /[.]/g,
lower: false,
charmap: slug.charmap,
multicharmap: slug.multicharmap
};
When using browserify you might want to remove the symbols table from your bundle by using --ignore
similar to this:
# generates a standalone slug browser bundle:
browserify slug.js --ignore unicode/category/So -s slug > slug-browser.js
FAQs
slugifies even utf-8 chars!
The npm package slug receives a total of 230,512 weekly downloads. As such, slug popularity was classified as popular.
We found that slug demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.