catala/french_law/js
2022-05-25 14:26:58 +02:00
..
.gitignore Big renaming and dir reorg 2021-06-21 11:39:06 +02:00
allocations_familiales.js Added other field 2022-01-07 09:47:10 +01:00
french_law.js refactor(api_web/runtime): runtime_value derive yojson_of 2022-05-25 14:26:58 +02:00
Makefile Install JS dependencies correctly 2021-06-21 11:54:56 +02:00
package-lock.json Revert "Merge pull request #196 from CatalaLang/fixup-cmdliner" 2022-02-21 14:53:48 +01:00
package.json Bump Catala version number 2021-11-07 01:38:17 +01:00
README.md refactor(api_web/runtime): runtime_value derive yojson_of 2022-05-25 14:26:58 +02:00

Javascript French Law Library

This folder contains a ready-to-use Javascript library featuring French public algorithms coded up in Catala.

Generating the source files

The JS code is extracted from OCaml using js_of_ocaml. See the dedicated README of the OCaml library for more precisions about the OCaml code. The wrapping between OCaml and JS is done by the api_web.ml module.

You can generate the french_law.js source JS module by invoking this command from the root of the repository:

make build_french_law_library_js

API description

API content

Data types

source_position

Stores information about the log position.

{
  fileName : string
  startLine : int
  endLine : int
  startColumn : int
  endColumn : int
  lawHeadings : [string]
 }

log_event

Stores information about one log event.

{
  eventType : string
  information : [string]
  sourcePosition : source_position?
  loggedValueJson : string
}

loggedValueJson is the resulting string representation of the Runtime.runtime_value serialization via yojson -- see ./src/compiler/runtime.mli.

Functions

french_law.resetLog()

Clears the log array.

Example of use:

french_law.resetLog(0) // Note that you have to pass an arbitrary argument.

french_law.retrieveLog()

Returns the array of log_event resulting of the computation of the algorithms.

Example of use:

let logs = french_law.retrieveLog(0) // Note that you have to pass an arbitrary argument.

Available algorithms

Allocations familiales

The function of the library is computeAllocationsFamiliales. This computation returns the amount of allocations familiales for one household described by the input. More precisely, the result returned is the sum of:

  • la base des allocations familiales
  • l'allocation forfaitaire relai pour dépassement de l'âge limite
  • la majoration pour âge
  • le complément dégressif en cas de dépassement du plafond de revenus

An example of use:

Law.computeAllocationsFamiliales({
  currentDate: new Date("2020-05-20"),
  children: [
    {
      id: 0,
      remunerationMensuelle: 0,
      dateNaissance: new Date("2003-03-02"),
      priseEnCharge: "Effective et permanente",
      aDejaOuvertDroitAuxAllocationsFamiliales: true,
    },
    {
      id: 1,
      remunerationMensuelle: 300,
      dateNaissance: new Date("2013-10-30"),
      priseEnCharge: "Garde alternée, partage des allocations",
      aDejaOuvertDroitAuxAllocationsFamiliales: true,
    },
  ],
  income: 30000,
  residence: "Métropole",
  personneQuiAssumeLaChargeEffectivePermanenteEstParent: true,
  personneQuiAssumeLaChargeEffectivePermanenteRemplitConditionsTitreISecuriteSociale: true,
});

Notably, the priseEnCharge variable for each child expects a value among:

  • "Effective et permanente"
  • "Garde alternée, allocataire unique"
  • "Garde alternée, partage des allocations"
  • "Confié aux service sociaux, allocation versée à la famille"
  • "Confié aux service sociaux, allocation versée aux services sociaux"