Comparing version 0.0.11 to 0.0.12
19
index.js
'use strict' | ||
const unidecode = require('unidecode') | ||
class Stringfy { | ||
@@ -29,2 +31,19 @@ constructor (string) { | ||
} | ||
slug () { | ||
const seperator = '-' | ||
let string = this.string | ||
string = unidecode(string) | ||
string = string.replace(/[:\/\?#\[\]@!$&'()*+,;=\\%<>\|\^~£"]/g, '') | ||
// Replace dots and spaces with a sepeator | ||
.replace(/(\s|\.)/g, seperator) | ||
// Convert 2 or more sepeators into just one sepeator | ||
.replace(/-+/g, seperator) | ||
// Make the whole thing lowercase | ||
.toLowerCase() | ||
if(string.substring(string.length - 1) == seperator){ | ||
string = string.substring(0, string.length - 1) | ||
} | ||
this.string = string | ||
return this | ||
} | ||
val () { | ||
@@ -31,0 +50,0 @@ return this.string |
{ | ||
"name": "stringfy", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"description": "", | ||
@@ -14,3 +14,6 @@ "main": "index.js", | ||
"should": "^7.1.0" | ||
}, | ||
"dependencies": { | ||
"unidecode": "^0.1.7" | ||
} | ||
} |
@@ -21,2 +21,6 @@ # Stringfy | ||
stringfy('呆死ki').count() | ||
// return slugify string, with CJK support | ||
// like 'I love cat' => 'i-love-cat' | ||
string('空彩观测').slug().val() | ||
``` | ||
@@ -23,0 +27,0 @@ |
@@ -35,2 +35,11 @@ var stringfy = require('./index') | ||
}) | ||
describe('slug', () => { | ||
it('should return slugify string kong-cai-guan-ce', () => { | ||
stringfy('空彩观测').slug().val().should.equal('kong-cai-guan-ce') | ||
}) | ||
it('should return slugify string te-me-go-to-hell', () => { | ||
stringfy('te me, go to hell').slug().val().should.equal('te-me-go-to-hell') | ||
}) | ||
}) | ||
}) |
4320
90
30
1
+ Addedunidecode@^0.1.7
+ Addedunidecode@0.1.8(transitive)