Skip to content

Commit

Permalink
proper slugify helper
Browse files Browse the repository at this point in the history
  • Loading branch information
jonschlinkert committed Jul 19, 2016
1 parent a839553 commit e1ed96c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
4 changes: 1 addition & 3 deletions lib/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,7 @@ exports.hyphenate = function hyphenate(str) {
* @api draft
*/

exports.slugify = function slugify(str) {
return exports.isString(str) ? exports.dashcase(str) : '';
};
exports.slugify = require('helper-slugify');

/**
* Reverse the characters in a string.
Expand Down
13 changes: 13 additions & 0 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require('make-iterator');
require('object.omit', 'omit');
require('relative');
require('right-align', 'alignRight');
require('strip-color');
require('titlecase');
require('to-gfm-code-block', 'block');
require('word-wrap', 'wrap');
Expand All @@ -51,6 +52,18 @@ utils.isEmpty = function(val) {
}
};

/**
* Get the "title" from a markdown link
*/

utils.getTitle = function(str) {
if (/^\[[^\]]+\]\(/.test(str)) {
var m = /^\[([^\]]+)\]/.exec(str);
if (m) return m[1];
}
return str;
};

/**
* Returns true if the given `val` is an object.
*
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"export-files": "^2.1.1",
"fs-exists-sync": "^0.1.0",
"get-value": "^2.0.6",
"helper-slugify": "^0.2.0",
"is-absolute": "^0.2.5",
"is-number": "^2.1.0",
"is-plain-object": "^2.0.1",
Expand All @@ -39,6 +40,7 @@
"object.omit": "^2.0.0",
"relative": "^3.0.2",
"right-align": "^0.1.3",
"strip-color": "^0.1.0",
"titlecase": "^1.1.2",
"to-gfm-code-block": "^0.1.1",
"word-wrap": "^1.1.0"
Expand All @@ -54,7 +56,7 @@
"markdown-link": "^0.1.1",
"mocha": "^2.5.3",
"through2": "^2.0.1",
"verb-generate-readme": "^0.1.21"
"verb-generate-readme": "^0.1.26"
},
"keywords": [
"compile",
Expand Down Expand Up @@ -83,9 +85,8 @@
"slugify",
"templates",
"verb",
"verb-readme-generator",
"word-wrap",
"verb-generate-readme"
"verb-generate-readme",
"word-wrap"
],
"related": {
"list": [
Expand All @@ -105,4 +106,4 @@
"reflinks": true
}
}
}
}
8 changes: 5 additions & 3 deletions test/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,19 @@ describe('string helpers', function() {
it('should return an empty string when undefined.', function() {
assert.equal(template('<%= slugify() %>', imports)(), '');
});

it('should slugify the characters in a string.', function() {
assert.equal(template('<%= slugify("foo bar baz") %>', imports)(), 'foo-bar-baz');
});

it('should work with hyphens.', function() {
assert.equal(template('<%= slugify("foo-bar-baz") %>', imports)(), 'foo-bar-baz');
assert.equal(template('<%= slugify("-foo bar baz-") %>', imports)(), 'foo-bar-baz');
assert.equal(template('<%= slugify("-foo bar baz-") %>', imports)(), '-foo-bar-baz-');
});

it('should work with other non-word characters.', function() {
assert.equal(template('<%= slugify("9foo-bar_baz") %>', imports)(), '9foo-bar-baz');
assert.equal(template('<%= slugify("_foo_bar_baz-") %>', imports)(), 'foo-bar-baz');
assert.equal(template('<%= slugify("9foo-bar_baz") %>', imports)(), '9foo-bar_baz');
assert.equal(template('<%= slugify("_foo_bar_baz-") %>', imports)(), '_foo_bar_baz-');
});
});

Expand Down

0 comments on commit e1ed96c

Please # to comment.