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

@sindresorhus/slugify

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sindresorhus/slugify - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

15

index.js

@@ -11,3 +11,3 @@ 'use strict';

const customReplacements = new Map([
const builtinReplacements = new Map([
['&', 'and'],

@@ -18,4 +18,4 @@ ['🦄', 'unicorn'],

const doCustomReplacements = string => {
for (const [key, value] of customReplacements) {
const doCustomReplacements = (string, replacements) => {
for (const [key, value] of replacements) {
string = string.replace(new RegExp(escapeStringRegexp(key), 'g'), ` ${value} `);

@@ -39,10 +39,15 @@ }

options = Object.assign({
separator: '-'
separator: '-',
customReplacements: []
}, options);
const separator = escapeStringRegexp(options.separator);
const customReplacements = new Map([
...builtinReplacements,
...options.customReplacements
]);
string = deburr(string);
string = decamelize(string);
string = doCustomReplacements(string);
string = doCustomReplacements(string, customReplacements);
string = string.toLowerCase();

@@ -49,0 +54,0 @@ string = string.replace(/[^a-z\d]+/g, separator);

{
"name": "@sindresorhus/slugify",
"version": "0.2.0",
"version": "0.3.0",
"description": "Slugify a string",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -31,2 +31,9 @@ # slugify [![Build Status](https://travis-ci.org/sindresorhus/slugify.svg?branch=master)](https://travis-ci.org/sindresorhus/slugify)

//=> 'bar_and_baz'
slugify('I ♥ 🦄 & 🐶', {
customReplacements: [
['🐶', 'dog']
]
});
//=> 'i-love-unicorn-and-dog'
```

@@ -51,4 +58,17 @@

##### customReplacements
Type: `Array`<br>
Default: `[
['&', 'and'],
['🦄', 'unicorn'],
['♥', 'love']
]`
Specifying this only replaces the default if you set an item with the same key, like `&`.
## Related
- [slugify-cli](https://github.com/sindresorhus/slugify-cli) - CLI for this module
- [filenamify](https://github.com/sindresorhus/filenamify) - Convert a string to a valid safe filename

@@ -55,0 +75,0 @@

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