-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6e0b723
Showing
5 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# SlugIt # | ||
|
||
Another slug package. Seriously. | ||
|
||
## Synopsis ## | ||
|
||
```js | ||
var slugit = require('slugit') | ||
|
||
console.log(slugit('Hello, World!')) | ||
// -> 'hello-world' | ||
``` | ||
|
||
## Author ## | ||
|
||
Andrew Chilton. | ||
|
||
## License ## | ||
|
||
ISC. | ||
|
||
(Ends) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
'use strict' | ||
|
||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
function slugit(title) { | ||
title = title || '' | ||
title = title.toLowerCase().trim() | ||
title = title.replace(/[\'\"]/g, '') | ||
title = title.replace(/[^0-9A-Za-z]+/g, '-') | ||
title = title.replace(/-+/g, '-').replace(/^-/, '').replace(/-$/, '') | ||
return title | ||
} | ||
|
||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
module.exports = slugit | ||
|
||
// -------------------------------------------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "slugit", | ||
"description": "Another slug package.", | ||
"version": "1.0.0", | ||
"scripts": { | ||
"test": "for FILE in test/*.js; do echo \"# --- $FILE ---\"; echo; tape $FILE; done" | ||
}, | ||
"devDependencies": { | ||
"tape": "^4.6.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/chilts/slugit.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/chilts/slugit/issues", | ||
"email": "[email protected]" | ||
}, | ||
"author": { | ||
"name": "Andrew Chilton", | ||
"email": "[email protected]", | ||
"url": "https://chilts.org/" | ||
}, | ||
"license": "ISC" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
"use strict" | ||
|
||
// npm | ||
var test = require('tape') | ||
|
||
// local | ||
var slugit = require('../') | ||
|
||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
var simple = [ | ||
[ 'Simple', 'simple', ], | ||
[ 'Hello, World!', 'hello-world', ], | ||
[ ' a ', 'a', ], | ||
[ '1234', '1234', ], | ||
[ '', '', ], | ||
[ 'The Mountains', 'the-mountains', ], | ||
[ "Andy's Tea", 'andys-tea', ], | ||
[ '!@#^&Expletive&@^#*@', 'expletive', ], | ||
] | ||
|
||
test('simple', function(t) { | ||
t.plan(simple.length) | ||
|
||
simple.forEach(function(row) { | ||
t.equal(slugit(row[0]), row[1], 'Testing ' + row[0]) | ||
}) | ||
|
||
t.end() | ||
}) | ||
|
||
// -------------------------------------------------------------------------------------------------------------------- |