Skip to content
Snippets Groups Projects
Commit c6422e79 authored by Millicent Billette's avatar Millicent Billette
Browse files

v3.5.8

FIX: dictionary-parser no more create duplicate with variable qty operator. example: "A{0,5}"
parent 7631b7a4
No related branches found
No related tags found
No related merge requests found
Pipeline #18407 passed with warnings
......@@ -14,6 +14,10 @@ et ce projet adhère au [versionnage sémantique](https://semver.org/spec/v2.0.0
## [Non-publié/Non-Stabilisé] (par [1000i100])
## [Version 3.5.8] - 2023-01-12 (par [1000i100])
### Corrections
- dictionary-parser ne génère plus de doublon superflu lorsque des quantités variables sont indiquées ( comme "A{0,5}" par exemple)
## [Version 3.5.7] - 2023-01-01 (par [1000i100])
### Corrections
- dictionary-tree ne supprime plus les alternatives vides ce qui permet d'avoir le comportement attendu avec des chaines comme "(|a)".
......
{
"name": "g1lib",
"version": "3.5.7",
"version": "3.5.8",
"description": "An ubiquitous static javascript toolbox lib for Ǧ1 / Duniter ecosystem with reliability in mind.",
"main": "nodejs/all.mjs",
"browser": "browser/all.mjs",
......
......@@ -209,11 +209,16 @@ function bracketsHandler(theString) {
return theString;
}
function qtyHandlerReplaceCallback(all, chr, qty) {
const mm = qty.split(',').map(n => n.trim() * 1); // eslint-disable-line no-implicit-coercion
const mm = qty.split(',').map(n => parseInt(n.trim()));
const min = mm[0];
const max = (mm.length === 2) ? mm[1] : min;
let result = new Array(min + 1).join(chr);// eslint-disable-line unicorn/no-new-array
for (let i = min; i < max; i++) result += `(|${chr})`;
if(isNaN(min) || isNaN(max)) throw `Error, invalid quantity : ${qty}`;
let result = chr.repeat(min);
if(max>min){
result+='(';
for (let i = 0; i <= max-min; i++) result += `|${chr.repeat(i)}`;
result+=')';
}
return result;
}
function qtyHandler(theString) {
......
......@@ -34,10 +34,10 @@ test('parse handle {qty}', t => {
t.is(app.parse('a{5}',{idSecPwd:false}), 'aaaaa');
});
test('parse handle {min,max}', t => {
t.is(app.parse('b{3,5}',{idSecPwd:false}), 'bbb(|b)(|b)');
t.is(app.parse('b{3,5}',{idSecPwd:false}), 'bbb(|b|bb)');
});
test('parse handle (string){qty}', t => {
t.is(app.parse(`c'est (toto|tata){0,2}`,{idSecPwd:false}), `c'est (|tata|toto)(|tata|toto)`);
t.is(app.parse(`c'est (toto|tata){0,2}`,{idSecPwd:false}), `c'est ((tata|toto)(tata|toto)||tata|toto)`);
});
test('parse handle nested (s|t(ri|ng)){qty}', t => {
t.is(app.parse(`(s|t(ri|ng)){1,2}`,{idSecPwd:false}), `(t(ng|ri)|s)(t(ng|ri)||s)`);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment