refactor: combine slug utils into one module
This commit is contained in:
committed by
mrugesh
parent
32ee2f032c
commit
9c2f1ffd82
@ -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',
|
||||
|
@ -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';
|
||||
|
||||
|
@ -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';
|
||||
|
||||
|
@ -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`;
|
||||
};
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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';
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
const path = require('path');
|
||||
const { dasherize } = require('..');
|
||||
const { dasherize } = require('../../../utils/slugs');
|
||||
|
||||
const { viewTypes } = require('../challengeTypes');
|
||||
|
||||
|
@ -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 = /<blockquote|<ol|<h4|<table/;
|
||||
|
||||
exports.isBrowser = function isBrowser() {
|
||||
|
@ -3,7 +3,7 @@ const { findIndex } = require('lodash');
|
||||
const readDirP = require('readdirp-walk');
|
||||
const { parseMarkdown } = require('@freecodecamp/challenge-md-parser');
|
||||
|
||||
const { dasherize } = require('./utils');
|
||||
const { dasherize } = require('../utils/slugs');
|
||||
|
||||
const challengesDir = path.resolve(__dirname, './challenges');
|
||||
const metaDir = path.resolve(challengesDir, '_meta');
|
||||
|
@ -6,7 +6,7 @@ const adler32 = require('adler32');
|
||||
const Rx = require('rx');
|
||||
const _ = require('lodash');
|
||||
const createDebugger = require('debug');
|
||||
const utils = require('../server/utils');
|
||||
const { dasherize, nameify } = require('../utils/slugs');
|
||||
const getChallenges = require('./getChallenges');
|
||||
const { validateChallenge } = require('./schema/challengeSchema');
|
||||
const app = require('../server/server');
|
||||
@ -16,8 +16,6 @@ const log = createDebugger('fcc:seed');
|
||||
// this may be brittle
|
||||
log.enabled = true;
|
||||
|
||||
const dasherize = utils.dasherize;
|
||||
const nameify = utils.nameify;
|
||||
const Observable = Rx.Observable;
|
||||
const Challenge = app.models.Challenge;
|
||||
|
||||
|
@ -1,14 +1,6 @@
|
||||
const path = require('path');
|
||||
require('dotenv').config({ path: path.resolve(__dirname, '../.env') });
|
||||
|
||||
exports.dasherize = function dasherize(name) {
|
||||
return ('' + name)
|
||||
.toLowerCase()
|
||||
.replace(/\s/g, '-')
|
||||
.replace(/[^a-z0-9\-\.]/gi, '')
|
||||
.replace(/\:/g, '');
|
||||
};
|
||||
|
||||
const supportedLangs = [
|
||||
'arabic',
|
||||
'chinese',
|
||||
|
@ -1,7 +1,7 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const matter = require('gray-matter');
|
||||
const { dasherize } = require('../../../client/utils');
|
||||
const { dasherize } = require('../../../utils/slugs');
|
||||
|
||||
const pass = true;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
const { flatten } = require('lodash');
|
||||
|
||||
const { dasherize } = require('../../../api-server/server/utils');
|
||||
const { dasherize } = require('../../../utils/slugs');
|
||||
|
||||
function createPathMigrationMap(curriculum) {
|
||||
return Object.keys(curriculum)
|
||||
|
21
utils/slugs.js
Normal file
21
utils/slugs.js
Normal file
@ -0,0 +1,21 @@
|
||||
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, '');
|
||||
};
|
||||
|
||||
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()
|
||||
);
|
||||
};
|
Reference in New Issue
Block a user