2021-06-25 11:50:49 +03:00
|
|
|
# Javascript French Law Library
|
2021-03-18 18:41:55 +03:00
|
|
|
|
2021-06-25 11:50:49 +03:00
|
|
|
This folder contains a ready-to-use Javascript library featuring French public
|
|
|
|
algorithms coded up in Catala.
|
2021-03-18 18:41:55 +03:00
|
|
|
|
2021-06-25 11:50:49 +03:00
|
|
|
## Generating the source files
|
|
|
|
|
|
|
|
The JS code is extracted from OCaml using
|
|
|
|
[`js_of_ocaml`](https://ocsigen.org/js_of_ocaml/). See the
|
|
|
|
[dedicated README](../ocaml/README.md) of the OCaml library for more precisions
|
2022-07-22 13:34:46 +03:00
|
|
|
about the OCaml code.
|
|
|
|
|
|
|
|
The wrapping between OCaml and JS is done by the generated
|
|
|
|
`../ocaml/law_source/<filename>_api_web.ml` modules.
|
2021-06-25 11:50:49 +03:00
|
|
|
|
|
|
|
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
|
|
|
|
```
|
|
|
|
|
2022-05-20 13:20:50 +03:00
|
|
|
## API description
|
|
|
|
|
2022-07-22 13:34:46 +03:00
|
|
|
The `french_law.js` library exposes:
|
2022-05-20 13:20:50 +03:00
|
|
|
|
2022-07-22 13:34:46 +03:00
|
|
|
- an [event manager](#the-event-manager)
|
|
|
|
- a list of [API functions](#api-functions)
|
|
|
|
- a list of fully exposed [sub-libraries](#sub-libraries)
|
2022-05-20 13:20:50 +03:00
|
|
|
|
2022-07-22 13:34:46 +03:00
|
|
|
### The event manager
|
2022-05-20 13:20:50 +03:00
|
|
|
|
2022-07-22 13:34:46 +03:00
|
|
|
A JavaScript object `eventsManager` is exposed with three callable methods:
|
2022-05-20 13:20:50 +03:00
|
|
|
|
|
|
|
```javascript
|
2022-07-22 13:34:46 +03:00
|
|
|
var frenchLaw = require("french_law.js");
|
2022-05-20 13:20:50 +03:00
|
|
|
|
2022-07-22 13:34:46 +03:00
|
|
|
// Clears the raw log event array.
|
|
|
|
frenchLaw.eventsManager.resetLog(0);
|
2022-05-20 13:20:50 +03:00
|
|
|
|
2022-07-22 13:34:46 +03:00
|
|
|
// Returns the current content of the raw log event array.
|
|
|
|
let rawEvents = frenchLaw.eventsManager.retrieveRawEvents(0)
|
2022-05-20 13:20:50 +03:00
|
|
|
|
2022-07-22 13:34:46 +03:00
|
|
|
// Returns the event array parsed from the current content of the raw log event array.
|
|
|
|
let events = frenchLaw.eventsManager.retrieveEvents(0)
|
2022-05-20 13:20:50 +03:00
|
|
|
```
|
|
|
|
|
2022-07-22 13:34:46 +03:00
|
|
|
> **Important**: you need to give an arbitrary value as argument.
|
2022-05-20 13:20:50 +03:00
|
|
|
|
2022-07-29 14:40:43 +03:00
|
|
|
### Date and time
|
|
|
|
|
|
|
|
Date values are encoded to JS string according the [ISO8601
|
|
|
|
format](https://www.iso.org/iso-8601-date-and-time-format.html): 'YYYY-MM-DD'.
|
|
|
|
|
2022-07-22 13:34:46 +03:00
|
|
|
### API functions
|
2022-05-20 13:20:50 +03:00
|
|
|
|
2022-07-22 13:34:46 +03:00
|
|
|
The `french_law.js` library exposes for each Catala program available in
|
|
|
|
`../ocaml/law_source/` a function to call in order to run the corresponding
|
|
|
|
encoded algorithm.
|
2022-05-20 13:20:50 +03:00
|
|
|
|
2022-07-22 13:34:46 +03:00
|
|
|
#### Available algorithms
|
2022-05-20 13:20:50 +03:00
|
|
|
|
2022-07-22 13:34:46 +03:00
|
|
|
##### Allocations familiales
|
2021-06-25 11:50:49 +03:00
|
|
|
|
2022-07-22 13:34:46 +03:00
|
|
|
The function is `computeAllocationsFamiliales`. This computation
|
2021-03-18 18:41:55 +03:00
|
|
|
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:
|
|
|
|
|
|
|
|
```javascript
|
2022-07-22 13:34:46 +03:00
|
|
|
var frenchLaw = require("french_law.js");
|
|
|
|
|
|
|
|
let amount = frenchLaw.computeAllocationsFamiliales({
|
2022-07-29 14:40:43 +03:00
|
|
|
iDateCouranteIn: "2020-04-20",
|
|
|
|
iEnfantsIn: [
|
2021-03-18 18:41:55 +03:00
|
|
|
{
|
2022-07-22 13:34:46 +03:00
|
|
|
dIdentifiant: 0,
|
2022-07-29 14:40:43 +03:00
|
|
|
dRemunerationMensuelle: 0,
|
|
|
|
dDateDeNaissance: "2003-02-02",
|
|
|
|
dPriseEnCharge: { kind: "EffectiveEtPermanente", payload: null },
|
2022-07-22 13:34:46 +03:00
|
|
|
dADejaOuvertDroitAuxAllocationsFamiliales: true,
|
|
|
|
dBeneficieTitrePersonnelAidePersonnelleLogement: false,
|
2021-03-18 18:41:55 +03:00
|
|
|
},
|
|
|
|
{
|
2022-07-22 13:34:46 +03:00
|
|
|
dIdentifiant: 1,
|
2022-07-29 14:40:43 +03:00
|
|
|
dRemunerationMensuelle: 300,
|
|
|
|
dDateDeNaissance: "2013-09-30",
|
|
|
|
dPriseEnCharge: {
|
|
|
|
kind: "GardeAlterneePartageAllocations",
|
|
|
|
payload: null,
|
|
|
|
},
|
2022-07-22 13:34:46 +03:00
|
|
|
dADejaOuvertDroitAuxAllocationsFamiliales: true,
|
|
|
|
dBeneficieTitrePersonnelAidePersonnelleLogement: false,
|
2021-03-18 18:41:55 +03:00
|
|
|
},
|
|
|
|
],
|
2022-07-29 14:40:43 +03:00
|
|
|
iRessourcesMenageIn: 30000,
|
|
|
|
iResidenceIn: { kind: "Metropole", payload: null },
|
2022-07-22 13:34:46 +03:00
|
|
|
iPersonneChargeEffectivePermanenteEstParentIn: true,
|
|
|
|
iPersonneChargeEffectivePermanenteRemplitTitreIIn: true,
|
2022-07-29 14:40:43 +03:00
|
|
|
iAvaitEnfantAChargeAvant1erJanvier2012In: false,
|
2021-03-18 18:41:55 +03:00
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-07-22 13:34:46 +03:00
|
|
|
Notably, the `dPriseEnCharge` variable for each child expects a value among:
|
|
|
|
- "GardeAlterneePartageAllocations"
|
|
|
|
- "GardeAlterneeAllocataireUnique"
|
|
|
|
- "EffectiveEtPermanente"
|
|
|
|
- "ServicesSociauxAllocationVerseeALaFamille"
|
|
|
|
- "ServicesSociauxAllocationVerseeAuxServicesSociaux"
|
2021-03-18 18:41:55 +03:00
|
|
|
|
2022-07-22 13:34:46 +03:00
|
|
|
> See `../ocaml/law_source/allocations_familiales_api_web.ml` for more
|
|
|
|
> information about data types.
|
|
|
|
|
2022-07-29 14:40:43 +03:00
|
|
|
##### Aides logement
|
|
|
|
|
|
|
|
> TODO: add information about `aides_logement_api_web.ml`.
|
|
|
|
|
2022-07-22 13:34:46 +03:00
|
|
|
### Sub libraries
|
|
|
|
|
|
|
|
All declared types and scopes of a Catala program are available in JavaScript
|
|
|
|
via the following sub libs:
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
var frenchLaw = require("french_law.js");
|
|
|
|
|
|
|
|
// Allocations familiales
|
|
|
|
// corresponding to the file: `../ocaml/law_source/allocations_familiales_api_web.ml
|
|
|
|
var allocationsFamiliales = frenchLaw.AllocationsFamilialesLib
|
2022-07-29 14:40:43 +03:00
|
|
|
|
|
|
|
// APL
|
|
|
|
// corresponding to the file: `../ocaml/law_source/aides_logement_api_web.ml
|
|
|
|
var aidesLogement = frenchLaw.AidesLogementLib
|
2022-07-22 13:34:46 +03:00
|
|
|
```
|