La librairie prend la notation pointée en entrée

pull/699/head
Mael 2019-10-02 17:43:15 +02:00 committed by Maël
parent 7676707e6f
commit 0eba339309
3 changed files with 7 additions and 12 deletions

View File

@ -1,7 +1,7 @@
{
"name": "mon-entreprise",
"license": "MIT",
"version": "1.2.1",
"version": "1.2.2",
"description": "Library to compute the french social security contributions. Also a website that explains the calculations, and a generic engine to build cool forms that asks the question needed to compute an objective.",
"main": "./dist/engine.js",
"files": [

View File

@ -1,25 +1,20 @@
// This file exports the functions of the public computing library
import { safeLoad } from 'js-yaml'
import {
collectDefaults,
enrichRule,
nestedSituationToPathMap,
rulesFr
} from './rules'
import { collectDefaults, enrichRule, rulesFr } from './rules'
import { analyseMany, parseAll } from './traverse.js'
// The public evaluation function takes a nested object of input values
let nestedSituationToStateSelector = rules => nestedSituation => dottedName =>
let inputToStateSelector = rules => input => dottedName =>
({
...collectDefaults(rules),
...nestedSituationToPathMap(nestedSituation)
...input
}[dottedName])
let enrichRules = input =>
(typeof input === 'string' ? safeLoad(input) : input).map(enrichRule)
export default {
evaluate: (targetInput, nestedSituation, config) => {
evaluate: (targetInput, input, config) => {
let rules = config
? [
...(config.base ? enrichRules(config.base) : rulesFr),
@ -30,7 +25,7 @@ export default {
let evaluation = analyseMany(
parseAll(rules),
Array.isArray(targetInput) ? targetInput : [targetInput]
)(nestedSituationToStateSelector(rules)(nestedSituation))
)(inputToStateSelector(rules)(input))
if (config?.debug) return evaluation
let values = evaluation.targets.map(t => t.nodeValue)

View File

@ -7,7 +7,7 @@ describe('library', function() {
it('should evaluate one target with no input data', function() {
let target = 'contrat salarié . rémunération . net'
let value = Lib.evaluate(target, {
'contrat salarié': { rémunération: { 'brut de base': 2300 } }
'contrat salarié . rémunération . brut de base': 2300
})
expect(value).to.be.within(1798, 1800)
})