pix-utils-js 1.0.6 → 1.0.7
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/README.md +4 -2
- package/index.d.ts +1 -1
- package/index.js +2 -1
- package/package.json +1 -1
- package/tests/index.js +27 -0
- package/utils/validator.js +5 -0
- package/yarn-error.log +59 -0
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ Instale pix-utils-js com npm ou yarn
|
|
|
31
31
|
|
|
32
32
|
| Função | Parametro | Retorno |
|
|
33
33
|
| :---------- | :--------- | :---------------------------------- |
|
|
34
|
-
| `identify` | `input: {pix: string}` | Pix `{ pix: string, type: 'email' \| 'cpf' \| 'cnpj' \| 'random' \|'phone' }` |
|
|
34
|
+
| `identify` | `input: {pix: string}` | Pix `{ pix: string, type: 'email' \| 'cpf' \| 'cnpj' \| 'random' \|'phone' \| 'qrcode' }` |
|
|
35
35
|
|
|
36
36
|
#### Validar uma chave pix
|
|
37
37
|
|
|
@@ -40,6 +40,7 @@ Instale pix-utils-js com npm ou yarn
|
|
|
40
40
|
console.log(validate({pix: 'test@gmail.com'})) // true
|
|
41
41
|
console.log(validate({pix: 'test'})) // false
|
|
42
42
|
console.log(validate({pix: 'test@gmail.com', type : 'cpf'})) // false
|
|
43
|
+
console.log(validate({pix: '00020126360014BR.GOV...', type : 'qrcode'})) // true
|
|
43
44
|
```
|
|
44
45
|
|
|
45
46
|
| Função | Parametro | Retorno |
|
|
@@ -53,11 +54,12 @@ Instale pix-utils-js com npm ou yarn
|
|
|
53
54
|
console.log(normalize({pix: '000.000.000-00'})) // {pix: '00000000000', type: 'cpf'}
|
|
54
55
|
console.log(normalize({pix: '00.000.000/0000-00'})) // {pix: '00000000000000', type: 'cnpj'}
|
|
55
56
|
console.log(normalize({pix: '+55 (11) 0000-0000'})) // {pix: '551100000000', type: 'phone'}
|
|
57
|
+
console.log(normalize({pix: '00020126360014BR.GOV...'})) // {pix: '00020126360014BR.GOV...', type: 'qrcode'}
|
|
56
58
|
```
|
|
57
59
|
|
|
58
60
|
| Função | Parametro | Retorno |
|
|
59
61
|
| :---------- | :--------- | :---------------------------------- |
|
|
60
|
-
| `normalize` | `input: {pix: string}` | Pix `{ pix: string, type: 'email' \| 'cpf' \| 'cnpj' \| 'random' \|'phone' }` |
|
|
62
|
+
| `normalize` | `input: {pix: string}` | Pix `{ pix: string, type: 'email' \| 'cpf' \| 'cnpj' \| 'random' \|'phone' \| 'qrcode' }` |
|
|
61
63
|
|
|
62
64
|
|
|
63
65
|
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
package/tests/index.js
CHANGED
|
@@ -9,6 +9,11 @@ describe('validate', () => {
|
|
|
9
9
|
assert.strictEqual(sut, false);
|
|
10
10
|
});
|
|
11
11
|
|
|
12
|
+
it('should returns false if qr pix key is provided', (t) => {
|
|
13
|
+
const sut = validate({pix: 'invalid', type: 'qrcode'})
|
|
14
|
+
assert.strictEqual(sut, false);
|
|
15
|
+
});
|
|
16
|
+
|
|
12
17
|
it('should returns true if email key is provided and is valid', (t) => {
|
|
13
18
|
const sut = validate({pix: Generator.generateRandomEmail()})
|
|
14
19
|
assert.strictEqual(sut, true);
|
|
@@ -23,6 +28,18 @@ describe('validate', () => {
|
|
|
23
28
|
const sut = validate({pix: Generator.generateRandomUUID()})
|
|
24
29
|
assert.strictEqual(sut, true);
|
|
25
30
|
});
|
|
31
|
+
|
|
32
|
+
it('should returns true qrcode if qrcode pix is provided and is valid', (t) => {
|
|
33
|
+
const qrCode = '00020126360014BR.GOV.BCB.PIX0114+5511999226498520400005303986540813213.005802BR5904test6004test62070503***630450CF'
|
|
34
|
+
const sut = validate({ pix: qrCode })
|
|
35
|
+
assert.strictEqual(sut, true);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should returns false qrcode if qrcode pix is provided and is invalid', (t) => {
|
|
39
|
+
const qrCode = '/INVALID/00020126360014BR.GOV.BCB.PIX0114+5511999226498520400005303986540813213.005802BR5904test6004test62070503***630450CF'
|
|
40
|
+
const sut = validate({ pix: qrCode })
|
|
41
|
+
assert.strictEqual(sut, false);
|
|
42
|
+
});
|
|
26
43
|
})
|
|
27
44
|
|
|
28
45
|
describe('identify', () => {
|
|
@@ -56,6 +73,12 @@ describe('identify', () => {
|
|
|
56
73
|
assert.notStrictEqual(sut, { pix: phone, type: 'phone' });
|
|
57
74
|
});
|
|
58
75
|
|
|
76
|
+
it('should returns qrcode if qrcode pix is provided', (t) => {
|
|
77
|
+
const qrCode = '00020126360014BR.GOV.BCB.PIX0114+5511999226498520400005303986540813213.005802BR5904test6004test62070503***630450CF'
|
|
78
|
+
const sut = identify({ pix: qrCode })
|
|
79
|
+
assert.notStrictEqual(sut, { pix: qrCode, type: 'qrcode' });
|
|
80
|
+
});
|
|
81
|
+
|
|
59
82
|
it('should throws if invalid pix is provided', (t) => {
|
|
60
83
|
let sut;
|
|
61
84
|
try {
|
|
@@ -79,4 +102,8 @@ describe("normalize", () => {
|
|
|
79
102
|
it('should normalize phone key', (t) => {
|
|
80
103
|
assert.deepEqual(normalize({ pix: "+55 (11) 0000-0000"}), { pix: '551100000000', type: 'phone'});
|
|
81
104
|
});
|
|
105
|
+
|
|
106
|
+
it('should normalize qrcode key', (t) => {
|
|
107
|
+
assert.deepEqual(normalize({ pix: "00020126360014BR.GOV.BCB.PIX0114+5511999226498520400005303986540813213.005802BR5904test6004test62070503***630450CF"}), { pix: '00020126360014BR.GOV.BCB.PIX0114+5511999226498520400005303986540813213.005802BR5904test6004test62070503***630450CF', type: 'qrcode'});
|
|
108
|
+
});
|
|
82
109
|
})
|
package/utils/validator.js
CHANGED
|
@@ -23,6 +23,11 @@ class Validator {
|
|
|
23
23
|
const cnpjRegex = /^(\d{2}\.\d{3}\.\d{3}\/\d{4}-\d{2}|\d{14})$/;
|
|
24
24
|
return cnpjRegex.test(cnpj)
|
|
25
25
|
}
|
|
26
|
+
|
|
27
|
+
isQRCode(pixKeyCopyPaste) {
|
|
28
|
+
const qrCodeRegex = /^(000201|01|2636)/
|
|
29
|
+
return qrCodeRegex.test(pixKeyCopyPaste)
|
|
30
|
+
}
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
module.exports = {
|
package/yarn-error.log
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
Arguments:
|
|
2
|
+
C:\Program Files\nodejs\node.exe C:\Users\Paulo\AppData\Roaming\npm\node_modules\yarn\bin\yarn.js publish
|
|
3
|
+
|
|
4
|
+
PATH:
|
|
5
|
+
C:\Program Files\PowerShell\7;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\Git\cmd;C:\Program Files\Docker\Docker\resources\bin;C:\Program Files\Amazon\AWSCLIV2\;C:\Program Files\nodejs\;C:\Program Files\PowerShell\7\;C:\Program Files\dotnet\;C:\Users\Paulo\AppData\Local\Microsoft\WindowsApps;;C:\Users\Paulo\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Paulo\AppData\Roaming\npm;C:\Users\Paulo\.dotnet\tools
|
|
6
|
+
|
|
7
|
+
Yarn version:
|
|
8
|
+
1.22.19
|
|
9
|
+
|
|
10
|
+
Node version:
|
|
11
|
+
20.9.0
|
|
12
|
+
|
|
13
|
+
Platform:
|
|
14
|
+
win32 x64
|
|
15
|
+
|
|
16
|
+
Trace:
|
|
17
|
+
Error: canceled
|
|
18
|
+
at Interface.<anonymous> (C:\Users\Paulo\AppData\Roaming\npm\node_modules\yarn\lib\cli.js:137150:13)
|
|
19
|
+
at Interface.emit (node:events:514:28)
|
|
20
|
+
at [_ttyWrite] [as _ttyWrite] (node:internal/readline/interface:1125:18)
|
|
21
|
+
at ReadStream.onkeypress (node:internal/readline/interface:264:20)
|
|
22
|
+
at ReadStream.emit (node:events:514:28)
|
|
23
|
+
at emitKeys (node:internal/readline/utils:371:14)
|
|
24
|
+
at emitKeys.next (<anonymous>)
|
|
25
|
+
at ReadStream.onData (node:internal/readline/emitKeypressEvents:64:36)
|
|
26
|
+
at ReadStream.emit (node:events:514:28)
|
|
27
|
+
at addChunk (node:internal/streams/readable:376:12)
|
|
28
|
+
|
|
29
|
+
npm manifest:
|
|
30
|
+
{
|
|
31
|
+
"name": "pix-utils-js",
|
|
32
|
+
"version": "1.0.7",
|
|
33
|
+
"author": "Paulo Henrique",
|
|
34
|
+
"description": "Um pacote para fornecer utilidades e validações para chaves pix.",
|
|
35
|
+
"main": "index.js",
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "https://github.com/paulohenriquesn/pix-utils-js.git"
|
|
39
|
+
},
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/paulohenriquesn/pix-utils-js/issues"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/paulohenriquesn/pix-utils-js#readme",
|
|
44
|
+
"scripts": {
|
|
45
|
+
"test": "node tests/index.js"
|
|
46
|
+
},
|
|
47
|
+
"keywords": [
|
|
48
|
+
"pix",
|
|
49
|
+
"chave pix"
|
|
50
|
+
],
|
|
51
|
+
"license": "MIT"
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
yarn manifest:
|
|
55
|
+
No manifest
|
|
56
|
+
|
|
57
|
+
Lockfile:
|
|
58
|
+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
|
59
|
+
# yarn lockfile v1
|