factor out (un)dasherize into utils

This commit is contained in:
Berkeley Martinez
2015-06-22 17:24:55 -07:00
parent 10a5c3c928
commit d624cf3640
2 changed files with 15 additions and 12 deletions

View File

@ -47,21 +47,13 @@ var R = require('ramda'),
var challengeMapWithNames = utils.getChallengeMapWithNames();
var challengeMapWithIds = utils.getChallengeMapWithIds();
var challengeMapWithDashedNames = utils.getChallengeMapWithDashedNames();
var challangesRegex = /^(bonfire|waypoint|zipline|basejump)/i;
var dasherize = utils.dasherize;
var unDasherize = utils.unDashedName;
var getMDNLinks = utils.getMDNLinks;
var challangesRegex = /^(bonfire|waypoint|zipline|basejump)/i;
function dasherize(name) {
return ('' + name)
.toLowerCase()
.replace(/\s/g, '-')
.replace(/[^a-z0-9\-\.]/gi, '');
}
function unDasherize(name) {
return ('' + name).replace(/\-/g, ' ');
}
function updateUserProgress(user, challengeId, completedChallenge) {
var index = user.uncompletedChallenges.indexOf(challengeId);
if (index > -1) {

View File

@ -60,6 +60,17 @@ Array.zip = function(left, right, combinerFunction) {
module.exports = {
dasherize: function dasherize(name) {
return ('' + name)
.toLowerCase()
.replace(/\s/g, '-')
.replace(/[^a-z0-9\-\.]/gi, '');
},
unDasherize: function unDasherize(name) {
return ('' + name).replace(/\-/g, ' ');
},
getChallengeMapForDisplay: function () {
if (!challengeMapForDisplay) {
challengeMapForDisplay = {};