github-slugger
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -6,2 +6,11 @@ # github-slugger change log | ||
## 1.2.1 2019-xx-xx | ||
* Fix collisions for slugs with occurrences | ||
* Fix accessing `Object.prototype` methods | ||
* Fix Russian | ||
* Add `files` to package.json | ||
## 1.2.0 2017-09-21 | ||
* Add `maintainCase` support | ||
## 1.1.3 2017-05-29 | ||
@@ -8,0 +17,0 @@ * Fix`emoji-regex` semver version to ensure npm5 compatibility. |
41
index.js
@@ -5,4 +5,9 @@ var emoji = require('emoji-regex') | ||
var own = Object.hasOwnProperty | ||
var whitespace = /\s/g | ||
var specials = /[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g | ||
function BananaSlug () { | ||
var self = this | ||
if (!(self instanceof BananaSlug)) return new BananaSlug() | ||
@@ -20,19 +25,13 @@ | ||
BananaSlug.prototype.slug = function (value, maintainCase) { | ||
maintainCase = maintainCase === true | ||
var self = this | ||
var slug = slugger(value, maintainCase) | ||
var occurrences = self.occurrences[slug] | ||
var slug = slugger(value, maintainCase === true) | ||
var originalSlug = slug | ||
if (self.occurrences.hasOwnProperty(slug)) { | ||
occurrences++ | ||
} else { | ||
occurrences = 0 | ||
while (own.call(self.occurrences, slug)) { | ||
self.occurrences[originalSlug]++ | ||
slug = originalSlug + '-' + self.occurrences[originalSlug] | ||
} | ||
self.occurrences[slug] = occurrences | ||
self.occurrences[slug] = 0 | ||
if (occurrences) { | ||
slug = slug + '-' + occurrences | ||
} | ||
return slug | ||
@@ -46,21 +45,13 @@ } | ||
BananaSlug.prototype.reset = function () { | ||
this.occurrences = {} | ||
this.occurrences = Object.create(null) | ||
} | ||
var whitespace = /\s/g | ||
function lower (string) { | ||
return string.toLowerCase() | ||
} | ||
function slugger (string, maintainCase) { | ||
var re = /[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g | ||
var replacement = '-' | ||
if (typeof string !== 'string') return '' | ||
if (!maintainCase) string = string.toLowerCase() | ||
if (typeof string !== 'string') return '' | ||
if (!maintainCase) string = string.replace(/[A-Z]+/g, lower) | ||
return string.trim() | ||
.replace(re, '') | ||
.replace(specials, '') | ||
.replace(emoji(), '') | ||
.replace(whitespace, replacement) | ||
.replace(whitespace, '-') | ||
} |
{ | ||
"name": "github-slugger", | ||
"description": "Generate a slug just like GitHub does for markdown headings.", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"author": "Dan Flettre <fletd01@yahoo.com>", | ||
@@ -13,2 +13,5 @@ "contributors": [ | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"dependencies": { | ||
@@ -18,4 +21,5 @@ "emoji-regex": ">=6.0.0 <=6.1.1" | ||
"devDependencies": { | ||
"nyc": "^13.1.0", | ||
"standard": "*", | ||
"tap-spec": "^4.0.2", | ||
"tap-spec": "^5.0.0", | ||
"tape": "^4.0.0" | ||
@@ -41,4 +45,13 @@ }, | ||
"scripts": { | ||
"test": "standard && tape test/*.js | tap-spec" | ||
"format": "standard --fix", | ||
"test-api": "tape test | tap-spec", | ||
"test-coverage": "nyc --reporter lcov tape test/index.js | tap-spec", | ||
"test": "npm run format && npm run test-coverage" | ||
}, | ||
"nyc": { | ||
"check-coverage": true, | ||
"lines": 100, | ||
"functions": 100, | ||
"branches": 100 | ||
} | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
5644
4
5
42
1