frontello-datas-format
Advanced tools
Comparing version 1.2.2 to 1.2.3
@@ -62,88 +62,85 @@ "use strict"; | ||
{ | ||
if (!this.isGrdf() | ||
&& !this.isElectriciteStrasbourg()) { | ||
return false; | ||
if (this._isStandard()) { | ||
return true; | ||
} | ||
if (this._checkFormats()) { | ||
return true; | ||
} | ||
return true; | ||
return false; | ||
} | ||
isGrdf() | ||
_checkFormats() | ||
{ | ||
if (/^GI[0-9]{6}$/.test(this.pce)) { | ||
const formats = this._getFormats(); | ||
for (let i = 0; i < formats.length; i++) { | ||
let format = formats[i]; | ||
if (!format) { | ||
continue; | ||
} | ||
if (!this.pce.match(format)) { | ||
continue; | ||
} | ||
return true; | ||
} | ||
if (!/^[0-9]{14}$/.test(this.pce)) { | ||
return false; | ||
} | ||
_isStandard() | ||
{ | ||
// Comporte 14 chiffres | ||
if (!/^\d{14}$/.test(this.pce)) { | ||
return false; | ||
} | ||
var pceGrdfIsValid = function(pce) { | ||
// Comporte 14 chiffres | ||
// Son préfix correspond à Grdf : 000 à 599 ou 900 à 999 | ||
let Cp1 = parseInt(pce.charAt(0)); | ||
let Cp2 = parseInt(pce.charAt(1)); | ||
let Cp3 = parseInt(pce.charAt(2)); | ||
if (Cp1 > 5 && Cp1 < 9) { | ||
return false; | ||
} | ||
let Cp = parseInt(pce.substring(0, 3)); | ||
if (Cp > 599 && Cp < 900) { | ||
return false; | ||
} | ||
// Identifiant | ||
let Ci1 = parseInt(pce.charAt(3)); | ||
let Ci2 = parseInt(pce.charAt(4)); | ||
let Ci3 = parseInt(pce.charAt(5)); | ||
let Ci4 = parseInt(pce.charAt(6)); | ||
let Ci5 = parseInt(pce.charAt(7)); | ||
let Ci6 = parseInt(pce.charAt(8)); | ||
let Ci7 = parseInt(pce.charAt(9)); | ||
let Ci8 = parseInt(pce.charAt(10)); | ||
let Ci9 = parseInt(pce.charAt(11)); | ||
// Clé de contrôle | ||
let Cc1 = parseInt(pce.charAt(12)); | ||
let Cc2 = parseInt(pce.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; | ||
// Son préfix | ||
let Cp = parseInt(this.pce.substring(0, 3)); | ||
// Identifiant | ||
let Ci1 = parseInt(this.pce.charAt(3)); | ||
let Ci2 = parseInt(this.pce.charAt(4)); | ||
let Ci3 = parseInt(this.pce.charAt(5)); | ||
let Ci4 = parseInt(this.pce.charAt(6)); | ||
let Ci5 = parseInt(this.pce.charAt(7)); | ||
let Ci6 = parseInt(this.pce.charAt(8)); | ||
let Ci7 = parseInt(this.pce.charAt(9)); | ||
let Ci8 = parseInt(this.pce.charAt(10)); | ||
let Ci9 = parseInt(this.pce.charAt(11)); | ||
// Clé de contrôle | ||
let Cc1 = parseInt(this.pce.charAt(12)); | ||
let Cc2 = parseInt(this.pce.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 (!pceGrdfIsValid(this.pce)) { | ||
if (!(resultatCc1 == Cc1 && resultatCc2 == Cc2)) { | ||
return false; | ||
@@ -154,13 +151,21 @@ } | ||
} | ||
isElectriciteStrasbourg() | ||
_getFormats() | ||
{ | ||
// Ex. : 29997630 | ||
if (!/^\d{8}$/.test(this.pce)) { | ||
return false; | ||
} | ||
const FormatGrdf = /^GI[0-9]{6}$/; // standard + 3300029208 ou 35000090164 | ||
const FormatGedia = /^(\d{12}\/)?(\d{5}GC\d{1})$/; // 27856GC1 ou 032036517323/56725GC1 | ||
const FormatGeg = /^\d{5,6}$/; // 45543 ou 126271 | ||
const FormatRegazBordeaux = /^\d{6}$/; // 123456 | ||
const FormatRegieMontdidier = /^(GZ\/\d{5}\/\d{6})$/; // GZ/12345/123456 | ||
const FormatReseauGazNaturelStrasbourg = /^\d{8}$/; // 29997630 | ||
return true; | ||
return [ | ||
FormatGrdf, | ||
FormatGedia, | ||
FormatGeg, | ||
FormatRegazBordeaux, | ||
FormatRegieMontdidier, | ||
FormatReseauGazNaturelStrasbourg, | ||
]; | ||
} | ||
} |
@@ -48,40 +48,36 @@ "use strict"; | ||
{ | ||
if (!this.isEnalp() | ||
&& !this.isEnedis() | ||
&& !this.isElectriciteStrasbourg()) { | ||
return false; | ||
if (this._isStandard()) { | ||
return true; | ||
} | ||
if (this._checkFormats()) { | ||
return true; | ||
} | ||
return true; | ||
return false; | ||
} | ||
isEnalp() | ||
_checkFormats() | ||
{ | ||
// Ex. : 82400168400099 | ||
const formats = this._getFormats(); | ||
for (let i = 0; i < formats.length; i++) { | ||
let format = formats[i]; | ||
return this._isStandard(false); | ||
} | ||
isEnedis() | ||
{ | ||
// Ex. : 00000000005515 | ||
return this._isStandard(true); | ||
} | ||
isElectriciteStrasbourg() | ||
{ | ||
// Ex. : 67124/E2/8008221 | ||
if (!format) { | ||
continue; | ||
} | ||
if (!/^\d{5}\/\w{1}\d{1}\/\d{7}$/.test(this.prm)) { | ||
return false; | ||
if (!this.prm.match(format)) { | ||
continue; | ||
} | ||
return true; | ||
} | ||
return true; | ||
return false; | ||
} | ||
_isStandard(estEnedis) | ||
_isStandard(estEnedis = false) | ||
{ | ||
// Comporte 14 chiffres | ||
if (!/^[0-9]{14}$/.test(this.prm)) { | ||
if (!/^\d{14}$/.test(this.prm)) { | ||
return false; | ||
@@ -147,2 +143,55 @@ } | ||
} | ||
_getFormats() | ||
{ | ||
const FormatCesml = /^\d{10,11}$/; // 3300029208 ou 35000090164 | ||
const FormatEdsb = null; // standard | ||
const FormatEnalp = null; // standard | ||
const FormatEnedis = null; // standard | ||
const FormatEnergiesServicesLavaur = null; // standard | ||
const FormatStrasbourgElectriciteReseaux = /^\d{5}\/\w{1}\d{1}\/\d{6,8}$/; // 12345/A1/123456, 12345/A1/1234567 ou 12345/A1/12345678 | ||
const FormatGedia = /^(\d{12})|(\d{5}EC\d{1})$/; // 27856EC1 ou 032036517323 | ||
const FormatGeg = /^\d{5,6}$/; // 45543 ou 126271 | ||
const FormatGeredis = /^(\d{3}EC\d{1})|(\d{5,6})|(\d{8})|(\d{11})|(\d{13})|(BT\/\d{5}\/\d{6})$/; // 123EC1, 12345, 123456, 12345678, 12345678901, 1234567890123, BT/12345/123456 | ||
const FormatGreenAlp = /^(\d{5,6}EC\d{1})$/; // standard / 12345EC1 ou 123456EC1 | ||
const FormatRegieBonneville = /^(\d{6}EC\d{1})|(\d{12})$/; // 123456EC1 ou 123456789012 | ||
const FormatRegieGignac = null; // standard | ||
const FormatRegieStMartinDeLondres = null; // standard | ||
const FormatRegieThones = null; // standard | ||
const FormatRegieTignes = null; // standard | ||
const FormatRegieMunicipaleMazeres = null; // standard | ||
const FormatRegieElectriqueCommunaleSaverdun = null; // standard | ||
const FormatRse = null; // standard | ||
const FormatSeolis = /^(\d{5,6})|(\d{12})$/; // standard / 12345, 123456 ou 123456789012 | ||
const FormatSicae = null; // standard | ||
const FormatSorea = null; // standard | ||
const FormatSrd = /^(\d{12})|(\d{15})$/; // standard / 123456789012 ou 123456789012345 | ||
const FormatUem = null; // standard | ||
return [ | ||
FormatCesml, | ||
FormatEdsb, | ||
FormatEnalp, | ||
FormatEnedis, | ||
FormatEnergiesServicesLavaur, | ||
FormatStrasbourgElectriciteReseaux, | ||
FormatGedia, | ||
FormatGeg, | ||
FormatGeredis, | ||
FormatGreenAlp, | ||
FormatRegieBonneville, | ||
FormatRegieGignac, | ||
FormatRegieStMartinDeLondres, | ||
FormatRegieThones, | ||
FormatRegieTignes, | ||
FormatRegieMunicipaleMazeres, | ||
FormatRegieElectriqueCommunaleSaverdun, | ||
FormatRse, | ||
FormatSeolis, | ||
FormatSicae, | ||
FormatSorea, | ||
FormatSrd, | ||
FormatUem, | ||
]; | ||
} | ||
} |
{ | ||
"name": "frontello-datas-format", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "UI format", | ||
@@ -5,0 +5,0 @@ "main": "format.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
21052
836