mon-entreprise/source/engine/rules.js

26 lines
629 B
JavaScript
Raw Normal View History

2016-12-07 18:08:10 +00:00
import rules from './load-rules'
import possibleVariableTypes from './possibleVariableTypes.yaml'
export let findRuleByName = search =>
2016-12-07 18:08:10 +00:00
rules
.map(extractRuleTypeAndName)
.find( ({name}) =>
name === search
2016-12-07 18:08:10 +00:00
)
export let searchRules = searchInput =>
rules
.filter( rule =>
rule && hasKnownRuleType(rule) &&
JSON.stringify(rule).indexOf(searchInput) > -1)
.map(extractRuleTypeAndName)
export let extractRuleTypeAndName = rule => {
let type = possibleVariableTypes.find(t => rule[t])
return {type, name: rule[type], rule}
2016-12-07 18:08:10 +00:00
}
export let hasKnownRuleType = rule => rule && extractRuleTypeAndName(rule).type