import { compose } from 'redux'; import { BONFIRE, HTML, JS } from '../../utils/challengeTypes'; export function encodeScriptTags(value) { return value .replace(/'); } export function encodeFormAction(value) { return value.replace( /]*>/, val => val.replace(/action(\s*?)=/, 'fccfaa$1=') ); } export function decodeFccfaaAttr(value) { return value.replace( /]*>/, val => val.replace(/fccfaa(\s*?)=/, 'action$1=') ); } export function arrayToString(seedData = ['']) { seedData = Array.isArray(seedData) ? seedData : [seedData]; return seedData.reduce((seed, line) => '' + seed + line + '\n', '\n'); } export function buildSeed({ challengeSeed = [] } = {}) { return compose( decodeSafeTags, arrayToString )(challengeSeed); } const pathsMap = { [HTML]: 'main.html', [JS]: 'main.js', [BONFIRE]: 'main.js' }; export function getPath({ challengeType }) { return pathsMap[challengeType] || 'main'; } export function createTests({ tests = [] }) { return tests .map(test => ({ text: test.split('message: ').pop().replace(/\'\);/g, '') })); }