@sindresorhus/slugify
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -115,2 +115,22 @@ export interface Options { | ||
readonly preserveLeadingUnderscore?: boolean; | ||
/** | ||
If your string ends with a dash, it will be preserved in the slugified string. | ||
For example, using slugify on an input field would allow for validation while not preventing the user from writing a slug. | ||
@default false | ||
@example | ||
``` | ||
import slugify from '@sindresorhus/slugify'; | ||
slugify('foo-bar-'); | ||
//=> 'foo-bar' | ||
slugify('foo-bar-', {preserveTrailingDash: true}); | ||
//=> 'foo-bar-' | ||
``` | ||
*/ | ||
readonly preserveTrailingDash?: boolean; | ||
} | ||
@@ -167,3 +187,3 @@ | ||
/** | ||
Returns a new instance of `slugify(string, options?)` with a counter to handle multiple occurences of the same string. | ||
Returns a new instance of `slugify(string, options?)` with a counter to handle multiple occurrences of the same string. | ||
@@ -170,0 +190,0 @@ @param string - String to slugify. |
@@ -34,2 +34,3 @@ import escapeStringRegexp from 'escape-string-regexp'; | ||
preserveLeadingUnderscore: false, | ||
preserveTrailingDash: false, | ||
...options | ||
@@ -39,2 +40,3 @@ }; | ||
const shouldPrependUnderscore = options.preserveLeadingUnderscore && string.startsWith('_'); | ||
const shouldAppendDash = options.preserveTrailingDash && string.endsWith('-'); | ||
@@ -69,2 +71,6 @@ const customReplacements = new Map([ | ||
if (shouldAppendDash) { | ||
string = `${string}-`; | ||
} | ||
return string; | ||
@@ -71,0 +77,0 @@ } |
{ | ||
"name": "@sindresorhus/slugify", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Slugify a string", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -170,5 +170,24 @@ # slugify | ||
##### preserveTrailingDash | ||
Type: `boolean`\ | ||
Default: `false` | ||
If your string ends with a dash, it will be preserved in the slugified string. | ||
For example, using slugify on an input field would allow for validation while not preventing the user from writing a slug. | ||
```js | ||
import slugify from '@sindresorhus/slugify'; | ||
slugify('foo-bar-'); | ||
//=> 'foo-bar' | ||
slugify('foo-bar-', {preserveTrailingDash: true}); | ||
//=> 'foo-bar-' | ||
``` | ||
### slugifyWithCounter() | ||
Returns a new instance of `slugify(string, options?)` with a counter to handle multiple occurences of the same string. | ||
Returns a new instance of `slugify(string, options?)` with a counter to handle multiple occurrences of the same string. | ||
@@ -175,0 +194,0 @@ #### Example |
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
13608
248
256