From 3e3f7ed3dd07e2cb8410bb0cbff3396b37c0e140 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 7 May 2020 13:52:37 +0800 Subject: [PATCH] Meta tweaks --- index.d.ts | 68 ++++++++++++++++++++++++------------------------- index.js | 2 +- index.test-d.ts | 2 +- package.json | 4 +-- 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/index.d.ts b/index.d.ts index 29703bd..d5c2f1d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -114,33 +114,6 @@ declare namespace slugify { } declare const slugify: { - /** - 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; - /** Returns a new instance of `slugify(string, options?)` with a counter to handle multiple occurences of the same string. @@ -180,11 +153,6 @@ declare const slugify: { You can then use `slugify.counter()` to generate unique HTML `id`'s to ensure anchors will link to the right headline. */ counter: () => { - ( - string: string, - options?: slugify.Options - ): string; - /** Reset the counter. @@ -205,8 +173,40 @@ declare const slugify: { //=> 'foo-bar' ``` */ - reset(): void; + 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; diff --git a/index.js b/index.js index 53d635e..21e315e 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,7 @@ const builtinOverridableReplacements = require('./overridable-replacements'); const decamelize = string => { return string // Separate capitalized words. - .replace(/([A-Z]{2,})([\d]+)/g, '$1 $2') + .replace(/([A-Z]{2,})(\d+)/g, '$1 $2') .replace(/([a-z\d]+)([A-Z]{2,})/g, '$1 $2') .replace(/([a-z\d])([A-Z])/g, '$1 $2') diff --git a/index.test-d.ts b/index.test-d.ts index b60084e..97c7d2e 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -8,6 +8,6 @@ expectType(slugify('fooBar', {decamelize: false})); expectType(slugify('I ♥ 🦄 & 🐶', {customReplacements: [['🐶', 'dog']]})); expectType(slugify('_foo_bar', {preserveLeadingUnderscore: true})); -// counter +// Counter expectType(slugify.counter()('I ♥ Dogs')); expectType(slugify.counter().reset()); diff --git a/package.json b/package.json index 31edb3d..7b8aa51 100644 --- a/package.json +++ b/package.json @@ -42,11 +42,11 @@ ], "dependencies": { "@sindresorhus/transliterate": "^0.1.0", - "escape-string-regexp": "^2.0.0" + "escape-string-regexp": "^4.0.0" }, "devDependencies": { "ava": "^2.4.0", "tsd": "^0.11.0", - "xo": "^0.26.1" + "xo": "^0.30.0" } }