refactor: combine slug utils into one module

This commit is contained in:
Oliver Eyton-Williams
2019-09-25 20:16:08 +02:00
committed by mrugesh
parent 32ee2f032c
commit 9c2f1ffd82
17 changed files with 33 additions and 81 deletions

View File

@ -15,7 +15,7 @@ import isURL from 'validator/lib/isURL';
import { homeLocation } from '../../../config/env';
import { ifNoUserSend } from '../utils/middleware';
import { dasherize } from '../utils';
import { dasherize } from '../../../utils/slugs';
import _pathMigrations from '../resources/pathMigration.json';
import { fixCompletedChallengeItem } from '../../common/utils';

View File

@ -8,7 +8,7 @@ import { homeLocation } from '../../../config/env';
import nonprofits from '../utils/commit.json';
import { commitGoals, completeCommitment$ } from '../utils/commit';
import { unDasherize } from '../utils';
import { unDasherize } from '../../../utils/slugs';
import { observeQuery, saveInstance } from '../utils/rx';

View File

@ -1,26 +1,3 @@
exports.dasherize = function dasherize(name) {
return ('' + name)
.toLowerCase()
.replace(/\s/g, '-')
.replace(/[^a-z0-9\-.]/gi, '')
.replace(/:/g, '');
};
exports.nameify = function nameify(str) {
return ('' + str).replace(/[^a-zA-Z0-9\s]/g, '').replace(/:/g, '');
};
exports.unDasherize = function unDasherize(name) {
return (
('' + name)
// replace dash with space
.replace(/-/g, ' ')
// strip nonalphanumarics chars except whitespace
.replace(/[^a-zA-Z\d\s]/g, '')
.trim()
);
};
exports.addPlaceholderImage = function addPlaceholderImage(name) {
return `https://example.com/${name}.png`;
};

View File

@ -1,7 +1,7 @@
import _ from 'lodash';
import { Observable } from 'rx';
import { unDasherize, nameify } from '../utils';
import { unDasherize, nameify } from '../../../utils/slugs';
import {
addNameIdMap as _addNameIdToMap,
checkMapData,