Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
OpenFisca-JSON-Model
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
leximpact
Simulateur socio-fiscal
Adaptations OpenFisca
OpenFisca-JSON-Model
Commits
1b17f282
Commit
1b17f282
authored
Jul 17, 2023
by
Emmanuel Raviart
Browse files
Options
Downloads
Patches
Plain Diff
Synchronize units with tax-benefit
parent
fb6922ef
No related branches found
No related tags found
No related merge requests found
Pipeline
#9478
failed
Jul 17, 2023
Stage: build
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
packages/lib/src/auditors/units.ts
+16
-0
16 additions, 0 deletions
packages/lib/src/auditors/units.ts
packages/lib/src/index.ts
+2
-2
2 additions, 2 deletions
packages/lib/src/index.ts
packages/lib/src/units.ts
+17
-14
17 additions, 14 deletions
packages/lib/src/units.ts
with
35 additions
and
16 deletions
packages/lib/src/auditors/units.ts
+
16
−
0
View file @
1b17f282
...
...
@@ -90,6 +90,22 @@ function auditUnit(audit: Audit, dataUnknown: unknown): [unknown, unknown] {
if
(
data
.
units
==
undefined
)
{
auditConstantUnitContent
(
audit
,
data
,
errors
,
remainingKeys
)
}
else
{
for
(
const
key
of
[
"
label
"
,
"
short_label
"
])
{
audit
.
attribute
(
data
,
key
,
true
,
errors
,
remainingKeys
,
auditSwitch
(
auditString
,
auditKeyValueDictionary
(
auditOptions
([...
pluralizationCategories
]),
[
auditString
,
auditRequire
,
]),
),
)
}
audit
.
attribute
(
data
,
"
name
"
,
...
...
This diff is collapsed.
Click to expand it.
packages/lib/src/index.ts
+
2
−
2
View file @
1b17f282
...
...
@@ -127,9 +127,9 @@ export {
getUnitAtDate
,
getUnitLabel
,
getUnitShortLabel
,
labelFro
nConstant
Unit
,
labelFro
m
Unit
,
pluralizationCategories
,
shortLabelFro
nConstant
Unit
,
shortLabelFro
m
Unit
,
type
ChangingUnit
,
type
ConstantUnit
,
type
PluralizationCategory
,
...
...
This diff is collapsed.
Click to expand it.
packages/lib/src/units.ts
+
17
−
14
View file @
1b17f282
...
...
@@ -3,10 +3,8 @@ export interface ChangingUnit extends UnitBase {
}
export
interface
ConstantUnit
extends
UnitBase
{
label
?:
StringByPluralizationCategory
|
string
/// Name of parameter containing the values of the unit
parameter
?:
string
short_label
?:
StringByPluralizationCategory
|
string
units
?:
undefined
}
...
...
@@ -29,15 +27,17 @@ export type StringByPluralizationCategory = {
export
type
Unit
=
ChangingUnit
|
ConstantUnit
export
interface
UnitBase
{
label
?:
StringByPluralizationCategory
|
string
name
:
string
short_label
?:
StringByPluralizationCategory
|
string
units
?:
{
[
date
:
string
]:
ConstantUnit
}
|
undefined
}
export
function
getUnitAtDate
(
unitByName
:
{
[
name
:
string
]:
Unit
},
name
:
string
|
undefined
|
null
,
date
:
string
,
):
Constant
Unit
|
undefined
{
date
:
string
|
undefined
|
null
,
):
Unit
|
undefined
{
if
(
name
==
null
)
{
return
undefined
}
...
...
@@ -45,6 +45,9 @@ export function getUnitAtDate(
if
(
unit
===
undefined
)
{
return
undefined
}
if
(
date
==
null
)
{
return
unit
}
if
(
unit
.
units
!==
undefined
)
{
unit
=
Object
.
entries
(
unit
.
units
)
.
sort
(([
startDate1
],
[
startDate2
])
=>
...
...
@@ -61,31 +64,31 @@ export function getUnitAtDate(
export
function
getUnitLabel
(
unitByName
:
{
[
name
:
string
]:
Unit
},
name
:
string
|
undefined
|
null
,
date
:
string
,
date
:
string
|
undefined
|
null
,
pluralizationCategory
:
PluralizationCategory
,
):
string
{
const
unit
=
getUnitAtDate
(
unitByName
,
name
,
date
)
if
(
unit
===
undefined
)
{
return
name
??
""
}
return
labelFro
nConstant
Unit
(
unit
,
pluralizationCategory
)
return
labelFro
m
Unit
(
unit
,
pluralizationCategory
)
}
export
function
getUnitShortLabel
(
unitByName
:
{
[
name
:
string
]:
Unit
},
name
:
string
|
undefined
|
null
,
date
:
string
,
date
:
string
|
undefined
|
null
,
pluralizationCategory
:
PluralizationCategory
,
):
string
{
const
unit
=
getUnitAtDate
(
unitByName
,
name
,
date
)
if
(
unit
===
undefined
)
{
return
name
??
""
}
return
shortLabelFro
nConstant
Unit
(
unit
,
pluralizationCategory
)
return
shortLabelFro
m
Unit
(
unit
,
pluralizationCategory
)
}
export
function
labelFro
nConstant
Unit
(
unit
:
Constant
Unit
,
export
function
labelFro
m
Unit
(
unit
:
Unit
,
pluralizationCategory
:
PluralizationCategory
,
):
string
{
const
label
=
unit
.
label
...
...
@@ -96,15 +99,15 @@ export function labelFronConstantUnit(
:
label
[
pluralizationCategory
]
??
unit
.
name
}
export
function
shortLabelFro
nConstant
Unit
(
unit
:
Constant
Unit
,
export
function
shortLabelFro
m
Unit
(
unit
:
Unit
,
pluralizationCategory
:
PluralizationCategory
,
):
string
{
const
shortLabel
=
unit
.
short_label
return
shortLabel
===
undefined
?
labelFro
nConstant
Unit
(
unit
,
pluralizationCategory
)
?
labelFro
m
Unit
(
unit
,
pluralizationCategory
)
:
typeof
shortLabel
===
"
string
"
?
shortLabel
:
shortLabel
[
pluralizationCategory
]
??
labelFro
nConstant
Unit
(
unit
,
pluralizationCategory
)
labelFro
m
Unit
(
unit
,
pluralizationCategory
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment