@sindresorhus/slugify
Advanced tools
Comparing version 1.1.2 to 2.0.0
296
index.d.ts
@@ -1,121 +0,166 @@ | ||
declare namespace slugify { | ||
interface Options { | ||
/** | ||
@default '-' | ||
export interface Options { | ||
/** | ||
@default '-' | ||
@example | ||
``` | ||
import slugify = require('@sindresorhus/slugify'); | ||
@example | ||
``` | ||
import slugify from '@sindresorhus/slugify'; | ||
slugify('BAR and baz'); | ||
//=> 'bar-and-baz' | ||
slugify('BAR and baz'); | ||
//=> 'bar-and-baz' | ||
slugify('BAR and baz', {separator: '_'}); | ||
//=> 'bar_and_baz' | ||
slugify('BAR and baz', {separator: '_'}); | ||
//=> 'bar_and_baz' | ||
slugify('BAR and baz', {separator: ''}); | ||
//=> 'barandbaz' | ||
``` | ||
*/ | ||
readonly separator?: string; | ||
slugify('BAR and baz', {separator: ''}); | ||
//=> 'barandbaz' | ||
``` | ||
*/ | ||
readonly separator?: string; | ||
/** | ||
Make the slug lowercase. | ||
/** | ||
Make the slug lowercase. | ||
@default true | ||
@default true | ||
@example | ||
``` | ||
import slugify = require('@sindresorhus/slugify'); | ||
@example | ||
``` | ||
import slugify from '@sindresorhus/slugify'; | ||
slugify('Déjà Vu!'); | ||
//=> 'deja-vu' | ||
slugify('Déjà Vu!'); | ||
//=> 'deja-vu' | ||
slugify('Déjà Vu!', {lowercase: false}); | ||
//=> 'Deja-Vu' | ||
``` | ||
*/ | ||
readonly lowercase?: boolean; | ||
slugify('Déjà Vu!', {lowercase: false}); | ||
//=> 'Deja-Vu' | ||
``` | ||
*/ | ||
readonly lowercase?: boolean; | ||
/** | ||
Convert camelcase to separate words. Internally it does `fooBar` → `foo bar`. | ||
/** | ||
Convert camelcase to separate words. Internally it does `fooBar` → `foo bar`. | ||
@default true | ||
@default true | ||
@example | ||
``` | ||
import slugify = require('@sindresorhus/slugify'); | ||
@example | ||
``` | ||
import slugify from '@sindresorhus/slugify'; | ||
slugify('fooBar'); | ||
//=> 'foo-bar' | ||
slugify('fooBar'); | ||
//=> 'foo-bar' | ||
slugify('fooBar', {decamelize: false}); | ||
//=> 'foobar' | ||
``` | ||
*/ | ||
readonly decamelize?: boolean; | ||
slugify('fooBar', {decamelize: false}); | ||
//=> 'foobar' | ||
``` | ||
*/ | ||
readonly decamelize?: boolean; | ||
/** | ||
Add your own custom replacements. | ||
/** | ||
Add your own custom replacements. | ||
The replacements are run on the original string before any other transformations. | ||
The replacements are run on the original string before any other transformations. | ||
This only overrides a default replacement if you set an item with the same key, like `&`. | ||
This only overrides a default replacement if you set an item with the same key, like `&`. | ||
Add a leading and trailing space to the replacement to have it separated by dashes. | ||
Add a leading and trailing space to the replacement to have it separated by dashes. | ||
@default [ ['&', ' and '], ['🦄', ' unicorn '], ['♥', ' love '] ] | ||
@default [ ['&', ' and '], ['🦄', ' unicorn '], ['♥', ' love '] ] | ||
@example | ||
``` | ||
import slugify = require('@sindresorhus/slugify'); | ||
@example | ||
``` | ||
import slugify from '@sindresorhus/slugify'; | ||
slugify('Foo@unicorn', { | ||
customReplacements: [ | ||
['@', 'at'] | ||
] | ||
}); | ||
//=> 'fooatunicorn' | ||
slugify('Foo@unicorn', { | ||
customReplacements: [ | ||
['@', 'at'] | ||
] | ||
}); | ||
//=> 'fooatunicorn' | ||
slugify('foo@unicorn', { | ||
customReplacements: [ | ||
['@', ' at '] | ||
] | ||
}); | ||
//=> 'foo-at-unicorn' | ||
slugify('foo@unicorn', { | ||
customReplacements: [ | ||
['@', ' at '] | ||
] | ||
}); | ||
//=> 'foo-at-unicorn' | ||
slugify('I love 🐶', { | ||
customReplacements: [ | ||
['🐶', 'dogs'] | ||
] | ||
}); | ||
//=> 'i-love-dogs' | ||
``` | ||
*/ | ||
readonly customReplacements?: ReadonlyArray<[string, string]>; | ||
slugify('I love 🐶', { | ||
customReplacements: [ | ||
['🐶', 'dogs'] | ||
] | ||
}); | ||
//=> 'i-love-dogs' | ||
``` | ||
*/ | ||
readonly customReplacements?: ReadonlyArray<[string, string]>; | ||
/** | ||
If your string starts with an underscore, it will be preserved in the slugified string. | ||
/** | ||
If your string starts with an underscore, it will be preserved in the slugified string. | ||
Sometimes leading underscores are intentional, for example, filenames representing hidden paths on a website. | ||
Sometimes leading underscores are intentional, for example, filenames representing hidden paths on a website. | ||
@default false | ||
@default false | ||
@example | ||
``` | ||
import slugify = require('@sindresorhus/slugify'); | ||
@example | ||
``` | ||
import slugify from '@sindresorhus/slugify'; | ||
slugify('_foo_bar'); | ||
//=> 'foo-bar' | ||
slugify('_foo_bar'); | ||
//=> 'foo-bar' | ||
slugify('_foo_bar', {preserveLeadingUnderscore: true}); | ||
//=> '_foo-bar' | ||
``` | ||
*/ | ||
readonly preserveLeadingUnderscore?: boolean; | ||
} | ||
slugify('_foo_bar', {preserveLeadingUnderscore: true}); | ||
//=> '_foo-bar' | ||
``` | ||
*/ | ||
readonly preserveLeadingUnderscore?: boolean; | ||
} | ||
declare const slugify: { | ||
/** | ||
Slugify a string. | ||
@param string - String to slugify. | ||
@example | ||
``` | ||
import slugify from '@sindresorhus/slugify'; | ||
slugify('I ♥ Dogs'); | ||
//=> 'i-love-dogs' | ||
slugify(' Déjà Vu! '); | ||
//=> 'deja-vu' | ||
slugify('fooBar 123 $#%'); | ||
//=> 'foo-bar-123' | ||
slugify('я люблю единорогов'); | ||
//=> 'ya-lyublyu-edinorogov' | ||
``` | ||
*/ | ||
export default function slugify(string: string, options?: Options): string; | ||
export interface CountableSlugify { | ||
/** | ||
Reset the counter. | ||
@example | ||
``` | ||
import {slugifyWithCounter} from '@sindresorhus/slugify'; | ||
const slugify = slugifyWithCounter(); | ||
slugify('foo bar'); | ||
//=> 'foo-bar' | ||
slugify('foo bar'); | ||
//=> 'foo-bar-2' | ||
slugify.reset(); | ||
slugify('foo bar'); | ||
//=> 'foo-bar' | ||
``` | ||
*/ | ||
reset: () => void; | ||
/** | ||
Returns a new instance of `slugify(string, options?)` with a counter to handle multiple occurences of the same string. | ||
@@ -127,14 +172,15 @@ | ||
``` | ||
import slugify = require('@sindresorhus/slugify'); | ||
import {slugifyWithCounter} from '@sindresorhus/slugify'; | ||
const countableSlugify = slugify.counter(); | ||
countableSlugify('foo bar'); | ||
const slugify = slugifyWithCounter(); | ||
slugify('foo bar'); | ||
//=> 'foo-bar' | ||
countableSlugify('foo bar'); | ||
slugify('foo bar'); | ||
//=> 'foo-bar-2' | ||
countableSlugify.reset(); | ||
slugify.reset(); | ||
countableSlugify('foo bar'); | ||
slugify('foo bar'); | ||
//=> 'foo-bar' | ||
@@ -157,61 +203,7 @@ ``` | ||
You can then use `slugify.counter()` to generate unique HTML `id`'s to ensure anchors will link to the right headline. | ||
You can then use `slugifyWithCounter()` to generate unique HTML `id`'s to ensure anchors will link to the right headline. | ||
*/ | ||
counter: () => { | ||
/** | ||
Reset the counter. | ||
(string: string, options?: Options): string; | ||
} | ||
@example | ||
``` | ||
import slugify = require('@sindresorhus/slugify'); | ||
const countableSlugify = slugify.counter(); | ||
countableSlugify('foo bar'); | ||
//=> 'foo-bar' | ||
countableSlugify('foo bar'); | ||
//=> 'foo-bar-2' | ||
countableSlugify.reset(); | ||
countableSlugify('foo bar'); | ||
//=> 'foo-bar' | ||
``` | ||
*/ | ||
reset: () => void; | ||
( | ||
string: string, | ||
options?: slugify.Options | ||
): string; | ||
}; | ||
/** | ||
Slugify a string. | ||
@param string - String to slugify. | ||
@example | ||
``` | ||
import slugify = require('@sindresorhus/slugify'); | ||
slugify('I ♥ Dogs'); | ||
//=> 'i-love-dogs' | ||
slugify(' Déjà Vu! '); | ||
//=> 'deja-vu' | ||
slugify('fooBar 123 $#%'); | ||
//=> 'foo-bar-123' | ||
slugify('я люблю единорогов'); | ||
//=> 'ya-lyublyu-edinorogov' | ||
``` | ||
*/ | ||
( | ||
string: string, | ||
options?: slugify.Options | ||
): string; | ||
}; | ||
export = slugify; | ||
export function slugifyWithCounter(): CountableSlugify; |
18
index.js
@@ -1,5 +0,4 @@ | ||
'use strict'; | ||
const escapeStringRegexp = require('escape-string-regexp'); | ||
const transliterate = require('@sindresorhus/transliterate'); | ||
const builtinOverridableReplacements = require('./overridable-replacements'); | ||
import escapeStringRegexp from 'escape-string-regexp'; | ||
import transliterate from '@sindresorhus/transliterate'; | ||
import builtinOverridableReplacements from './overridable-replacements.js'; | ||
@@ -24,3 +23,3 @@ const decamelize = string => { | ||
const slugify = (string, options) => { | ||
export default function slugify(string, options) { | ||
if (typeof string !== 'string') { | ||
@@ -70,5 +69,5 @@ throw new TypeError(`Expected a string, got \`${typeof string}\``); | ||
return string; | ||
}; | ||
} | ||
const counter = () => { | ||
export function slugifyWithCounter() { | ||
const occurrences = new Map(); | ||
@@ -100,5 +99,2 @@ | ||
return countable; | ||
}; | ||
module.exports = slugify; | ||
module.exports.counter = counter; | ||
} |
@@ -1,4 +0,2 @@ | ||
'use strict'; | ||
module.exports = [ | ||
const overridableReplacements = [ | ||
['&', ' and '], | ||
@@ -8,1 +6,3 @@ ['🦄', ' unicorn '], | ||
]; | ||
export default overridableReplacements; |
{ | ||
"name": "@sindresorhus/slugify", | ||
"version": "1.1.2", | ||
"version": "2.0.0", | ||
"description": "Slugify a string", | ||
@@ -13,4 +13,6 @@ "license": "MIT", | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=10" | ||
"node": ">=12" | ||
}, | ||
@@ -45,10 +47,10 @@ "scripts": { | ||
"dependencies": { | ||
"@sindresorhus/transliterate": "^0.1.1", | ||
"escape-string-regexp": "^4.0.0" | ||
"@sindresorhus/transliterate": "^1.0.0", | ||
"escape-string-regexp": "^5.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^2.4.0", | ||
"tsd": "^0.13.1", | ||
"xo": "^0.32.1" | ||
"ava": "^3.15.0", | ||
"tsd": "^0.14.0", | ||
"xo": "^0.38.2" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# slugify [![Build Status](https://travis-ci.com/sindresorhus/slugify.svg?branch=master)](https://travis-ci.com/github/sindresorhus/slugify) | ||
# slugify | ||
@@ -18,3 +18,3 @@ > Slugify a string | ||
```js | ||
const slugify = require('@sindresorhus/slugify'); | ||
import slugify from '@sindresorhus/slugify'; | ||
@@ -54,3 +54,3 @@ slugify('I ♥ Dogs'); | ||
```js | ||
const slugify = require('@sindresorhus/slugify'); | ||
import slugify from '@sindresorhus/slugify'; | ||
@@ -75,3 +75,3 @@ slugify('BAR and baz'); | ||
```js | ||
const slugify = require('@sindresorhus/slugify'); | ||
import slugify from '@sindresorhus/slugify'; | ||
@@ -93,3 +93,3 @@ slugify('Déjà Vu!'); | ||
```js | ||
const slugify = require('@sindresorhus/slugify'); | ||
import slugify from '@sindresorhus/slugify'; | ||
@@ -119,3 +119,3 @@ slugify('fooBar'); | ||
```js | ||
const slugify = require('@sindresorhus/slugify'); | ||
import slugify from '@sindresorhus/slugify'; | ||
@@ -133,3 +133,3 @@ slugify('Foo@unicorn', { | ||
```js | ||
const slugify = require('@sindresorhus/slugify'); | ||
import slugify from '@sindresorhus/slugify'; | ||
@@ -147,3 +147,3 @@ slugify('foo@unicorn', { | ||
```js | ||
const slugify = require('@sindresorhus/slugify'); | ||
import slugify from '@sindresorhus/slugify'; | ||
@@ -168,3 +168,3 @@ slugify('I love 🐶', { | ||
```js | ||
const slugify = require('@sindresorhus/slugify'); | ||
import slugify from '@sindresorhus/slugify'; | ||
@@ -178,3 +178,3 @@ slugify('_foo_bar'); | ||
### slugify.counter() | ||
### slugifyWithCounter() | ||
@@ -186,15 +186,15 @@ Returns a new instance of `slugify(string, options?)` with a counter to handle multiple occurences of the same string. | ||
```js | ||
const slugify = require('@sindresorhus/slugify'); | ||
import {slugifyWithCounter} from '@sindresorhus/slugify'; | ||
const countableSlugify = slugify.counter(); | ||
const slugify = slugifyWithCounter(); | ||
countableSlugify('foo bar'); | ||
slugify('foo bar'); | ||
//=> 'foo-bar' | ||
countableSlugify('foo bar'); | ||
slugify('foo bar'); | ||
//=> 'foo-bar-2' | ||
countableSlugify.reset(); | ||
slugify.reset(); | ||
countableSlugify('foo bar'); | ||
slugify('foo bar'); | ||
//=> 'foo-bar' | ||
@@ -217,3 +217,3 @@ ``` | ||
You can then use `slugify.counter()` to generate unique HTML `id`'s to ensure anchors will link to the right headline. | ||
You can then use `slugifyWithCounter()` to generate unique HTML `id`'s to ensure anchors will link to the right headline. | ||
@@ -227,15 +227,15 @@ ### slugify.reset() | ||
```js | ||
const slugify = require('@sindresorhus/slugify'); | ||
import {slugifyWithCounter} from '@sindresorhus/slugify'; | ||
const countableSlugify = slugify.counter(); | ||
const slugify = slugifyWithCounter(); | ||
countableSlugify('foo bar'); | ||
slugify('foo bar'); | ||
//=> 'foo-bar' | ||
countableSlugify('foo bar'); | ||
slugify('foo bar'); | ||
//=> 'foo-bar-2' | ||
countableSlugify.reset(); | ||
slugify.reset(); | ||
countableSlugify('foo bar'); | ||
slugify('foo bar'); | ||
//=> 'foo-bar' | ||
@@ -242,0 +242,0 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Yes
12562
229
+ Added@sindresorhus/transliterate@1.6.0(transitive)
+ Addedescape-string-regexp@5.0.0(transitive)
- Removed@sindresorhus/transliterate@0.1.2(transitive)
- Removedescape-string-regexp@2.0.04.0.0(transitive)
- Removedlodash.deburr@4.1.0(transitive)
Updatedescape-string-regexp@^5.0.0