Skip to content
Snippets Groups Projects
Select Git revision
  • cfa2b4a5d0fa4355f18177bfc69e9925b52aa5cb
  • master default protected
  • doc-script-gen-off-tests
  • 366-signe-a-cote-du-droit-en-vigueur-sur-l-ui-pour-indiquer-que-la-reforme-a-eu-lieu-mais-qu-elle-n
  • revalo_retraites
  • 381-pb-affichage-labels-des-parametres-sur-plus-de-3-lignes
  • ajoute-duplicate-aide-logement
  • poc_castype_ia
  • parametres-editables-budget
  • ui-parametres
  • 355-les-dispositifs-prestations-sociales-du-graphique-se-cachent-montrent-en-meme-temps-2
  • 358-les-variables-dont-le-montant-est-nul-apparaissent-en-bleu-et-non-cliquables
  • 356-ajuster-la-largeur-sur-les-graphiques-budgetaires
  • incoherence_cas_type_0
  • fix-ui-suppression-tranches-baremes
  • ajout-agregat-cehr-version-plf
  • impact_carbone
  • xlsx
  • header_revamp
  • 270-concevoir-la-page-d-accueil-leximpact
  • 219-conversion-des-montants-min-et-max-de-l-axe-des-x-en-smic
  • 0.0.1177
  • 0.0.1176
  • 0.0.1175
  • 0.0.1174
  • 0.0.1173
  • 0.0.1172
  • 0.0.1171
  • 0.0.1170
  • 0.0.1169
  • 0.0.1168
  • 0.0.1167
  • 0.0.1166
  • 0.0.1165
  • 0.0.1164
  • 0.0.1163
  • 0.0.1162
  • 0.0.1161
  • 0.0.1160
  • 0.0.1159
  • 0.0.1158
41 results

svelte.config.js

Blame
  • units.ts 1.85 KiB
    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-ignore
    import unitsUnknown from "@leximpact/socio-fiscal-openfisca-json/units.yaml"
    import {
      getUnitAtDate as getUnitAtDateOriginal,
      getUnitLabel as getUnitLabelOriginal,
      getUnitShortLabel as getUnitShortLabelOriginal,
      type ConstantUnit,
      type PeriodUnit,
      type Unit,
    } from "@openfisca/json-model"
    
    const frenchPluralRules = new Intl.PluralRules(["fr-FR"])
    export const units = unitsUnknown as Unit[]
    const unitByName = Object.fromEntries(units.map((unit) => [unit.name, unit]))
    
    export function getUnitAtDate(
      name: string | undefined | null,
      date: string,
    ): ConstantUnit | undefined {
      return getUnitAtDateOriginal(unitByName, name, date)
    }
    
    export function getUnitByName(
      name: string | undefined | null,
    ): Unit | undefined {
      if (name === undefined || name === null) {
        return undefined
      }
      return unitByName[name]
    }
    
    export function getUnitLabel(
      name: string | undefined | null,
      date: string,
      { periodUnit, value = 123 }: { periodUnit?: PeriodUnit; value?: number } = {},
    ): string {
      const unitLabel = getUnitLabelOriginal(
        unitByName,
        name,
        date,
        frenchPluralRules.select(value ?? 0),
      )
      if (
        unitLabel === "" ||
        periodUnit === undefined ||
        !["day", "month", "year"].includes(periodUnit)
      ) {
        return unitLabel
      }
      return `${unitLabel}/an`
    }
    
    export function getUnitShortLabel(
      name: string | undefined | null,
      date: string,
      { periodUnit, value = 123 }: { periodUnit?: PeriodUnit; value?: number } = {},
    ): string {
      const unitShortLabel = getUnitShortLabelOriginal(
        unitByName,
        name,
        date,
        frenchPluralRules.select(value ?? 0),
      )
      if (
        unitShortLabel === "" ||
        periodUnit === undefined ||
        !["day", "month", "year"].includes(periodUnit)
      ) {
        return unitShortLabel
      }
      return `${unitShortLabel}/an`
    }