mirror of
https://github.com/TECHNOFAB11/ergogen.git
synced 2025-12-12 16:10:04 +01:00
19 lines
667 B
JavaScript
19 lines
667 B
JavaScript
|
|
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
|
||
|
|
}
|