2016-05-11 23:45:42 -07:00
|
|
|
import { compose } from 'redux';
|
2016-05-13 20:04:56 -07:00
|
|
|
import { BONFIRE, HTML, JS } from '../../utils/challengeTypes';
|
2016-05-11 23:45:42 -07:00
|
|
|
|
|
|
|
export function encodeScriptTags(value) {
|
|
|
|
return value
|
|
|
|
.replace(/<script>/gi, 'fccss')
|
|
|
|
.replace(/<\/script>/gi, 'fcces');
|
|
|
|
}
|
|
|
|
|
|
|
|
export function decodeSafeTags(value) {
|
|
|
|
return value
|
|
|
|
.replace(/fccss/gi, '<script>')
|
|
|
|
.replace(/fcces/gi, '</script>');
|
|
|
|
}
|
|
|
|
|
|
|
|
export function encodeFormAction(value) {
|
|
|
|
return value.replace(
|
|
|
|
/<form[^>]*>/,
|
|
|
|
val => val.replace(/action(\s*?)=/, 'fccfaa$1=')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function decodeFccfaaAttr(value) {
|
|
|
|
return value.replace(
|
|
|
|
/<form[^>]*>/,
|
|
|
|
val => val.replace(/fccfaa(\s*?)=/, 'action$1=')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-05-14 16:46:20 -07:00
|
|
|
export function arrayToString(seedData = ['']) {
|
2016-05-11 23:45:42 -07:00
|
|
|
seedData = Array.isArray(seedData) ? seedData : [seedData];
|
|
|
|
return seedData.reduce((seed, line) => '' + seed + line + '\n', '\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
export function buildSeed({ challengeSeed = [] } = {}) {
|
|
|
|
return compose(
|
|
|
|
decodeSafeTags,
|
2016-05-14 16:46:20 -07:00
|
|
|
arrayToString
|
2016-05-11 23:45:42 -07:00
|
|
|
)(challengeSeed);
|
|
|
|
}
|
|
|
|
|
|
|
|
const pathsMap = {
|
2016-05-20 12:42:26 -07:00
|
|
|
[HTML]: 'html',
|
|
|
|
[JS]: 'js',
|
|
|
|
[BONFIRE]: 'js'
|
2016-05-11 23:45:42 -07:00
|
|
|
};
|
|
|
|
|
2016-05-20 12:42:26 -07:00
|
|
|
export function getPreFile({ challengeType }) {
|
|
|
|
return {
|
|
|
|
name: 'index',
|
|
|
|
ext: pathsMap[challengeType] || 'html',
|
|
|
|
key: getFileKey({ challengeType })
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getFileKey({ challengeType }) {
|
|
|
|
return 'index' + (pathsMap[challengeType] || 'html');
|
2016-05-11 23:45:42 -07:00
|
|
|
}
|
|
|
|
|
2016-05-13 20:04:56 -07:00
|
|
|
export function createTests({ tests = [] }) {
|
|
|
|
return tests
|
|
|
|
.map(test => ({
|
2016-05-25 18:28:20 -07:00
|
|
|
text: test.split('message: ').pop().replace(/\'\);/g, ''),
|
|
|
|
testString: test
|
2016-05-13 20:04:56 -07:00
|
|
|
}));
|
|
|
|
}
|