fix: add tests and refactor slug utils

This commit is contained in:
Oliver Eyton-Williams
2019-09-26 16:27:26 +02:00
committed by mrugesh
parent 9c2f1ffd82
commit 3dc4e5897d
3 changed files with 53 additions and 4 deletions

View File

@ -2,11 +2,11 @@ exports.dasherize = function dasherize(name) {
return ('' + name)
.toLowerCase()
.replace(/\s/g, '-')
.replace(/[^a-z0-9\-.]/gi, '');
.replace(/[^a-z\d\-.]/g, '');
};
exports.nameify = function nameify(str) {
return ('' + str).replace(/[^a-zA-Z0-9\s]/g, '');
return ('' + str).replace(/[^a-z\d\s]/gi, '');
};
exports.unDasherize = function unDasherize(name) {
@ -15,7 +15,7 @@ exports.unDasherize = function unDasherize(name) {
// replace dash with space
.replace(/-/g, ' ')
// strip nonalphanumarics chars except whitespace
.replace(/[^a-zA-Z\d\s]/g, '')
.replace(/[^a-z\d\s]/gi, '')
.trim()
);
};