pix-utils-js 1.0.5 → 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.
@@ -0,0 +1,25 @@
1
+ name: Node.js CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ "main" ]
6
+ pull_request:
7
+ branches: [ "main" ]
8
+
9
+ jobs:
10
+ build:
11
+
12
+ runs-on: ubuntu-latest
13
+
14
+ strategy:
15
+ matrix:
16
+ node-version: [18.x]
17
+
18
+ steps:
19
+ - uses: actions/checkout@v3
20
+ - name: Use Node.js ${{ matrix.node-version }}
21
+ uses: actions/setup-node@v3
22
+ with:
23
+ node-version: ${{ matrix.node-version }}
24
+ - run: yarn
25
+ - run: yarn test
package/README.md CHANGED
@@ -25,21 +25,22 @@ Instale pix-utils-js com npm ou yarn
25
25
  #### Identifique uma chave pix
26
26
 
27
27
  ```js
28
- const { identify } = 'pix-utils-js'
28
+ import { identify } from 'pix-utils-js'
29
29
  const { pix, type } = identify({pix: 'test@gmail.com'}) // {pix: 'test@gmail.com', type: 'email'}
30
30
  ```
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
 
38
38
  ```js
39
- const { validate } = 'pix-utils-js'
39
+ import { validate } from 'pix-utils-js'
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 |
@@ -49,15 +50,16 @@ Instale pix-utils-js com npm ou yarn
49
50
  #### Normalizar uma chave pix
50
51
 
51
52
  ```js
52
- const { normalize } = 'pix-utils-js'
53
+ import { normalize } from 'pix-utils-js'
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
@@ -1,4 +1,4 @@
1
- export type PixType = "email" | "cpf" | "cnpj" | "random" | "phone"
1
+ export type PixType = "email" | "cpf" | "cnpj" | "random" | "phone" | "qrcode"
2
2
 
3
3
  export interface InvalidPix extends Error {
4
4
  message: "chave pix invalida."
package/index.js CHANGED
@@ -7,7 +7,8 @@ const validationPixMap = {
7
7
  random: validator.isUUID,
8
8
  phone: validator.isPhoneNumber,
9
9
  cnpj: validator.isCNPJ,
10
- cpf: validator.isCPF
10
+ cpf: validator.isCPF,
11
+ qrcode: validator.isQRCode
11
12
  };
12
13
 
13
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pix-utils-js",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "author": "Paulo Henrique",
5
5
  "description": "Um pacote para fornecer utilidades e validações para chaves pix.",
6
6
  "main": "index.js",
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
  })
@@ -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