mirror of
https://github.com/TECHNOFAB11/ergogen.git
synced 2025-12-12 08:00:06 +01:00
25 lines
No EOL
715 B
JavaScript
25 lines
No EOL
715 B
JavaScript
const op_prefix = exports.op_prefix = str => {
|
|
|
|
const prefix = str[0]
|
|
const suffix = str.slice(1)
|
|
const result = {name: suffix, operation: 'add'}
|
|
|
|
if (prefix == '+') ; // noop
|
|
else if (prefix == '-') result.operation = 'subtract'
|
|
else if (prefix == '~') result.operation = 'intersect'
|
|
else if (prefix == '^') result.operation = 'stack'
|
|
else result.name = str // no prefix, so the name was the whole string
|
|
|
|
return result
|
|
}
|
|
|
|
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.what = key
|
|
break
|
|
}
|
|
}
|
|
return res
|
|
} |