Fixed some issues in test files

This commit is contained in:
Angelos Chalaris
2018-06-18 19:07:48 +03:00
parent 1439ba9504
commit 977adb1198
31 changed files with 1390 additions and 2080 deletions

1357
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@ const URLJoin = (...args) =>
args args
.join('/') .join('/')
.replace(/[\/]+/g, '/') .replace(/[\/]+/g, '/')
.replace(/^(.+):\ .replace(/^(.+):\//, '$1://')
.replace(/^file:/, 'file:/') .replace(/^file:/, 'file:/')
.replace(/\/(\?|&|#[^!])/g, '$1') .replace(/\/(\?|&|#[^!])/g, '$1')
.replace(/\?/g, '&') .replace(/\?/g, '&')

View File

@ -5,7 +5,7 @@ cleanObj(obj[key], keysToKeep, childIndicator);
} else if (!keysToKeep.includes(key)) { } else if (!keysToKeep.includes(key)) {
delete obj[key]; delete obj[key];
} }
});
return obj; return obj;
}; };
module.exports = cleanObj; module.exports = cleanObj;

View File

@ -15,5 +15,5 @@ bgBlue: `\x1b[44m${args.join(' ')}\x1b[0m`,
bgMagenta: `\x1b[45m${args.join(' ')}\x1b[0m`, bgMagenta: `\x1b[45m${args.join(' ')}\x1b[0m`,
bgCyan: `\x1b[46m${args.join(' ')}\x1b[0m`, bgCyan: `\x1b[46m${args.join(' ')}\x1b[0m`,
bgWhite: `\x1b[47m${args.join(' ')}\x1b[0m` bgWhite: `\x1b[47m${args.join(' ')}\x1b[0m`
});
module.exports = colorize; module.exports = colorize;

View File

@ -2,5 +2,5 @@ const countBy = (arr, fn) =>
arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val, i) => { arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val, i) => {
acc[val] = (acc[val] || 0) + 1; acc[val] = (acc[val] || 0) + 1;
return acc; return acc;
}, { }, {});
module.exports = countBy; module.exports = countBy;

View File

@ -11,5 +11,5 @@ off(event, handler) {
const i = (this.hub[event] || []).findIndex(h => h === handler); const i = (this.hub[event] || []).findIndex(h => h === handler);
if (i > -1) this.hub[event].splice(i, 1); if (i > -1) this.hub[event].splice(i, 1);
} }
});
module.exports = createEventHub; module.exports = createEventHub;

View File

@ -4,5 +4,5 @@ const pre = prefix.length ? prefix + '.' : '';
if (typeof obj[k] === 'object') Object.assign(acc, flattenObject(obj[k], pre + k)); if (typeof obj[k] === 'object') Object.assign(acc, flattenObject(obj[k], pre + k));
else acc[pre + k] = obj[k]; else acc[pre + k] = obj[k];
return acc; return acc;
}, { }, {});
module.exports = flattenObject; module.exports = flattenObject;

View File

@ -1,5 +1,5 @@
const getScrollPosition = (el = window) => ({ const getScrollPosition = (el = window) => ({
x: el.pageXOffset !== undefined ? el.pageXOffset : el.scrollLeft, x: el.pageXOffset !== undefined ? el.pageXOffset : el.scrollLeft,
y: el.pageYOffset !== undefined ? el.pageYOffset : el.scrollTop y: el.pageYOffset !== undefined ? el.pageYOffset : el.scrollTop
});
module.exports = getScrollPosition; module.exports = getScrollPosition;

View File

@ -2,5 +2,5 @@ const groupBy = (arr, fn) =>
arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val, i) => { arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val, i) => {
acc[val] = (acc[val] || []).concat(arr[i]); acc[val] = (acc[val] || []).concat(arr[i]);
return acc; return acc;
}, { }, {});
module.exports = groupBy; module.exports = groupBy;

View File

@ -5,5 +5,5 @@ view = new DataView(h);
for (let i = 0; i < view.byteLength; i += 4) for (let i = 0; i < view.byteLength; i += 4)
hexes.push(('00000000' + view.getUint32(i).toString(16)).slice(-8)); hexes.push(('00000000' + view.getUint32(i).toString(16)).slice(-8));
return hexes.join(''); return hexes.join('');
});
module.exports = hashBrowser; module.exports = hashBrowser;

View File

@ -1,4 +1,4 @@
const httpsRedirect = () => { const httpsRedirect = () => {
if (location.protocol !== 'https:') location.replace('https: if (location.protocol !== 'https:') location.replace('https://' + location.href.split('//')[1]);
}; };
module.exports = httpsRedirect; module.exports = httpsRedirect;

View File

@ -4,5 +4,5 @@ const val = fn ? fn(obj[key]) : obj[key];
acc[val] = acc[val] || []; acc[val] = acc[val] || [];
acc[val].push(key); acc[val].push(key);
return acc; return acc;
}, { }, {});
module.exports = invertKeyValues; module.exports = invertKeyValues;

View File

@ -2,5 +2,5 @@ const lowercaseKeys = obj =>
Object.keys(obj).reduce((acc, key) => { Object.keys(obj).reduce((acc, key) => {
acc[key.toLowerCase()] = obj[key]; acc[key.toLowerCase()] = obj[key];
return acc; return acc;
}, { }, {});
module.exports = lowercaseKeys; module.exports = lowercaseKeys;

View File

@ -2,5 +2,5 @@ const mapKeys = (obj, fn) =>
Object.keys(obj).reduce((acc, k) => { Object.keys(obj).reduce((acc, k) => {
acc[fn(obj[k], k, obj)] = obj[k]; acc[fn(obj[k], k, obj)] = obj[k];
return acc; return acc;
}, { }, {});
module.exports = mapKeys; module.exports = mapKeys;

View File

@ -2,5 +2,5 @@ const mapValues = (obj, fn) =>
Object.keys(obj).reduce((acc, k) => { Object.keys(obj).reduce((acc, k) => {
acc[k] = fn(obj[k], k, obj); acc[k] = fn(obj[k], k, obj);
return acc; return acc;
}, { }, {});
module.exports = mapValues; module.exports = mapValues;

View File

@ -3,7 +3,7 @@ const times = fns.map(fn => {
const before = performance.now(); const before = performance.now();
for (let i = 0; i < iterations; i++) fn(); for (let i = 0; i < iterations; i++) fn();
return performance.now() - before; return performance.now() - before;
});
return times.indexOf(Math.min(...times)); return times.indexOf(Math.min(...times));
}; };
module.exports = mostPerformant; module.exports = mostPerformant;

View File

@ -1,2 +1,2 @@
const objectFromPairs = arr => arr.reduce((a, v) => ((a[v[0]] = v[1]), a), { const objectFromPairs = arr => arr.reduce((a, v) => ((a[v[0]] = v[1]), a), {});
module.exports = objectFromPairs; module.exports = objectFromPairs;

View File

@ -1,5 +1,5 @@
const omit = (obj, arr) => const omit = (obj, arr) =>
Object.keys(obj) Object.keys(obj)
.filter(k => !arr.includes(k)) .filter(k => !arr.includes(k))
.reduce((acc, key) => ((acc[key] = obj[key]), acc), { .reduce((acc, key) => ((acc[key] = obj[key]), acc), {});
module.exports = omit; module.exports = omit;

View File

@ -1,5 +1,5 @@
const omitBy = (obj, fn) => const omitBy = (obj, fn) =>
Object.keys(obj) Object.keys(obj)
.filter(k => !fn(obj[k], k)) .filter(k => !fn(obj[k], k))
.reduce((acc, key) => ((acc[key] = obj[key]), acc), { .reduce((acc, key) => ((acc[key] = obj[key]), acc), {});
module.exports = omitBy; module.exports = omitBy;

View File

@ -10,6 +10,6 @@ lastTime = now;
document.addEventListener('touchstart', () => { document.addEventListener('touchstart', () => {
if (type === 'touch') return; if (type === 'touch') return;
(type = 'touch'), callback(type), document.addEventListener('mousemove', mousemoveHandler); (type = 'touch'), callback(type), document.addEventListener('mousemove', mousemoveHandler);
});
}; };
module.exports = onUserInputChange; module.exports = onUserInputChange;

View File

@ -5,5 +5,5 @@ str
.reduce((acc, v) => { .reduce((acc, v) => {
acc[decodeURIComponent(v[0].trim())] = decodeURIComponent(v[1].trim()); acc[decodeURIComponent(v[0].trim())] = decodeURIComponent(v[1].trim());
return acc; return acc;
}, { }, {});
module.exports = parseCookie; module.exports = parseCookie;

View File

@ -1,3 +1,3 @@
const pick = (obj, arr) => const pick = (obj, arr) =>
arr.reduce((acc, curr) => (curr in obj && (acc[curr] = obj[curr]), acc), { arr.reduce((acc, curr) => (curr in obj && (acc[curr] = obj[curr]), acc), {});
module.exports = pick; module.exports = pick;

View File

@ -1,5 +1,5 @@
const pickBy = (obj, fn) => const pickBy = (obj, fn) =>
Object.keys(obj) Object.keys(obj)
.filter(k => fn(obj[k], k)) .filter(k => fn(obj[k], k))
.reduce((acc, key) => ((acc[key] = obj[key]), acc), { .reduce((acc, key) => ((acc[key] = obj[key]), acc), {});
module.exports = pickBy; module.exports = pickBy;

View File

@ -13,7 +13,7 @@ const run = () => {
raf = requestAnimationFrame(() => { raf = requestAnimationFrame(() => {
callback(); callback();
if (running) run(); if (running) run();
});
}; };
if (autoStart) start(); if (autoStart) start();
return { start, stop }; return { start, stop };

View File

@ -11,6 +11,6 @@ res(data), worker.terminate();
worker.onerror = err => { worker.onerror = err => {
rej(err), worker.terminate(); rej(err), worker.terminate();
}; };
});
}; };
module.exports = runAsync; module.exports = runAsync;

View File

@ -1,5 +1,5 @@
const smoothScroll = element => const smoothScroll = element =>
document.querySelector(element).scrollIntoView({ document.querySelector(element).scrollIntoView({
behavior: 'smooth' behavior: 'smooth'
});
module.exports = smoothScroll; module.exports = smoothScroll;

View File

@ -22,7 +22,7 @@ stack.push(OPERATORS[symbol](parseFloat(b), parseFloat(a)));
} else { } else {
throw `${symbol} is not a recognized symbol`; throw `${symbol} is not a recognized symbol`;
} }
});
if (stack.length === 1) return stack.pop(); if (stack.length === 1) return stack.pop();
else throw `${rpn} is not a proper RPN. Please check it and try again`; else throw `${rpn} is not a proper RPN. Please check it and try again`;
}; };

File diff suppressed because it is too large Load Diff

View File

@ -13,5 +13,5 @@ obj[k] +
); );
} else acc[k] = obj[k]; } else acc[k] = obj[k];
return acc; return acc;
}, { }, {});
module.exports = unflattenObject; module.exports = unflattenObject;

View File

@ -2,6 +2,6 @@ const zip = (...arrays) => {
const maxLength = Math.max(...arrays.map(x => x.length)); const maxLength = Math.max(...arrays.map(x => x.length));
return Array.from({ length: maxLength }).map((_, i) => { return Array.from({ length: maxLength }).map((_, i) => {
return Array.from({ length: arrays.length }, (_, k) => arrays[k][i]); return Array.from({ length: arrays.length }, (_, k) => arrays[k][i]);
});
}; };
module.exports = zip; module.exports = zip;

View File

@ -1,3 +1,3 @@
const zipObject = (props, values) => const zipObject = (props, values) =>
props.reduce((obj, prop, index) => ((obj[prop] = values[index]), obj), { props.reduce((obj, prop, index) => ((obj[prop] = values[index]), obj), {});
module.exports = zipObject; module.exports = zipObject;