validation-br 2.0.0-next-4 → 2.0.0-next-6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/_exceptions/ValidationBRError.d.ts +25 -0
- package/dist/src/_exceptions/ValidationBRError.d.ts.map +1 -0
- package/dist/src/_exceptions/ValidationBRError.js +52 -0
- package/dist/src/_exceptions/ValidationBRError.js.map +1 -0
- package/dist/src/_helpers/crc.d.ts +8 -0
- package/dist/src/_helpers/crc.d.ts.map +1 -0
- package/dist/src/_helpers/crc.js +49 -0
- package/dist/src/_helpers/crc.js.map +1 -0
- package/dist/src/_helpers/crockford.d.ts +32 -0
- package/dist/src/_helpers/crockford.d.ts.map +1 -0
- package/dist/src/_helpers/crockford.js +63 -0
- package/dist/src/_helpers/crockford.js.map +1 -0
- package/dist/src/_helpers/mask.d.ts +19 -0
- package/dist/src/_helpers/mask.d.ts.map +1 -0
- package/dist/src/_helpers/mask.js +39 -0
- package/dist/src/_helpers/mask.js.map +1 -0
- package/dist/src/_helpers/random.d.ts +28 -0
- package/dist/src/_helpers/random.d.ts.map +1 -0
- package/dist/src/_helpers/random.js +55 -0
- package/dist/src/_helpers/random.js.map +1 -0
- package/dist/src/_helpers/utils.d.ts +95 -0
- package/dist/src/_helpers/utils.d.ts.map +1 -0
- package/dist/src/_helpers/utils.js +128 -0
- package/dist/src/_helpers/utils.js.map +1 -0
- package/dist/src/base.d.ts +34 -0
- package/dist/src/base.d.ts.map +1 -0
- package/dist/src/base.js +51 -0
- package/dist/src/base.js.map +1 -0
- package/dist/src/carplate.d.ts +32 -0
- package/dist/src/carplate.d.ts.map +1 -0
- package/dist/src/carplate.js +71 -0
- package/dist/src/carplate.js.map +1 -0
- package/dist/src/cbi_sinter.d.ts +79 -0
- package/dist/src/cbi_sinter.d.ts.map +1 -0
- package/dist/src/cbi_sinter.js +124 -0
- package/dist/src/cbi_sinter.js.map +1 -0
- package/dist/src/cep.d.ts +62 -0
- package/dist/src/cep.d.ts.map +1 -0
- package/dist/src/cep.js +223 -0
- package/dist/src/cep.js.map +1 -0
- package/dist/src/certidao.d.ts +84 -0
- package/dist/src/certidao.d.ts.map +1 -0
- package/dist/src/certidao.js +131 -0
- package/dist/src/certidao.js.map +1 -0
- package/dist/src/cnh.d.ts +81 -0
- package/dist/src/cnh.d.ts.map +1 -0
- package/dist/src/cnh.js +129 -0
- package/dist/src/cnh.js.map +1 -0
- package/dist/src/cnpj.d.ts +108 -0
- package/dist/src/cnpj.d.ts.map +1 -0
- package/dist/src/cnpj.js +175 -0
- package/dist/src/cnpj.js.map +1 -0
- package/dist/src/cpf.d.ts +89 -0
- package/dist/src/cpf.d.ts.map +1 -0
- package/dist/src/cpf.js +138 -0
- package/dist/src/cpf.js.map +1 -0
- package/dist/src/email.d.ts +13 -0
- package/dist/src/email.d.ts.map +1 -0
- package/dist/src/email.js +45 -0
- package/dist/src/email.js.map +1 -0
- package/dist/src/judicial-process.d.ts +151 -0
- package/dist/src/judicial-process.d.ts.map +1 -0
- package/dist/src/judicial-process.js +298 -0
- package/dist/src/judicial-process.js.map +1 -0
- package/dist/src/main.d.ts +16 -0
- package/dist/src/main.d.ts.map +1 -0
- package/dist/src/main.js +57 -0
- package/dist/src/main.js.map +1 -0
- package/dist/src/nup17.d.ts +99 -0
- package/dist/src/nup17.d.ts.map +1 -0
- package/dist/src/nup17.js +156 -0
- package/dist/src/nup17.js.map +1 -0
- package/dist/src/phone.d.ts +104 -0
- package/dist/src/phone.d.ts.map +1 -0
- package/dist/src/phone.js +204 -0
- package/dist/src/phone.js.map +1 -0
- package/dist/src/pis-pasep.d.ts +71 -0
- package/dist/src/pis-pasep.d.ts.map +1 -0
- package/dist/src/pis-pasep.js +117 -0
- package/dist/src/pis-pasep.js.map +1 -0
- package/dist/src/pix-copy-paste.d.ts +27 -0
- package/dist/src/pix-copy-paste.d.ts.map +1 -0
- package/dist/src/pix-copy-paste.js +84 -0
- package/dist/src/pix-copy-paste.js.map +1 -0
- package/dist/src/pix-key.d.ts +30 -0
- package/dist/src/pix-key.d.ts.map +1 -0
- package/dist/src/pix-key.js +90 -0
- package/dist/src/pix-key.js.map +1 -0
- package/dist/src/postal-track-code.d.ts +77 -0
- package/dist/src/postal-track-code.d.ts.map +1 -0
- package/dist/src/postal-track-code.js +130 -0
- package/dist/src/postal-track-code.js.map +1 -0
- package/dist/src/renavam.d.ts +32 -0
- package/dist/src/renavam.d.ts.map +1 -0
- package/dist/src/renavam.js +114 -0
- package/dist/src/renavam.js.map +1 -0
- package/dist/src/tituloEleitor.d.ts +83 -0
- package/dist/src/tituloEleitor.d.ts.map +1 -0
- package/dist/src/tituloEleitor.js +168 -0
- package/dist/src/tituloEleitor.js.map +1 -0
- package/dist/src/uf.d.ts +90 -0
- package/dist/src/uf.d.ts.map +1 -0
- package/dist/src/uf.js +264 -0
- package/dist/src/uf.js.map +1 -0
- package/dist/src/uuid.d.ts +10 -0
- package/dist/src/uuid.d.ts.map +1 -0
- package/dist/src/uuid.js +35 -0
- package/dist/src/uuid.js.map +1 -0
- package/package.json +9 -8
- package/.prettierignore +0 -1
- package/.prettierrc +0 -9
- package/dist/jest.config.d.ts +0 -8
- package/dist/jest.config.d.ts.map +0 -1
- package/dist/jest.config.js +0 -154
- package/dist/jest.config.js.map +0 -1
- package/eslint.config.mjs +0 -11
- package/jest.config.ts +0 -210
- package/todo.md +0 -33
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export default class ValidationBRError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
export declare class InvalidChecksumException extends ValidationBRError {
|
|
5
|
+
constructor();
|
|
6
|
+
}
|
|
7
|
+
export declare class InvalidFormatException extends ValidationBRError {
|
|
8
|
+
constructor();
|
|
9
|
+
}
|
|
10
|
+
export declare class EmptyValueException extends ValidationBRError {
|
|
11
|
+
constructor();
|
|
12
|
+
}
|
|
13
|
+
export declare class TooLongException extends ValidationBRError {
|
|
14
|
+
constructor();
|
|
15
|
+
}
|
|
16
|
+
export declare class TooShortException extends ValidationBRError {
|
|
17
|
+
constructor();
|
|
18
|
+
}
|
|
19
|
+
export declare class RepeatedSequenceException extends ValidationBRError {
|
|
20
|
+
constructor();
|
|
21
|
+
}
|
|
22
|
+
export declare class NoChecksumException extends ValidationBRError {
|
|
23
|
+
constructor();
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=ValidationBRError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidationBRError.d.ts","sourceRoot":"","sources":["../../../src/_exceptions/ValidationBRError.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,KAAK;gBACtC,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,wBAAyB,SAAQ,iBAAiB;;CAI9D;AAED,qBAAa,sBAAuB,SAAQ,iBAAiB;;CAI5D;AAED,qBAAa,mBAAoB,SAAQ,iBAAiB;;CAIzD;AAED,qBAAa,gBAAiB,SAAQ,iBAAiB;;CAItD;AAED,qBAAa,iBAAkB,SAAQ,iBAAiB;;CAIvD;AAED,qBAAa,yBAA0B,SAAQ,iBAAiB;;CAI/D;AAED,qBAAa,mBAAoB,SAAQ,iBAAiB;;CAIzD"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NoChecksumException = exports.RepeatedSequenceException = exports.TooShortException = exports.TooLongException = exports.EmptyValueException = exports.InvalidFormatException = exports.InvalidChecksumException = void 0;
|
|
4
|
+
class ValidationBRError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.default = ValidationBRError;
|
|
10
|
+
class InvalidChecksumException extends ValidationBRError {
|
|
11
|
+
constructor() {
|
|
12
|
+
super('Dígito verificador inválido');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.InvalidChecksumException = InvalidChecksumException;
|
|
16
|
+
class InvalidFormatException extends ValidationBRError {
|
|
17
|
+
constructor() {
|
|
18
|
+
super('Formato inválido');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.InvalidFormatException = InvalidFormatException;
|
|
22
|
+
class EmptyValueException extends ValidationBRError {
|
|
23
|
+
constructor() {
|
|
24
|
+
super('Valor não preenchido');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.EmptyValueException = EmptyValueException;
|
|
28
|
+
class TooLongException extends ValidationBRError {
|
|
29
|
+
constructor() {
|
|
30
|
+
super('Número de caracteres excedido');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.TooLongException = TooLongException;
|
|
34
|
+
class TooShortException extends ValidationBRError {
|
|
35
|
+
constructor() {
|
|
36
|
+
super('Número de caracteres muito curto');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.TooShortException = TooShortException;
|
|
40
|
+
class RepeatedSequenceException extends ValidationBRError {
|
|
41
|
+
constructor() {
|
|
42
|
+
super('Sequência de números repetidos não permitida');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.RepeatedSequenceException = RepeatedSequenceException;
|
|
46
|
+
class NoChecksumException extends ValidationBRError {
|
|
47
|
+
constructor() {
|
|
48
|
+
super('Este objeto não possui dígito verificador');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.NoChecksumException = NoChecksumException;
|
|
52
|
+
//# sourceMappingURL=ValidationBRError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidationBRError.js","sourceRoot":"","sources":["../../../src/_exceptions/ValidationBRError.ts"],"names":[],"mappings":";;;AAAA,MAAqB,iBAAkB,SAAQ,KAAK;IAClD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;IAChB,CAAC;CACF;AAJD,oCAIC;AAED,MAAa,wBAAyB,SAAQ,iBAAiB;IAC7D;QACE,KAAK,CAAC,6BAA6B,CAAC,CAAC;IACvC,CAAC;CACF;AAJD,4DAIC;AAED,MAAa,sBAAuB,SAAQ,iBAAiB;IAC3D;QACE,KAAK,CAAC,kBAAkB,CAAC,CAAC;IAC5B,CAAC;CACF;AAJD,wDAIC;AAED,MAAa,mBAAoB,SAAQ,iBAAiB;IACxD;QACE,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAChC,CAAC;CACF;AAJD,kDAIC;AAED,MAAa,gBAAiB,SAAQ,iBAAiB;IACrD;QACE,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACzC,CAAC;CACF;AAJD,4CAIC;AAED,MAAa,iBAAkB,SAAQ,iBAAiB;IACtD;QACE,KAAK,CAAC,kCAAkC,CAAC,CAAC;IAC5C,CAAC;CACF;AAJD,8CAIC;AAED,MAAa,yBAA0B,SAAQ,iBAAiB;IAC9D;QACE,KAAK,CAAC,8CAA8C,CAAC,CAAC;IACxD,CAAC;CACF;AAJD,8DAIC;AAED,MAAa,mBAAoB,SAAQ,iBAAiB;IACxD;QACE,KAAK,CAAC,2CAA2C,CAAC,CAAC;IACrD,CAAC;CACF;AAJD,kDAIC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crc.d.ts","sourceRoot":"","sources":["../../../src/_helpers/crc.ts"],"names":[],"mappings":"AAAA,qBAAa,GAAG;IACF,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAElC,IAAI,KAAK,IAAI,MAAM,CAElB;IAGD,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,SAAI;IAKrC,SAAS,CAAC,MAAM,UAAQ;CAqCzB"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CRC = void 0;
|
|
4
|
+
class CRC {
|
|
5
|
+
_value;
|
|
6
|
+
constructor(_value) {
|
|
7
|
+
this._value = _value;
|
|
8
|
+
}
|
|
9
|
+
get value() {
|
|
10
|
+
return this._value;
|
|
11
|
+
}
|
|
12
|
+
// https://github.com/NascentSecureTech/pix-qrcode-utils/blob/01a072f458d63dea2376e631284085405fd8b027/packages/data-schemas/src/data-utils.ts#L9
|
|
13
|
+
static numToHex(n, digits = 4) {
|
|
14
|
+
const hex = n.toString(16).toUpperCase();
|
|
15
|
+
return ('0'.repeat(digits) + hex).slice(-digits);
|
|
16
|
+
}
|
|
17
|
+
calculate(invert = false) {
|
|
18
|
+
const bytes = new TextEncoder().encode(this._value);
|
|
19
|
+
const crcTable = [
|
|
20
|
+
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 0x1231, 0x0210, 0x3273,
|
|
21
|
+
0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7,
|
|
22
|
+
0x44a4, 0x5485, 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, 0xb75b,
|
|
23
|
+
0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, 0xc9cc, 0xd9ed, 0xe98e, 0xf9af,
|
|
24
|
+
0x8948, 0x9969, 0xa90a, 0xb92b, 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b,
|
|
25
|
+
0xab1a, 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, 0x7e97, 0x6eb6,
|
|
26
|
+
0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c,
|
|
27
|
+
0xc12d, 0xf14e, 0xe16f, 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
|
|
28
|
+
0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, 0x34e2, 0x24c3, 0x14a0,
|
|
29
|
+
0x0481, 0x7466, 0x6447, 0x5424, 0x4405, 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676,
|
|
30
|
+
0x4615, 0x5634, 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, 0xcb7d,
|
|
31
|
+
0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d,
|
|
32
|
+
0xbdaa, 0xad8b, 0x9de8, 0x8dc9, 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9,
|
|
33
|
+
0x9ff8, 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0,
|
|
34
|
+
];
|
|
35
|
+
let crc = 0xffff;
|
|
36
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
37
|
+
const c = bytes[i];
|
|
38
|
+
const j = (c ^ (crc >> 8)) & 0xff;
|
|
39
|
+
crc = crcTable[j] ^ (crc << 8);
|
|
40
|
+
}
|
|
41
|
+
const answer = (crc ^ 0) & 0xffff;
|
|
42
|
+
const hex = CRC.numToHex(answer, 4);
|
|
43
|
+
if (invert)
|
|
44
|
+
return hex.slice(2) + hex.slice(0, 2);
|
|
45
|
+
return hex;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.CRC = CRC;
|
|
49
|
+
//# sourceMappingURL=crc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crc.js","sourceRoot":"","sources":["../../../src/_helpers/crc.ts"],"names":[],"mappings":";;;AAAA,MAAa,GAAG;IACM;IAApB,YAAoB,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAI,CAAC;IAEvC,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,iJAAiJ;IACjJ,MAAM,CAAC,QAAQ,CAAC,CAAS,EAAE,MAAM,GAAG,CAAC;QACnC,MAAM,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;QACzC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC;IACnD,CAAC;IAED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AAG,MAAM,CAAC;QAElC,MAAM,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAEpC,IAAI,MAAM;YAAE,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAElD,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AAlDD,kBAkDC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare class Crockford {
|
|
2
|
+
private static readonly ALPHABET;
|
|
3
|
+
/**
|
|
4
|
+
* Normaliza a string conforme as regras do SINTER/CIB:
|
|
5
|
+
* 1. Remove pontuação e espaços
|
|
6
|
+
* 2. Converte para Maiúsculas
|
|
7
|
+
* 3. Substitui 'I' e 'L' por '1'
|
|
8
|
+
* 4. Substitui 'O' por '0'
|
|
9
|
+
* 5. Lança erro para o caractere proibido 'U'
|
|
10
|
+
*/
|
|
11
|
+
static normalize(value: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Converte um caractere alfanumérico para seu valor decimal (0-31)
|
|
14
|
+
*/
|
|
15
|
+
static charToInt(char: string): number;
|
|
16
|
+
/**
|
|
17
|
+
* Converte um valor numérico (0-31) para o caractere correspondente
|
|
18
|
+
*/
|
|
19
|
+
static intToChar(value: number): string;
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* Retorna o alfabeto utilizado
|
|
23
|
+
*/
|
|
24
|
+
static getAlphabet(): string;
|
|
25
|
+
static getAlphabet(options: {
|
|
26
|
+
returnArray: false;
|
|
27
|
+
}): string;
|
|
28
|
+
static getAlphabet(options: {
|
|
29
|
+
returnArray: true;
|
|
30
|
+
}): string[];
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=crockford.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crockford.d.ts","sourceRoot":"","sources":["../../../src/_helpers/crockford.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAS;IAEpB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAsC;IAEtE;;;;;;;OAOG;WACW,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAmB9C;;OAEG;WACW,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAiB7C;;OAEG;WACW,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAQ9C;;;OAGG;WACW,WAAW,IAAI,MAAM;WACrB,WAAW,CAAC,OAAO,EAAE;QAAE,WAAW,EAAE,KAAK,CAAA;KAAE,GAAG,MAAM;WACpD,WAAW,CAAC,OAAO,EAAE;QAAE,WAAW,EAAE,IAAI,CAAA;KAAE,GAAG,MAAM,EAAE;CAUpE"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Crockford = void 0;
|
|
4
|
+
class Crockford {
|
|
5
|
+
// Alfabeto Base 32 de Douglas Crockford (32 caracteres)
|
|
6
|
+
static ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
7
|
+
/**
|
|
8
|
+
* Normaliza a string conforme as regras do SINTER/CIB:
|
|
9
|
+
* 1. Remove pontuação e espaços
|
|
10
|
+
* 2. Converte para Maiúsculas
|
|
11
|
+
* 3. Substitui 'I' e 'L' por '1'
|
|
12
|
+
* 4. Substitui 'O' por '0'
|
|
13
|
+
* 5. Lança erro para o caractere proibido 'U'
|
|
14
|
+
*/
|
|
15
|
+
static normalize(value) {
|
|
16
|
+
if (!value)
|
|
17
|
+
return "";
|
|
18
|
+
let normalized = value
|
|
19
|
+
.toUpperCase()
|
|
20
|
+
.replace(/[-.\s]/g, ""); // Remove hífens, pontos e espaços
|
|
21
|
+
// Substituições de ambiguidade visual
|
|
22
|
+
normalized = normalized.replace(/[IL]/g, "1");
|
|
23
|
+
normalized = normalized.replace(/O/g, "0");
|
|
24
|
+
// Validação do caractere proibido
|
|
25
|
+
if (normalized.includes("U")) {
|
|
26
|
+
throw new Error("O caractere 'U' é proibido no padrão CIB/SINTER para evitar palavras obscenas.");
|
|
27
|
+
}
|
|
28
|
+
return normalized;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Converte um caractere alfanumérico para seu valor decimal (0-31)
|
|
32
|
+
*/
|
|
33
|
+
static charToInt(char) {
|
|
34
|
+
// Normaliza apenas o caractere para garantir que substituições (como 'i' -> '1') ocorram
|
|
35
|
+
const cleanChar = this.normalize(char);
|
|
36
|
+
if (cleanChar.length !== 1) {
|
|
37
|
+
throw new Error("Deve ser fornecido apenas um caractere.");
|
|
38
|
+
}
|
|
39
|
+
const index = this.ALPHABET.indexOf(cleanChar);
|
|
40
|
+
if (index === -1) {
|
|
41
|
+
throw new Error(`Caractere '${char}' não pertence ao alfabeto Crockford Base32.`);
|
|
42
|
+
}
|
|
43
|
+
return index;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Converte um valor numérico (0-31) para o caractere correspondente
|
|
47
|
+
*/
|
|
48
|
+
static intToChar(value) {
|
|
49
|
+
if (value < 0 || value > 31) {
|
|
50
|
+
throw new Error("O valor deve estar entre 0 e 31 para conversão em Base32.");
|
|
51
|
+
}
|
|
52
|
+
return this.ALPHABET[value];
|
|
53
|
+
}
|
|
54
|
+
static getAlphabet(options) {
|
|
55
|
+
const { returnArray = false } = options || {};
|
|
56
|
+
if (returnArray) {
|
|
57
|
+
return this.ALPHABET.split('');
|
|
58
|
+
}
|
|
59
|
+
return this.ALPHABET;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.Crockford = Crockford;
|
|
63
|
+
//# sourceMappingURL=crockford.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crockford.js","sourceRoot":"","sources":["../../../src/_helpers/crockford.ts"],"names":[],"mappings":";;;AAAA,MAAa,SAAS;IACpB,wDAAwD;I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CAAC,CAAC;QAC/E,CAAC;QAED,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IASM,MAAM,CAAC,WAAW,CAAC,OAA4B;QACpD,MAAM,EAAE,WAAW,GAAG,KAAK,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;QAE9C,IAAI,WAAW,EAAE,CAAC;YAChB,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACjC,CAAC;QAED,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;;AA7EH,8BA8EC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare class Mask {
|
|
2
|
+
private _value;
|
|
3
|
+
constructor(_value: string);
|
|
4
|
+
/**
|
|
5
|
+
* applyMask()
|
|
6
|
+
* Aplica uma máscara a uma string
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* applyMask('59650000', '00.000-000') // -> 59.650-000
|
|
10
|
+
* applyMask('99877665544', '(00) 0 0000-0000') // -> (99) 8 7766-5544
|
|
11
|
+
*
|
|
12
|
+
* @param {String|Number} value Valor original
|
|
13
|
+
* @param {String} mask
|
|
14
|
+
* @returns {String}
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
apply(mask: string): string;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=mask.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mask.d.ts","sourceRoot":"","sources":["../../../src/_helpers/mask.ts"],"names":[],"mappings":"AAEA,qBAAa,IAAI;IACH,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAElC;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CAgB5B"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Mask = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
class Mask {
|
|
6
|
+
_value;
|
|
7
|
+
constructor(_value) {
|
|
8
|
+
this._value = _value;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* applyMask()
|
|
12
|
+
* Aplica uma máscara a uma string
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* applyMask('59650000', '00.000-000') // -> 59.650-000
|
|
16
|
+
* applyMask('99877665544', '(00) 0 0000-0000') // -> (99) 8 7766-5544
|
|
17
|
+
*
|
|
18
|
+
* @param {String|Number} value Valor original
|
|
19
|
+
* @param {String} mask
|
|
20
|
+
* @returns {String}
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
apply(mask) {
|
|
24
|
+
const maskLen = (0, utils_1.clearValue)(mask).length;
|
|
25
|
+
let masked = (0, utils_1.clearValue)(this._value, maskLen, {
|
|
26
|
+
fillZerosAtLeft: true,
|
|
27
|
+
trimAtRight: true,
|
|
28
|
+
});
|
|
29
|
+
const specialChars = ['/', '-', '.', '(', ')', ' '];
|
|
30
|
+
for (let position = 0; position < mask.length; position += 1) {
|
|
31
|
+
const current = mask[position];
|
|
32
|
+
if (specialChars.includes(current))
|
|
33
|
+
masked = (0, utils_1.insertAtPosition)(masked, current, position);
|
|
34
|
+
}
|
|
35
|
+
return masked;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.Mask = Mask;
|
|
39
|
+
//# sourceMappingURL=mask.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mask.js","sourceRoot":"","sources":["../../../src/_helpers/mask.ts"],"names":[],"mappings":";;;AAAA,mCAAuD;AAEvD,MAAa,IAAI;IACK;IAApB,YAAoB,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAEtC;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,IAAY;QAChB,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,IAAI,CAAC,CAAC,MAAM,CAAC;QACxC,IAAI,MAAM,GAAG,IAAA,kBAAU,EAAC,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE;YAC5C,eAAe,EAAE,IAAI;YACrB,WAAW,EAAE,IAAI;SAClB,CAAC,CAAC;QACH,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QAEpD,KAAK,IAAI,QAAQ,GAAG,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC,MAAM,EAAE,QAAQ,IAAI,CAAC,EAAE,CAAC;YAC7D,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC/B,IAAI,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC;gBAChC,MAAM,GAAG,IAAA,wBAAgB,EAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;QACzD,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAhCD,oBAgCC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare class Random {
|
|
2
|
+
/**
|
|
3
|
+
* Devolve um inteiro aleatório entre um mínimo e um máximo.
|
|
4
|
+
*/
|
|
5
|
+
static between(min: number, max: number): number;
|
|
6
|
+
/**
|
|
7
|
+
* Devolve um texto aleatório
|
|
8
|
+
*/
|
|
9
|
+
static alpha(length?: number, isUppercase?: boolean, isHex?: boolean): string;
|
|
10
|
+
/**
|
|
11
|
+
* Seleciona um item de um array aleatoramente
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const array = [1, 2, 3, 4, 5];
|
|
15
|
+
*
|
|
16
|
+
* const singleItem = Random.fromArray(array); // Pode retornar 1, 2, 3, 4 ou 5
|
|
17
|
+
* const multipleItems = Random.fromArray(array, 3); // Pode retornar [1, 2, 3], [4, 5, 1], etc.
|
|
18
|
+
*
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
static fromArray<T>(array: T[], length: number): T[];
|
|
22
|
+
static fromArray<T>(array: T[], length?: 1): T;
|
|
23
|
+
/**
|
|
24
|
+
* Cria um número aleatório com a quantidade definida de caracteres
|
|
25
|
+
*/
|
|
26
|
+
static number(length: number, forceLength?: boolean, isAlpha?: boolean): string;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=random.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../../src/_helpers/random.ts"],"names":[],"mappings":"AAAA,qBAAa,MAAM;IACjB;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAIhD;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,MAAM,SAAI,EAAE,WAAW,UAAQ,EAAE,KAAK,UAAQ,GAAG,MAAM;IAapE;;;;;;;;;;OAUG;IACH,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC,EAAE;IACpD,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC;IAiB9C;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,UAAQ,EAAE,OAAO,UAAQ,GAAG,MAAM;CAa5E"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Random = void 0;
|
|
4
|
+
class Random {
|
|
5
|
+
/**
|
|
6
|
+
* Devolve um inteiro aleatório entre um mínimo e um máximo.
|
|
7
|
+
*/
|
|
8
|
+
static between(min, max) {
|
|
9
|
+
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Devolve um texto aleatório
|
|
13
|
+
*/
|
|
14
|
+
static alpha(length = 1, isUppercase = false, isHex = false) {
|
|
15
|
+
const letters = isHex ? '0123456789abcdef' : 'abcdefghijklmnopqrstuvwxyz';
|
|
16
|
+
let result = '';
|
|
17
|
+
for (let i = 0; i < length; i++) {
|
|
18
|
+
const index = Random.between(0, letters.length - 1);
|
|
19
|
+
result += letters[index];
|
|
20
|
+
}
|
|
21
|
+
if (isUppercase)
|
|
22
|
+
return result.toLocaleUpperCase();
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
static fromArray(array, length = 1) {
|
|
26
|
+
const _get = () => array.at(Random.between(0, array.length - 1));
|
|
27
|
+
if (length === 1)
|
|
28
|
+
return _get();
|
|
29
|
+
const result = [];
|
|
30
|
+
for (let i = 0; i < length; i++) {
|
|
31
|
+
const item = _get();
|
|
32
|
+
if (item !== undefined) {
|
|
33
|
+
result.push(item);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Cria um número aleatório com a quantidade definida de caracteres
|
|
40
|
+
*/
|
|
41
|
+
static number(length, forceLength = false, isAlpha = false) {
|
|
42
|
+
let value;
|
|
43
|
+
if (isAlpha)
|
|
44
|
+
value = Math.round(Math.random() * 36 ** length)
|
|
45
|
+
.toString(36)
|
|
46
|
+
.toLocaleUpperCase();
|
|
47
|
+
else
|
|
48
|
+
value = Math.floor(Math.random() * 10 ** length).toString();
|
|
49
|
+
if (forceLength)
|
|
50
|
+
return String(value).padStart(length, '0');
|
|
51
|
+
return String(value);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.Random = Random;
|
|
55
|
+
//# sourceMappingURL=random.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random.js","sourceRoot":"","sources":["../../../src/_helpers/random.ts"],"names":[],"mappings":";;;AAAA,MAAa,MAAM;IACjB;;OAE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AAI,KAAK,SAAS,EAAE,CAAC;gBACvB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACpB,CAAC;QACH,CAAC;QAED,OAAO,MAAsB,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,MAAc,EAAE,WAAW,GAAG,KAAK,EAAE,OAAO,GAAG,KAAK;QAChE,IAAI,KAAa,CAAC;QAElB,IAAI,OAAO;YACT,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,MAAM,CAAC;iBAC7C,QAAQ,CAAC,EAAE,CAAC;iBACZ,iBAAiB,EAAE,CAAC;;YACpB,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC;QAEjE,IAAI,WAAW;YAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAE5D,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;CACF;AArED,wBAqEC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calcula o DV verificador a partir das regras do MOD11:
|
|
3
|
+
* O valor da soma é dividido por 11. O resultado é o resto da divisão. Caso o resto seja
|
|
4
|
+
* menor que 2, ou seja, o valor da divisão seja 10 ou 11, o resultado é 0.
|
|
5
|
+
*
|
|
6
|
+
* @param {Integer} sum Soma
|
|
7
|
+
* @returns {Integer}
|
|
8
|
+
*/
|
|
9
|
+
export declare function sumToDV(sum: number): number;
|
|
10
|
+
/**
|
|
11
|
+
* Checa se o número repassado possui todos os digitos iguais
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* checkRepeatedSequence(12345678)
|
|
15
|
+
* // -> false
|
|
16
|
+
* checkRepeatedSequence(11111111)
|
|
17
|
+
* // -> true
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
export declare function checkRepeatedSequence(value: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Multiplica os elementos de uma string com os elementos de outra, ou de um array
|
|
23
|
+
* e soma o resultado ao final
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* sumElementsByMultipliers('123', '987') //-> 46
|
|
27
|
+
* sumElementsByMultipliers('123', [9, 8, 7]) //-> 46
|
|
28
|
+
*
|
|
29
|
+
* @param {String} value
|
|
30
|
+
* @param {String|Array} multiplier
|
|
31
|
+
* @returns {Integer} Somatório
|
|
32
|
+
*/
|
|
33
|
+
export declare function sumElementsByMultipliers(value: string, multiplier: number[]): number;
|
|
34
|
+
/**
|
|
35
|
+
* Limpa um número informado, retirando caracteres diferentes de números,
|
|
36
|
+
* preenchendo com zeros à esquerda se for menor que o tamanho exato e
|
|
37
|
+
* removendo uma parte do número se for maior que tamanho definido.
|
|
38
|
+
*
|
|
39
|
+
* 1) Retira caracteres não-numéricos
|
|
40
|
+
* 2) Preenche com zeros à esquerda se 'value' for menor que 'length'
|
|
41
|
+
* 3) Remove caracteres à direita se 'value' for maior que 'length'
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* clearValue(12345-6, 6) // -> 123456
|
|
45
|
+
* clearValue(12345678, 3) // -> 123
|
|
46
|
+
* clearValue(12345, 10) // -> 0000001234
|
|
47
|
+
*
|
|
48
|
+
* @param {Number|String} value
|
|
49
|
+
* @param {Number} length Tamanho exato. Se for null, só retira os caracteres não-numéricos
|
|
50
|
+
* @returns {String} Número com o tamanho exato
|
|
51
|
+
*/
|
|
52
|
+
export declare function clearValue(value: string | number, length?: number | null, options?: ClearValueOptions): string;
|
|
53
|
+
/**
|
|
54
|
+
* insertAtPosition()
|
|
55
|
+
* Insere um conjunto de caracteres em um local específico de uma string
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* insertAtPosition('AAABBB', 'C', 3) // -> AAACBBB
|
|
59
|
+
* insertAtPosition('000011122223445555', 99, 7) // -> 00001119922223445555
|
|
60
|
+
*
|
|
61
|
+
* @param {String|Number} value Valor original
|
|
62
|
+
* @param {String|Number} insertValue Valor que será inserido
|
|
63
|
+
* @param {String|Number} position Posição que receberá o novo valor
|
|
64
|
+
* @returns {String}
|
|
65
|
+
*
|
|
66
|
+
*/
|
|
67
|
+
export declare function insertAtPosition(value: string, insertValue: string, position: number): string;
|
|
68
|
+
/**
|
|
69
|
+
* removeFromPosition()
|
|
70
|
+
* Retira um conjunto de caracteres de um local específico de uma string
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* removeFromPosition('00001119922223445555', 7,9) // -> 000011122223445555
|
|
74
|
+
* removeFromPosition('AAACBBB', 3,4) // -> AAABBB
|
|
75
|
+
*
|
|
76
|
+
* @param {String|Number} value Valor original
|
|
77
|
+
* @param {String|Number} startPosition
|
|
78
|
+
* @param {String|Number} endPosition
|
|
79
|
+
* @returns {String}
|
|
80
|
+
*
|
|
81
|
+
*/
|
|
82
|
+
export declare function removeFromPosition(value: string, startPosition: number, endPosition: number): string;
|
|
83
|
+
/**
|
|
84
|
+
* Opções do clearValue
|
|
85
|
+
*/
|
|
86
|
+
interface ClearValueOptions {
|
|
87
|
+
fillZerosAtLeft?: boolean;
|
|
88
|
+
trimAtRight?: boolean;
|
|
89
|
+
rejectEmpty?: boolean;
|
|
90
|
+
rejectIfLonger?: boolean;
|
|
91
|
+
rejectIfShorter?: boolean;
|
|
92
|
+
rejectEqualSequence?: boolean;
|
|
93
|
+
}
|
|
94
|
+
export {};
|
|
95
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/_helpers/utils.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,WAElD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,MAAM,CAKpF;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,MAAM,GAAE,MAAM,GAAG,IAAW,EAC5B,OAAO,CAAC,EAAE,iBAAiB,GAC1B,MAAM,CA6BR;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE7F;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,MAAM,EACb,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,GAClB,MAAM,CAER;AAGD;;GAEG;AACH,UAAU,iBAAiB;IAEzB,eAAe,CAAC,EAAE,OAAO,CAAC;IAG1B,WAAW,CAAC,EAAE,OAAO,CAAC;IAGtB,WAAW,CAAC,EAAE,OAAO,CAAC;IAGtB,cAAc,CAAC,EAAE,OAAO,CAAC;IAGzB,eAAe,CAAC,EAAE,OAAO,CAAC;IAG1B,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sumToDV = sumToDV;
|
|
4
|
+
exports.checkRepeatedSequence = checkRepeatedSequence;
|
|
5
|
+
exports.sumElementsByMultipliers = sumElementsByMultipliers;
|
|
6
|
+
exports.clearValue = clearValue;
|
|
7
|
+
exports.insertAtPosition = insertAtPosition;
|
|
8
|
+
exports.removeFromPosition = removeFromPosition;
|
|
9
|
+
const ValidationBRError_1 = require("../_exceptions/ValidationBRError");
|
|
10
|
+
/**
|
|
11
|
+
* Calcula o DV verificador a partir das regras do MOD11:
|
|
12
|
+
* O valor da soma é dividido por 11. O resultado é o resto da divisão. Caso o resto seja
|
|
13
|
+
* menor que 2, ou seja, o valor da divisão seja 10 ou 11, o resultado é 0.
|
|
14
|
+
*
|
|
15
|
+
* @param {Integer} sum Soma
|
|
16
|
+
* @returns {Integer}
|
|
17
|
+
*/
|
|
18
|
+
function sumToDV(sum) {
|
|
19
|
+
return sum % 11 < 2 ? 0 : 11 - (sum % 11);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Checa se o número repassado possui todos os digitos iguais
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* checkRepeatedSequence(12345678)
|
|
26
|
+
* // -> false
|
|
27
|
+
* checkRepeatedSequence(11111111)
|
|
28
|
+
* // -> true
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
function checkRepeatedSequence(value) {
|
|
32
|
+
return [...value].every(digit => digit === value[0]);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Multiplica os elementos de uma string com os elementos de outra, ou de um array
|
|
36
|
+
* e soma o resultado ao final
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* sumElementsByMultipliers('123', '987') //-> 46
|
|
40
|
+
* sumElementsByMultipliers('123', [9, 8, 7]) //-> 46
|
|
41
|
+
*
|
|
42
|
+
* @param {String} value
|
|
43
|
+
* @param {String|Array} multiplier
|
|
44
|
+
* @returns {Integer} Somatório
|
|
45
|
+
*/
|
|
46
|
+
function sumElementsByMultipliers(value, multiplier) {
|
|
47
|
+
return multiplier.reduce((accu, curr, i) => accu + curr * Number(value[i]), 0);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Limpa um número informado, retirando caracteres diferentes de números,
|
|
51
|
+
* preenchendo com zeros à esquerda se for menor que o tamanho exato e
|
|
52
|
+
* removendo uma parte do número se for maior que tamanho definido.
|
|
53
|
+
*
|
|
54
|
+
* 1) Retira caracteres não-numéricos
|
|
55
|
+
* 2) Preenche com zeros à esquerda se 'value' for menor que 'length'
|
|
56
|
+
* 3) Remove caracteres à direita se 'value' for maior que 'length'
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* clearValue(12345-6, 6) // -> 123456
|
|
60
|
+
* clearValue(12345678, 3) // -> 123
|
|
61
|
+
* clearValue(12345, 10) // -> 0000001234
|
|
62
|
+
*
|
|
63
|
+
* @param {Number|String} value
|
|
64
|
+
* @param {Number} length Tamanho exato. Se for null, só retira os caracteres não-numéricos
|
|
65
|
+
* @returns {String} Número com o tamanho exato
|
|
66
|
+
*/
|
|
67
|
+
function clearValue(value, length = null, options) {
|
|
68
|
+
let clearedValue = String(value).replace(/([/.\s-])+/gi, '');
|
|
69
|
+
if (options) {
|
|
70
|
+
const shouldRejectEmpty = options.rejectEmpty === true && clearedValue.length === 0;
|
|
71
|
+
if (shouldRejectEmpty) {
|
|
72
|
+
throw new ValidationBRError_1.EmptyValueException();
|
|
73
|
+
}
|
|
74
|
+
const shouldrejectIfLonger = options.rejectIfLonger === true && length && clearedValue.length > length;
|
|
75
|
+
if (shouldrejectIfLonger) {
|
|
76
|
+
throw new ValidationBRError_1.TooLongException();
|
|
77
|
+
}
|
|
78
|
+
const shouldrejectIfShorter = options.rejectIfShorter === true && length && clearedValue.length < length;
|
|
79
|
+
if (shouldrejectIfShorter) {
|
|
80
|
+
throw new ValidationBRError_1.TooShortException();
|
|
81
|
+
}
|
|
82
|
+
const shouldRejectEqualSequence = options.rejectEqualSequence === true && length;
|
|
83
|
+
if (shouldRejectEqualSequence) {
|
|
84
|
+
if (checkRepeatedSequence(clearedValue))
|
|
85
|
+
throw new ValidationBRError_1.RepeatedSequenceException();
|
|
86
|
+
}
|
|
87
|
+
if (length && options.fillZerosAtLeft)
|
|
88
|
+
clearedValue = clearedValue.padStart(length, '0');
|
|
89
|
+
if (length && options.trimAtRight)
|
|
90
|
+
clearedValue = clearedValue.substring(0, length);
|
|
91
|
+
}
|
|
92
|
+
return clearedValue;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* insertAtPosition()
|
|
96
|
+
* Insere um conjunto de caracteres em um local específico de uma string
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* insertAtPosition('AAABBB', 'C', 3) // -> AAACBBB
|
|
100
|
+
* insertAtPosition('000011122223445555', 99, 7) // -> 00001119922223445555
|
|
101
|
+
*
|
|
102
|
+
* @param {String|Number} value Valor original
|
|
103
|
+
* @param {String|Number} insertValue Valor que será inserido
|
|
104
|
+
* @param {String|Number} position Posição que receberá o novo valor
|
|
105
|
+
* @returns {String}
|
|
106
|
+
*
|
|
107
|
+
*/
|
|
108
|
+
function insertAtPosition(value, insertValue, position) {
|
|
109
|
+
return `${value.substring(0, position)}${insertValue}${value.substring(position)}`;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* removeFromPosition()
|
|
113
|
+
* Retira um conjunto de caracteres de um local específico de uma string
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* removeFromPosition('00001119922223445555', 7,9) // -> 000011122223445555
|
|
117
|
+
* removeFromPosition('AAACBBB', 3,4) // -> AAABBB
|
|
118
|
+
*
|
|
119
|
+
* @param {String|Number} value Valor original
|
|
120
|
+
* @param {String|Number} startPosition
|
|
121
|
+
* @param {String|Number} endPosition
|
|
122
|
+
* @returns {String}
|
|
123
|
+
*
|
|
124
|
+
*/
|
|
125
|
+
function removeFromPosition(value, startPosition, endPosition) {
|
|
126
|
+
return [value.slice(0, startPosition), value.slice(endPosition)].join('');
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=utils.js.map
|