@devix-tecnologia/value-objects 2.1.4
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/LICENSE +21 -0
- package/README.md +42 -0
- package/dist/cjs/cpf_cnpj/index.js +152 -0
- package/dist/cjs/imagem_base64/image-formats.js +90 -0
- package/dist/cjs/imagem_base64/index.js +132 -0
- package/dist/cjs/index.js +9 -0
- package/dist/cjs/telefone/country_codes.js +1146 -0
- package/dist/cjs/telefone/ddd.js +73 -0
- package/dist/cjs/telefone/index.js +127 -0
- package/dist/cjs/types/base_class.js +2 -0
- package/dist/cjs/types/cpf_cnpj/index.d.ts +25 -0
- package/dist/cjs/types/cpf_cnpj/index.d.ts.map +1 -0
- package/dist/cjs/types/imagem_base64/image-formats.d.ts +14 -0
- package/dist/cjs/types/imagem_base64/image-formats.d.ts.map +1 -0
- package/dist/cjs/types/imagem_base64/index.d.ts +32 -0
- package/dist/cjs/types/imagem_base64/index.d.ts.map +1 -0
- package/dist/cjs/types/index.d.ts +5 -0
- package/dist/cjs/types/index.d.ts.map +1 -0
- package/dist/cjs/types/telefone/country_codes.d.ts +7 -0
- package/dist/cjs/types/telefone/country_codes.d.ts.map +1 -0
- package/dist/cjs/types/telefone/ddd.d.ts +3 -0
- package/dist/cjs/types/telefone/ddd.d.ts.map +1 -0
- package/dist/cjs/types/telefone/index.d.ts +38 -0
- package/dist/cjs/types/telefone/index.d.ts.map +1 -0
- package/dist/cjs/types/types/base_class.d.ts +26 -0
- package/dist/cjs/types/types/base_class.d.ts.map +1 -0
- package/dist/esm/cpf_cnpj/index.js +151 -0
- package/dist/esm/imagem_base64/image-formats.js +86 -0
- package/dist/esm/imagem_base64/index.js +129 -0
- package/dist/esm/index.mjs +4 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/telefone/country_codes.js +1143 -0
- package/dist/esm/telefone/ddd.js +70 -0
- package/dist/esm/telefone/index.js +124 -0
- package/dist/esm/types/base_class.js +1 -0
- package/dist/esm/types/cpf_cnpj/index.d.ts +25 -0
- package/dist/esm/types/cpf_cnpj/index.d.ts.map +1 -0
- package/dist/esm/types/imagem_base64/image-formats.d.ts +14 -0
- package/dist/esm/types/imagem_base64/image-formats.d.ts.map +1 -0
- package/dist/esm/types/imagem_base64/index.d.ts +32 -0
- package/dist/esm/types/imagem_base64/index.d.ts.map +1 -0
- package/dist/esm/types/index.d.ts +5 -0
- package/dist/esm/types/index.d.ts.map +1 -0
- package/dist/esm/types/telefone/country_codes.d.ts +7 -0
- package/dist/esm/types/telefone/country_codes.d.ts.map +1 -0
- package/dist/esm/types/telefone/ddd.d.ts +3 -0
- package/dist/esm/types/telefone/ddd.d.ts.map +1 -0
- package/dist/esm/types/telefone/index.d.ts +38 -0
- package/dist/esm/types/telefone/index.d.ts.map +1 -0
- package/dist/esm/types/types/base_class.d.ts +26 -0
- package/dist/esm/types/types/base_class.d.ts.map +1 -0
- package/package.json +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Devix Tecnologia
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
Aqui está o README.md atualizado da raiz do projeto, incluindo as informações do componente `ImagemBase64`:
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Devix - Objetos de Valores
|
|
6
|
+
|
|
7
|
+
Biblioteca para manipulação e validação de objetos de valor em JavaScript/TypeScript. Fornece classes utilitárias para lidar com dados comuns, como números de telefone, documentos e imagens em base64, garantindo validação e formatação consistentes.
|
|
8
|
+
|
|
9
|
+
## Instalação
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
npm i @devix-tecnologia/value-objects
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Importação
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import { NomeDaClasse } from '@devix-tecnologia/value-objects'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Objetos de valor disponíveis
|
|
22
|
+
|
|
23
|
+
- <a href="./src/telefone/readme.md">Telefone</a> - Manipula e valida números de telefone, com suporte a DDD brasileiro e códigos de país.
|
|
24
|
+
- <a href="./src/cpf_cnpj/readme.md">CPF/CNPJ</a> - Valida e formata documentos CPF e CNPJ.
|
|
25
|
+
- <a href="./src/imagem_base64/readme.md">ImagemBase64</a> - Gerencia e valida imagens codificadas em base64, com detecção automática de formato.
|
|
26
|
+
|
|
27
|
+
## A fazer
|
|
28
|
+
|
|
29
|
+
- Endereço
|
|
30
|
+
- Email
|
|
31
|
+
- Nome (Pessoa Física)
|
|
32
|
+
- Dinheiro
|
|
33
|
+
- CEP
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
### Notas sobre a atualização:
|
|
38
|
+
1. **Adição do ImagemBase64**: Incluí o componente `ImagemBase64` na lista de objetos de valor, com um link para o README específico (`./src/imagem_base64/readme.md`) e uma breve descrição de sua funcionalidade.
|
|
39
|
+
2. **Estrutura mantida**: Preservei o formato original do README, apenas expandindo a seção de objetos de valor.
|
|
40
|
+
3. **Consistência**: Alinhei a descrição do `ImagemBase64` com o estilo das outras entradas (Telefone e CPF/CNPJ).
|
|
41
|
+
|
|
42
|
+
Se precisar de mais ajustes ou quiser que eu inclua algo específico, como exemplos adicionais ou uma seção de "Funções auxiliares" mais detalhada, é só pedir!
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CpfCnpj = void 0;
|
|
4
|
+
class CpfCnpj {
|
|
5
|
+
constructor(numDoc) {
|
|
6
|
+
this._isValid = false;
|
|
7
|
+
const doc = String(numDoc).replace(/[^\d]+/g, '');
|
|
8
|
+
this._docId = doc;
|
|
9
|
+
if (doc.length === 11 && this.isCpfValid()) {
|
|
10
|
+
this._docType = 'CPF';
|
|
11
|
+
this._isValid = true;
|
|
12
|
+
}
|
|
13
|
+
else if (doc.length === 14 && this.isCnpjValid()) {
|
|
14
|
+
this._docType = 'CNPJ';
|
|
15
|
+
this._isValid = true;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
this._docType = 'INVALID';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
get type() {
|
|
22
|
+
return this._docType;
|
|
23
|
+
}
|
|
24
|
+
get version() {
|
|
25
|
+
return CpfCnpj.VERSION;
|
|
26
|
+
}
|
|
27
|
+
get validation() {
|
|
28
|
+
return this._docType === 'CPF'
|
|
29
|
+
? 'Módulo 11 para CPF'
|
|
30
|
+
: 'Módulo 11 para CNPJ';
|
|
31
|
+
}
|
|
32
|
+
get formatted() {
|
|
33
|
+
this.isValid({ raiseException: true });
|
|
34
|
+
if (this._docType === 'CPF') {
|
|
35
|
+
return this._docId.replace(/^(\d{3})(\d{3})(\d{3})(\d{2})$/, '$1.$2.$3-$4');
|
|
36
|
+
}
|
|
37
|
+
return this._docId.replace(/^(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})$/, '$1.$2.$3/$4-$5');
|
|
38
|
+
}
|
|
39
|
+
get onlyNumbers() {
|
|
40
|
+
this.isValid({ raiseException: true });
|
|
41
|
+
return this._docId;
|
|
42
|
+
}
|
|
43
|
+
toJSON() {
|
|
44
|
+
return {
|
|
45
|
+
type: this.type,
|
|
46
|
+
value: this.onlyNumbers,
|
|
47
|
+
formatted: this.formatted,
|
|
48
|
+
isValid: this._isValid,
|
|
49
|
+
version: this.version,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
toString() {
|
|
53
|
+
return this.formatted;
|
|
54
|
+
}
|
|
55
|
+
isValid(config = { raiseException: false }) {
|
|
56
|
+
if (config.raiseException && !this._isValid) {
|
|
57
|
+
throw new Error(`Invalid ${this._docType.toLowerCase()}`);
|
|
58
|
+
}
|
|
59
|
+
return this._isValid;
|
|
60
|
+
}
|
|
61
|
+
equals(other) {
|
|
62
|
+
if (!this._isValid)
|
|
63
|
+
return false;
|
|
64
|
+
try {
|
|
65
|
+
const otherDoc = other instanceof CpfCnpj ? other : new CpfCnpj(other);
|
|
66
|
+
return this.onlyNumbers === otherDoc.onlyNumbers;
|
|
67
|
+
}
|
|
68
|
+
catch (_a) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
static newCpf() {
|
|
73
|
+
let doc_id = '';
|
|
74
|
+
for (let i = 0; i < 9; i += 1) {
|
|
75
|
+
doc_id += Math.floor(Math.random() * 9);
|
|
76
|
+
}
|
|
77
|
+
doc_id += this.CpfVerifierDigits(doc_id);
|
|
78
|
+
doc_id += this.CpfVerifierDigits(doc_id);
|
|
79
|
+
return new CpfCnpj(doc_id);
|
|
80
|
+
}
|
|
81
|
+
static newCnpj() {
|
|
82
|
+
let doc_id = '';
|
|
83
|
+
for (let i = 0; i < 12; i += 1) {
|
|
84
|
+
doc_id += Math.floor(Math.random() * 9);
|
|
85
|
+
}
|
|
86
|
+
doc_id += this.CnpjVerifierDigits(doc_id);
|
|
87
|
+
doc_id += this.CnpjVerifierDigits(doc_id);
|
|
88
|
+
return new CpfCnpj(doc_id);
|
|
89
|
+
}
|
|
90
|
+
isCpfValid() {
|
|
91
|
+
const blocklist = [
|
|
92
|
+
'00000000000',
|
|
93
|
+
'11111111111',
|
|
94
|
+
'22222222222',
|
|
95
|
+
'33333333333',
|
|
96
|
+
'44444444444',
|
|
97
|
+
'55555555555',
|
|
98
|
+
'66666666666',
|
|
99
|
+
'77777777777',
|
|
100
|
+
'88888888888',
|
|
101
|
+
'99999999999',
|
|
102
|
+
'12345678909',
|
|
103
|
+
];
|
|
104
|
+
if (blocklist.includes(this._docId))
|
|
105
|
+
return false;
|
|
106
|
+
let numbers = this._docId.slice(0, 9);
|
|
107
|
+
numbers += CpfCnpj.CpfVerifierDigits(numbers);
|
|
108
|
+
numbers += CpfCnpj.CpfVerifierDigits(numbers);
|
|
109
|
+
return numbers.slice(-2) === this._docId.slice(-2);
|
|
110
|
+
}
|
|
111
|
+
isCnpjValid() {
|
|
112
|
+
const blocklist = [
|
|
113
|
+
'00000000000000',
|
|
114
|
+
'11111111111111',
|
|
115
|
+
'22222222222222',
|
|
116
|
+
'33333333333333',
|
|
117
|
+
'44444444444444',
|
|
118
|
+
'55555555555555',
|
|
119
|
+
'66666666666666',
|
|
120
|
+
'77777777777777',
|
|
121
|
+
'88888888888888',
|
|
122
|
+
'99999999999999',
|
|
123
|
+
];
|
|
124
|
+
if (blocklist.includes(this._docId))
|
|
125
|
+
return false;
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
static CpfVerifierDigits(doc_ident) {
|
|
129
|
+
const numbers = doc_ident.split('').map((number) => parseInt(number, 10));
|
|
130
|
+
const modulus = numbers.length + 1;
|
|
131
|
+
const multiplied = numbers.map((number, index) => number * (modulus - index));
|
|
132
|
+
const mod = multiplied.reduce((buffer, number) => buffer + number) % 11;
|
|
133
|
+
return mod < 2 ? 0 : 11 - mod;
|
|
134
|
+
}
|
|
135
|
+
static CnpjVerifierDigits(doc_ident) {
|
|
136
|
+
let index = 2;
|
|
137
|
+
const reverse = doc_ident
|
|
138
|
+
.split('')
|
|
139
|
+
.reduce((buffer, number) => {
|
|
140
|
+
return [parseInt(number, 10)].concat(buffer);
|
|
141
|
+
}, []);
|
|
142
|
+
const sum = reverse.reduce((buffer, number) => {
|
|
143
|
+
buffer += number * index;
|
|
144
|
+
index = index === 9 ? 2 : index + 1;
|
|
145
|
+
return buffer;
|
|
146
|
+
}, 0);
|
|
147
|
+
const mod = sum % 11;
|
|
148
|
+
return mod < 2 ? 0 : 11 - mod;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
exports.CpfCnpj = CpfCnpj;
|
|
152
|
+
CpfCnpj.VERSION = '1.0.0';
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.imageFormats = void 0;
|
|
4
|
+
exports.findFormatByPrefix = findFormatByPrefix;
|
|
5
|
+
const imageFormats = {
|
|
6
|
+
JPEG: {
|
|
7
|
+
name: 'JPEG Image',
|
|
8
|
+
extension: 'jpg',
|
|
9
|
+
mimeType: 'image/jpeg',
|
|
10
|
+
base64Prefix: ['/9j/'],
|
|
11
|
+
},
|
|
12
|
+
PNG: {
|
|
13
|
+
name: 'Portable Network Graphics',
|
|
14
|
+
extension: 'png',
|
|
15
|
+
mimeType: 'image/png',
|
|
16
|
+
base64Prefix: ['iVBORw0KGgo'],
|
|
17
|
+
},
|
|
18
|
+
GIF: {
|
|
19
|
+
name: 'Graphics Interchange Format',
|
|
20
|
+
extension: 'gif',
|
|
21
|
+
mimeType: 'image/gif',
|
|
22
|
+
base64Prefix: ['R0lGODlh'],
|
|
23
|
+
},
|
|
24
|
+
WEBP: {
|
|
25
|
+
name: 'WebP Image',
|
|
26
|
+
extension: 'webp',
|
|
27
|
+
mimeType: 'image/webp',
|
|
28
|
+
base64Prefix: ['UklGRg=='],
|
|
29
|
+
},
|
|
30
|
+
BMP: {
|
|
31
|
+
name: 'Bitmap Image File',
|
|
32
|
+
extension: 'bmp',
|
|
33
|
+
mimeType: 'image/bmp',
|
|
34
|
+
base64Prefix: ['Qk'],
|
|
35
|
+
},
|
|
36
|
+
TIFF: {
|
|
37
|
+
name: 'Tagged Image File Format',
|
|
38
|
+
extension: 'tiff',
|
|
39
|
+
mimeType: 'image/tiff',
|
|
40
|
+
base64Prefix: ['SUkqAA==', 'TU0AKg=='],
|
|
41
|
+
},
|
|
42
|
+
ICO: {
|
|
43
|
+
name: 'Windows Icon',
|
|
44
|
+
extension: 'ico',
|
|
45
|
+
mimeType: 'image/x-icon',
|
|
46
|
+
base64Prefix: ['AAABAAEAICAQAAEABADoAgAAFg=='],
|
|
47
|
+
},
|
|
48
|
+
SVG: {
|
|
49
|
+
name: 'Scalable Vector Graphics',
|
|
50
|
+
extension: 'svg',
|
|
51
|
+
mimeType: 'image/svg+xml',
|
|
52
|
+
base64Prefix: ['PHN2Zw=='],
|
|
53
|
+
},
|
|
54
|
+
HEIC: {
|
|
55
|
+
name: 'High Efficiency Image Format',
|
|
56
|
+
extension: 'heic',
|
|
57
|
+
mimeType: 'image/heic',
|
|
58
|
+
base64Prefix: ['AAAAGGZ0eXA='],
|
|
59
|
+
},
|
|
60
|
+
AVIF: {
|
|
61
|
+
name: 'AV1 Image File Format',
|
|
62
|
+
extension: 'avif',
|
|
63
|
+
mimeType: 'image/avif',
|
|
64
|
+
base64Prefix: ['AAAAGGFhdmM='],
|
|
65
|
+
},
|
|
66
|
+
PSD: {
|
|
67
|
+
name: 'Adobe Photoshop Document',
|
|
68
|
+
extension: 'psd',
|
|
69
|
+
mimeType: 'image/vnd.adobe.photoshop',
|
|
70
|
+
base64Prefix: ['OEJQUw=='],
|
|
71
|
+
},
|
|
72
|
+
unknown: {
|
|
73
|
+
name: 'Unknown Format',
|
|
74
|
+
extension: '',
|
|
75
|
+
mimeType: 'application/octet-stream',
|
|
76
|
+
base64Prefix: [],
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
exports.imageFormats = imageFormats;
|
|
80
|
+
/**
|
|
81
|
+
* Detecta o formato da imagem pelo seu prefixo base64
|
|
82
|
+
*/
|
|
83
|
+
function findFormatByPrefix(base64Str) {
|
|
84
|
+
for (const [format, info] of Object.entries(imageFormats)) {
|
|
85
|
+
if (info.base64Prefix.some((prefix) => base64Str.startsWith(prefix))) {
|
|
86
|
+
return format;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return 'unknown';
|
|
90
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImagemBase64 = void 0;
|
|
4
|
+
const image_formats_js_1 = require("./image-formats.js");
|
|
5
|
+
/**
|
|
6
|
+
* Cria objeto de valor para imagens em base64.
|
|
7
|
+
* Valida se a string fornecida é uma imagem base64 válida.
|
|
8
|
+
* Detecta o formato da imagem.
|
|
9
|
+
* Aceita tanto strings base64 puras quanto data URIs.
|
|
10
|
+
*/
|
|
11
|
+
class ImagemBase64 {
|
|
12
|
+
constructor(content) {
|
|
13
|
+
this._content = '';
|
|
14
|
+
this._format = 'unknown';
|
|
15
|
+
this._isValid = false;
|
|
16
|
+
this._isDataUri = false;
|
|
17
|
+
this._content = content;
|
|
18
|
+
this.validate();
|
|
19
|
+
}
|
|
20
|
+
get type() {
|
|
21
|
+
return 'BASE64_IMAGE';
|
|
22
|
+
}
|
|
23
|
+
get version() {
|
|
24
|
+
return ImagemBase64.VERSION;
|
|
25
|
+
}
|
|
26
|
+
get validation() {
|
|
27
|
+
return 'Validação de string base64 e assinatura de formato de imagem';
|
|
28
|
+
}
|
|
29
|
+
get formatted() {
|
|
30
|
+
return this.DataUri;
|
|
31
|
+
}
|
|
32
|
+
get format() {
|
|
33
|
+
this.isValid({ raiseException: true });
|
|
34
|
+
return this._format;
|
|
35
|
+
}
|
|
36
|
+
get content() {
|
|
37
|
+
this.isValid({ raiseException: true });
|
|
38
|
+
return this._isDataUri ? this._content.split(',')[1] : this._content;
|
|
39
|
+
}
|
|
40
|
+
get formatInfo() {
|
|
41
|
+
this.isValid({ raiseException: true });
|
|
42
|
+
return image_formats_js_1.imageFormats[this._format];
|
|
43
|
+
}
|
|
44
|
+
get DataUri() {
|
|
45
|
+
this.isValid({ raiseException: true });
|
|
46
|
+
if (this._isDataUri) {
|
|
47
|
+
return this._content;
|
|
48
|
+
}
|
|
49
|
+
return `data:image/${this._format.toLowerCase()};base64,${this._content}`;
|
|
50
|
+
}
|
|
51
|
+
toJSON() {
|
|
52
|
+
if (!this._isValid) {
|
|
53
|
+
return {
|
|
54
|
+
type: this.type,
|
|
55
|
+
isValid: false,
|
|
56
|
+
version: this.version,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
type: this.type,
|
|
61
|
+
formatted: this.formatted,
|
|
62
|
+
format: this._format,
|
|
63
|
+
isValid: true,
|
|
64
|
+
version: this.version,
|
|
65
|
+
mimeType: `image/${this._format.toLowerCase()}`,
|
|
66
|
+
isDataUri: this._isDataUri,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
toString() {
|
|
70
|
+
if (!this._isValid)
|
|
71
|
+
return '';
|
|
72
|
+
return this.formatted;
|
|
73
|
+
}
|
|
74
|
+
isValid(config = { raiseException: false }) {
|
|
75
|
+
if (config.raiseException && !this._isValid) {
|
|
76
|
+
throw new Error('Invalid base64 image');
|
|
77
|
+
}
|
|
78
|
+
return this._isValid;
|
|
79
|
+
}
|
|
80
|
+
equals(other) {
|
|
81
|
+
if (!this._isValid)
|
|
82
|
+
return false;
|
|
83
|
+
try {
|
|
84
|
+
const otherImage = other instanceof ImagemBase64
|
|
85
|
+
? other
|
|
86
|
+
: new ImagemBase64(other);
|
|
87
|
+
if (!otherImage.isValid())
|
|
88
|
+
return false;
|
|
89
|
+
return this.content === otherImage.content;
|
|
90
|
+
}
|
|
91
|
+
catch (_a) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
validate() {
|
|
96
|
+
if (!this._content || typeof this._content !== 'string') {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
// Verifica se é data URI
|
|
100
|
+
if (this._content.startsWith('data:image/')) {
|
|
101
|
+
this._isDataUri = true;
|
|
102
|
+
const [header, base64Content] = this._content.split(',');
|
|
103
|
+
if (!base64Content || !this.isBase64String(base64Content)) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const format = header.split('data:image/')[1].split(';')[0].toUpperCase();
|
|
107
|
+
this._format = format === 'JPG' ? 'JPEG' : format;
|
|
108
|
+
this._isValid = true;
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
// Verifica se é base64 puro
|
|
112
|
+
if (!this.isBase64String(this._content)) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
// Detecta o formato
|
|
116
|
+
this._format = (0, image_formats_js_1.findFormatByPrefix)(this._content);
|
|
117
|
+
this._isValid = this._format !== 'unknown';
|
|
118
|
+
}
|
|
119
|
+
isBase64String(str) {
|
|
120
|
+
if (!str)
|
|
121
|
+
return false;
|
|
122
|
+
try {
|
|
123
|
+
const regex = /^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$/;
|
|
124
|
+
return regex.test(str.trim());
|
|
125
|
+
}
|
|
126
|
+
catch (_a) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.ImagemBase64 = ImagemBase64;
|
|
132
|
+
ImagemBase64.VERSION = '1.0.0';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImagemBase64 = exports.CpfCnpj = exports.Telefone = void 0;
|
|
4
|
+
const index_js_1 = require("./telefone/index.js");
|
|
5
|
+
Object.defineProperty(exports, "Telefone", { enumerable: true, get: function () { return index_js_1.Telefone; } });
|
|
6
|
+
const index_js_2 = require("./cpf_cnpj/index.js");
|
|
7
|
+
Object.defineProperty(exports, "CpfCnpj", { enumerable: true, get: function () { return index_js_2.CpfCnpj; } });
|
|
8
|
+
const index_js_3 = require("./imagem_base64/index.js");
|
|
9
|
+
Object.defineProperty(exports, "ImagemBase64", { enumerable: true, get: function () { return index_js_3.ImagemBase64; } });
|