Refactor, units, tests

This commit is contained in:
Bán Dénes 2021-01-01 00:50:04 +01:00
parent 519c34bc60
commit cd90705ba1
24 changed files with 1221 additions and 1222 deletions

19
src/operation.js Normal file
View file

@ -0,0 +1,19 @@
const op_prefix = exports.op_prefix = str => {
const suffix = str.slice(1)
if (str.startsWith('+')) return {name: suffix, operation: 'add'}
if (str.startsWith('-')) return {name: suffix, operation: 'subtract'}
if (str.startsWith('~')) return {name: suffix, operation: 'intersect'}
if (str.startsWith('^')) return {name: suffix, operation: 'stack'}
return {name: str, operation: 'add'}
}
exports.operation = (str, choices={}, order=Object.keys(choices)) => {
let res = op_prefix(str)
for (const key of order) {
if (choices[key].includes(res.name)) {
res.type = key
break
}
}
return res
}