forked from kb18519142009/android_interview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
25 lines (18 loc) · 675 Bytes
/
index.js
File metadata and controls
25 lines (18 loc) · 675 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var SYMBOLS = [
'[', ']', '!', '"', '\'', '#',
'$', '%', '&', '(', ')', '*', '+', ',', '.', '/', ':', ';', '<', '=',
'>', '?', '@', '', '', '^', '_', '`', '{', '|', '}', '~',
'©', '∑', '®', '†', '“', '”', '‘', '’', '∂', 'ƒ', '™', '℠', '…',
'œ', 'Œ','˚', 'º', 'ª', '•', '∆', '∞', '♥', '&', '|'
];
function slug(content, separator) {
separator = separator || '-';
var re = new RegExp('[\\'+SYMBOLS.join('\\')+']+', 'g');
var s = content
.replace(re, '')
.replace(/ /g, separator)
.toLowerCase();
if (s[0] == separator) s = s.slice(1);
return s;
}
module.exports = slug;