frontello-datas-format
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -19,3 +19,3 @@ "use strict"; | ||
{ | ||
if (this.isEnedis()) { | ||
if (this._isStandard(false)) { | ||
return this.getPrettierEnedis(); | ||
@@ -49,3 +49,4 @@ } | ||
{ | ||
if (!this.isEnedis() | ||
if (!this.isEnalp() | ||
&& !this.isEnedis() | ||
&& !this.isElectriciteStrasbourg()) { | ||
@@ -58,4 +59,30 @@ return false; | ||
isEnalp() | ||
{ | ||
// Ex. : 82400168400099 | ||
return this._isStandard(false); | ||
} | ||
isEnedis() | ||
{ | ||
// Ex. : 00000000005515 | ||
return this._isStandard(true); | ||
} | ||
isElectriciteStrasbourg() | ||
{ | ||
// Ex. : 67124/E2/8008221 | ||
if (!/^\d{5}\/\w{1}\d{1}\/\d{7}$/.test(this.prm)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
_isStandard(estEnedis) | ||
{ | ||
// Comporte 14 chiffres | ||
if (!/^[0-9]{14}$/.test(this.prm)) { | ||
@@ -65,86 +92,59 @@ return false; | ||
var prmEnedisIsValid = function(prm) { | ||
// Comporte 14 chiffres | ||
// Son préfix correspond à Enedis : 000 à 599 ou 900 à 999 | ||
if (estEnedis) { | ||
let Cp = parseInt(this.prm.substring(0, 3)); | ||
// Son préfix correspond à Enedis : 000 à 599 ou 900 à 999 | ||
let Cp1 = parseInt(prm.charAt(0)); | ||
let Cp2 = parseInt(prm.charAt(1)); | ||
let Cp3 = parseInt(prm.charAt(2)); | ||
if (Cp1 > 5 && Cp1 < 9) { | ||
return false; | ||
} | ||
let Cp = parseInt(prm.substring(0, 3)); | ||
if (Cp > 599 && Cp < 900) { | ||
return false; | ||
} | ||
// Identifiant | ||
let Ci1 = parseInt(prm.charAt(3)); | ||
let Ci2 = parseInt(prm.charAt(4)); | ||
let Ci3 = parseInt(prm.charAt(5)); | ||
let Ci4 = parseInt(prm.charAt(6)); | ||
let Ci5 = parseInt(prm.charAt(7)); | ||
let Ci6 = parseInt(prm.charAt(8)); | ||
let Ci7 = parseInt(prm.charAt(9)); | ||
let Ci8 = parseInt(prm.charAt(10)); | ||
let Ci9 = parseInt(prm.charAt(11)); | ||
// Clé de contrôle | ||
let Cc1 = parseInt(prm.charAt(12)); | ||
let Cc2 = parseInt(prm.charAt(13)); | ||
// Vérification de la clé de contrôle | ||
let N1 = Ci1 + Ci2 + Ci3 + Ci4 + Ci5 + Ci6 + Ci7 + Ci8 + Ci9 + 2; | ||
let resultatCc1 = N1 % 11; | ||
let N2 = 2 + 2 * Ci9 + 3 * Ci8 + 4 * Ci7 + 5 * Ci6 + 6 * Ci5 + 7 * Ci4 + 8 * Ci3 + 9 * Ci2 + 10 * Ci1; | ||
let resultatCc2 = N2 % 11; | ||
// Cas particuliers | ||
if (resultatCc1 == 10 && resultatCc2 == 10) { | ||
resultatCc1 = 9; | ||
resultatCc2 = 9; | ||
} | ||
else if (resultatCc1 == 10 && resultatCc2 == 0) { | ||
resultatCc1 = 9; | ||
resultatCc2 = 8; | ||
} | ||
else if (resultatCc1 == 10 && resultatCc2 != 0) { | ||
resultatCc1 = 0; | ||
} | ||
else if (resultatCc1 == 0 && resultatCc2 == 10) { | ||
resultatCc1 = 8; | ||
resultatCc2 = 9; | ||
} | ||
else if (resultatCc1 != 0 && resultatCc2 == 10) { | ||
resultatCc2 = 0; | ||
} | ||
if (!(resultatCc1 == Cc1 && resultatCc2 == Cc2)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
if (!prmEnedisIsValid(this.prm)) { | ||
return false; | ||
// Identifiant | ||
let Ci1 = parseInt(this.prm.charAt(3)); | ||
let Ci2 = parseInt(this.prm.charAt(4)); | ||
let Ci3 = parseInt(this.prm.charAt(5)); | ||
let Ci4 = parseInt(this.prm.charAt(6)); | ||
let Ci5 = parseInt(this.prm.charAt(7)); | ||
let Ci6 = parseInt(this.prm.charAt(8)); | ||
let Ci7 = parseInt(this.prm.charAt(9)); | ||
let Ci8 = parseInt(this.prm.charAt(10)); | ||
let Ci9 = parseInt(this.prm.charAt(11)); | ||
// Clé de contrôle | ||
let Cc1 = parseInt(this.prm.charAt(12)); | ||
let Cc2 = parseInt(this.prm.charAt(13)); | ||
// Vérification de la clé de contrôle | ||
let N1 = Ci1 + Ci2 + Ci3 + Ci4 + Ci5 + Ci6 + Ci7 + Ci8 + Ci9 + 2; | ||
let resultatCc1 = N1 % 11; | ||
let N2 = 2 + 2 * Ci9 + 3 * Ci8 + 4 * Ci7 + 5 * Ci6 + 6 * Ci5 + 7 * Ci4 + 8 * Ci3 + 9 * Ci2 + 10 * Ci1; | ||
let resultatCc2 = N2 % 11; | ||
// Cas particuliers | ||
if (resultatCc1 == 10 && resultatCc2 == 10) { | ||
resultatCc1 = 9; | ||
resultatCc2 = 9; | ||
} | ||
else if (resultatCc1 == 10 && resultatCc2 == 0) { | ||
resultatCc1 = 9; | ||
resultatCc2 = 8; | ||
} | ||
else if (resultatCc1 == 10 && resultatCc2 != 0) { | ||
resultatCc1 = 0; | ||
} | ||
else if (resultatCc1 == 0 && resultatCc2 == 10) { | ||
resultatCc1 = 8; | ||
resultatCc2 = 9; | ||
} | ||
else if (resultatCc1 != 0 && resultatCc2 == 10) { | ||
resultatCc2 = 0; | ||
} | ||
return true; | ||
} | ||
isElectriciteStrasbourg() | ||
{ | ||
// Ex. : 67124/E2/8008221 | ||
if (!/^\d{5}\/\w{1}\d{1}\/\d{7}$/.test(this.prm)) { | ||
if (!(resultatCc1 == Cc1 && resultatCc2 == Cc2)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
{ | ||
"name": "frontello-datas-format", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "UI format", | ||
@@ -5,0 +5,0 @@ "main": "format.js", |
779
18773