Generalize part objects/arrays, add combination shorthands, update docs

This commit is contained in:
Bán Dénes 2020-10-17 19:05:38 +02:00
parent 5b1da540ac
commit d60c9dbc94
5 changed files with 104 additions and 134 deletions

View file

@ -162,4 +162,24 @@ const inherit = exports.inherit = (name_prefix, name, set) => {
result = extend.apply(this, list)
}
return result
}
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.op_str = (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
}