@agencebio/rosetta-cultures
Advanced tools
Comparing version 1.8.2 to 1.8.3
@@ -90,6 +90,19 @@ "use strict"; | ||
if (precision === void 0) { precision = null; } | ||
if (precision) { | ||
var cleanedPrecision_1 = String(precision).padStart(3, '0'); | ||
var results = cpf_json_1.default.filter(function (_a) { | ||
var cultures_pac = _a.cultures_pac; | ||
return cultures_pac.some(function (culture) { | ||
return culture.code === code && culture.precision === cleanedPrecision_1; | ||
}); | ||
}); | ||
if (results.length) { | ||
return results; | ||
} | ||
} | ||
// otherwise, and in any case, we lookup results without precision | ||
return cpf_json_1.default.filter(function (_a) { | ||
var cultures_pac = _a.cultures_pac; | ||
return cultures_pac.some(function (culture) { | ||
return culture.code === code && culture.precision === (precision ? String(precision).padStart(3, '0') : ''); | ||
return culture.code === code && culture.precision === ''; | ||
}); | ||
@@ -96,0 +109,0 @@ }); |
18
index.js
@@ -82,5 +82,20 @@ /** | ||
export function fromCodePacAll (code, precision = null) { | ||
if (precision) { | ||
const cleanedPrecision = String(precision).padStart(3, '0') | ||
const results = cpf.filter(({ cultures_pac }) => { | ||
return cultures_pac.some(culture => { | ||
return culture.code === code && culture.precision === cleanedPrecision | ||
}) | ||
}) | ||
if (results.length) { | ||
return results | ||
} | ||
} | ||
// otherwise, and in any case, we lookup results without precision | ||
return cpf.filter(({ cultures_pac }) => { | ||
return cultures_pac.some(culture => { | ||
return culture.code === code && culture.precision === (precision ? String(precision).padStart(3, '0') : '') | ||
return culture.code === code && culture.precision === '' | ||
}) | ||
@@ -91,3 +106,2 @@ }) | ||
/** | ||
@@ -94,0 +108,0 @@ * @param {String} code |
@@ -90,2 +90,7 @@ import { describe, it } from 'node:test' | ||
deepEqual(fromCodePacFirst('VRG', '002').code_cpf, "01.25.31") // Amandes | ||
// inexisting precision falls back to regular code | ||
deepEqual(fromCodePacFirst('BTH', '001'), fromCodePacFirst('BTH')) // Blé tendre d’hiver | ||
// digit version = string version | ||
deepEqual(fromCodePacFirst('VRG', 1), fromCodePacFirst('VRG', '001')) // Abricots | ||
@@ -133,2 +138,7 @@ deepEqual(fromCodePacFirst('VRG', 2), fromCodePacFirst('VRG', '002')) // Amandes | ||
deepEqual( | ||
fromCodePacAll('VRG', '002').map(({ code_cpf }) => code_cpf), | ||
['01.25.31'] | ||
) | ||
deepEqual( | ||
fromCodePacAll('VRG', '003').map(({ code_cpf }) => code_cpf), | ||
@@ -135,0 +145,0 @@ ['01.24.10.1', '01.24.10.2'] |
{ | ||
"name": "@agencebio/rosetta-cultures", | ||
"version": "1.8.2", | ||
"version": "1.8.3", | ||
"description": "Traduction des codes cultures de la CPF vers la PAC vers des nomenclatures d'organismes de certification, et vice-versa.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2704932
91112