slug-component
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -5,3 +5,3 @@ { | ||
"description": "slug generator", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"keywords": ["slug"], | ||
@@ -8,0 +8,0 @@ "dependencies": {}, |
1.1.0 / 2013-02-15 | ||
================== | ||
* added options object, with replace and separator [ianstormtaylor] | ||
0.0.1 / 2012-11-28 | ||
@@ -3,0 +8,0 @@ ================== |
11
index.js
@@ -11,11 +11,14 @@ | ||
* @param {String} str | ||
* @param {String} repl defaulted to `-` | ||
* @param {Object} options | ||
* @config {String|RegExp} [replace] characters to replace, defaulted to `/[^a-z0-9]/g` | ||
* @config {String} [separator] separator to insert, defaulted to `-` | ||
* @return {String} | ||
*/ | ||
module.exports = function (str, repl) { | ||
module.exports = function (str, options) { | ||
options || (options = {}); | ||
return str.toLowerCase() | ||
.replace(/[^a-z0-9]/g, ' ') | ||
.replace(options.replace || /[^a-z0-9]/g, ' ') | ||
.replace(/^ +| +$/g, '') | ||
.replace(/ +/g, repl || '-') | ||
.replace(/ +/g, options.separator || '-') | ||
}; |
{ | ||
"name": "slug-component", | ||
"description": "slug generator", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"author": "Amir Abu Shareb <yields@icloud.com>", | ||
"license": "MIT" | ||
} |
@@ -27,6 +27,10 @@ | ||
it('should respect `replacement` parameter', function () { | ||
assert(gen('foo bar', '_') == 'foo_bar'); | ||
it('should respect `separator` option', function () { | ||
assert(gen('foo bar', { separator: '_' }) == 'foo_bar'); | ||
}) | ||
it('should respect `replace` option', function () { | ||
assert(gen('foo bar', { replace : /o/g }) == 'f-bar'); | ||
}) | ||
it('should trim', function () { | ||
@@ -33,0 +37,0 @@ assert(gen(' foo ---') == 'foo'); |
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
99233
4007