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

github-slugger

Package Overview
Dependencies
Maintainers
5
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github-slugger - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

9

CHANGELOG.md

@@ -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
}
}
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