diff --git a/api-server/common/utils/index.js b/api-server/common/utils/index.js index 52351d0863..c467d7c48a 100644 --- a/api-server/common/utils/index.js +++ b/api-server/common/utils/index.js @@ -10,17 +10,6 @@ export { renderSignInEmail } from './auth'; -export function dashify(str) { - return ('' + str) - .toLowerCase() - .replace(/\s/g, '-') - .replace(/[^a-z0-9\-.]/gi, '') - .replace(/:/g, ''); -} -// todo: unify with server/utils/index.js:dasherize -const dasherize = dashify; -export { dasherize }; - export const fixCompletedChallengeItem = obj => pick(obj, [ 'id', diff --git a/api-server/server/boot/challenge.js b/api-server/server/boot/challenge.js index 52d395d150..0818130bef 100644 --- a/api-server/server/boot/challenge.js +++ b/api-server/server/boot/challenge.js @@ -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'; diff --git a/api-server/server/boot/commit.js b/api-server/server/boot/commit.js index 782b474bb8..dd7be86e2e 100644 --- a/api-server/server/boot/commit.js +++ b/api-server/server/boot/commit.js @@ -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'; diff --git a/api-server/server/utils/index.js b/api-server/server/utils/index.js index 4959464313..22a76d5bbc 100644 --- a/api-server/server/utils/index.js +++ b/api-server/server/utils/index.js @@ -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`; }; diff --git a/api-server/server/utils/map.js b/api-server/server/utils/map.js index d34d69e0f8..02c39cdac0 100644 --- a/api-server/server/utils/map.js +++ b/api-server/server/utils/map.js @@ -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, diff --git a/client/gatsby-node.js b/client/gatsby-node.js index 623f79422c..2c6811ed2f 100644 --- a/client/gatsby-node.js +++ b/client/gatsby-node.js @@ -2,7 +2,7 @@ require('dotenv').config(); const { createFilePath } = require('gatsby-source-filesystem'); -const { dasherize } = require('./utils'); +const { dasherize } = require('../utils/slugs'); const { blockNameify } = require('./utils/blockNameify'); const { createChallengePages, diff --git a/client/src/templates/Challenges/classic/Show.js b/client/src/templates/Challenges/classic/Show.js index b377695e38..d5d3fc2389 100644 --- a/client/src/templates/Challenges/classic/Show.js +++ b/client/src/templates/Challenges/classic/Show.js @@ -24,7 +24,7 @@ import Hotkeys from '../components/Hotkeys'; import { getGuideUrl } from '../utils'; import { challengeTypes } from '../../../../utils/challengeTypes'; import { ChallengeNode } from '../../../redux/propTypes'; -import { dasherize } from '../../../../utils'; +import { dasherize } from '../../../../../utils/slugs'; import { createFiles, challengeFilesSelector, diff --git a/client/src/templates/Challenges/components/CompletionModal.js b/client/src/templates/Challenges/components/CompletionModal.js index 1304bdc82d..6c422bf420 100644 --- a/client/src/templates/Challenges/components/CompletionModal.js +++ b/client/src/templates/Challenges/components/CompletionModal.js @@ -8,7 +8,7 @@ import { Button, Modal } from '@freecodecamp/react-bootstrap'; import ga from '../../../analytics'; import GreenPass from '../../../assets/icons/GreenPass'; -import { dasherize } from '../../../../utils'; +import { dasherize } from '../../../../../utils/slugs'; import './completion-modal.css'; diff --git a/client/utils/buildChallenges.js b/client/utils/buildChallenges.js index c81c072083..b1f9ae61bc 100644 --- a/client/utils/buildChallenges.js +++ b/client/utils/buildChallenges.js @@ -5,13 +5,10 @@ const { createChallenge, getChallengesDirForLang } = require('../../curriculum/getChallenges'); -const utils = require('./'); +const { dasherize, nameify } = require('../../utils/slugs'); const { locale } = require('../config/env.json'); const { blockNameify } = require('./blockNameify'); -const dasherize = utils.dasherize; -const nameify = utils.nameify; - const arrToString = arr => Array.isArray(arr) ? arr.join('\n') : _.toString(arr); diff --git a/client/utils/gatsby/challengePageCreator.js b/client/utils/gatsby/challengePageCreator.js index 5d04a090f4..109e2bd66f 100644 --- a/client/utils/gatsby/challengePageCreator.js +++ b/client/utils/gatsby/challengePageCreator.js @@ -1,5 +1,5 @@ const path = require('path'); -const { dasherize } = require('..'); +const { dasherize } = require('../../../utils/slugs'); const { viewTypes } = require('../challengeTypes'); diff --git a/client/utils/index.js b/client/utils/index.js index feb63d4137..bad6519bdc 100644 --- a/client/utils/index.js +++ b/client/utils/index.js @@ -1,25 +1,3 @@ -exports.dasherize = function dasherize(name) { - return ('' + name) - .toLowerCase() - .replace(/\s/g, '-') - .replace(/[^a-z0-9\-.]/gi, ''); -}; - -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.descriptionRegex = /