@betagouv/aides-velo
Advanced tools
Comparing version
import { | ||
publicodes_build_default | ||
} from "../chunk-COFCYNYW.js"; | ||
} from "../chunk-KJEEOVEF.js"; | ||
import "../chunk-MLKGABMK.js"; | ||
@@ -5,0 +5,0 @@ export { |
@@ -574,2 +574,12 @@ import * as Engine from 'publicodes'; | ||
/** | ||
* Set the situation of the engine. This will update the Publicodes situation | ||
* with the given situation. | ||
* | ||
* @param situation The situation to set. | ||
* @returns The instance of the engine with the updated situation. | ||
* | ||
* @note This is a low-level method prefer using {@link setInputs} instead. | ||
*/ | ||
setSituation(situation: Situation): this; | ||
/** | ||
* Filter the available aids by the given country. | ||
@@ -605,2 +615,10 @@ * | ||
/** | ||
* Get the options of a question by its name, if it has any. | ||
* | ||
* @param name The name of the question to get the options of. | ||
* @returns The list of options or `undefined` if the question doesn't have | ||
* any. | ||
*/ | ||
getOptions<T extends keyof Questions>(name: T): Questions[T][] | undefined; | ||
/** | ||
* Format the description of an aid by replacing the placeholders with the | ||
@@ -667,2 +685,2 @@ * evaluated values. | ||
export { type Aide, AideRuleNames, AidesVeloEngine, Commune, Localisation, LocalisationHelper, type Questions, type RuleName, rules, slugify }; | ||
export { type Aide, AideRuleNames, AidesVeloEngine, Commune, Localisation, LocalisationHelper, type Questions, type RuleName, type Situation, rules, slugify }; |
import { | ||
publicodes_build_default | ||
} from "../chunk-COFCYNYW.js"; | ||
} from "../chunk-KJEEOVEF.js"; | ||
import { | ||
@@ -10,5 +10,21 @@ data_exports | ||
// src/lib/utils.ts | ||
import { reduceAST } from "publicodes"; | ||
function slugify(str) { | ||
return str.normalize("NFKD").replace(/[\u0300-\u036f]/g, "").trim().replace("\u0153", "oe").toLowerCase().replace(/[^a-z0-9 -]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-"); | ||
} | ||
function extractOptions(rule) { | ||
return reduceAST( | ||
(_, node) => { | ||
if (node.nodeKind === "une possibilit\xE9") { | ||
return node.explanation.map((e) => { | ||
if (e.nodeKind === "reference") { | ||
return e.name; | ||
} | ||
}).filter(Boolean); | ||
} | ||
}, | ||
void 0, | ||
rule | ||
); | ||
} | ||
@@ -54,2 +70,15 @@ // src/lib/AidesVeloEngine.ts | ||
/** | ||
* Set the situation of the engine. This will update the Publicodes situation | ||
* with the given situation. | ||
* | ||
* @param situation The situation to set. | ||
* @returns The instance of the engine with the updated situation. | ||
* | ||
* @note This is a low-level method prefer using {@link setInputs} instead. | ||
*/ | ||
setSituation(situation) { | ||
this.engine.setSituation(situation); | ||
return this; | ||
} | ||
/** | ||
* Filter the available aids by the given country. | ||
@@ -130,2 +159,12 @@ * | ||
/** | ||
* Get the options of a question by its name, if it has any. | ||
* | ||
* @param name The name of the question to get the options of. | ||
* @returns The list of options or `undefined` if the question doesn't have | ||
* any. | ||
*/ | ||
getOptions(name) { | ||
return extractOptions(this.engine.getRule(name)); | ||
} | ||
/** | ||
* Format the description of an aid by replacing the placeholders with the | ||
@@ -132,0 +171,0 @@ * evaluated values. |
{ | ||
"name": "@betagouv/aides-velo", | ||
"description": "Modèle Publicodes pour le calcul des aides vélo en France", | ||
"version": "0.1.0-10", | ||
"version": "0.1.0-11", | ||
"author": "Emile Rolley <emile.rolley@beta.gouv.fr>", | ||
@@ -6,0 +6,0 @@ "license": "Apache-2.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
14257790
0.03%10002
0.96%