pix-utils-js 1.0.0 → 1.0.2

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 CHANGED
@@ -1,6 +1,11 @@
1
1
 
2
2
  # 💸 pix-utils-js
3
3
 
4
+ ![](https://img.shields.io/npm/dw/pix-utils-js)
5
+ ![](https://img.shields.io/npm/v/pix-utils-js)
6
+ ![](https://img.shields.io/github/contributors/paulohenriquesn/pix-utils-js)
7
+ ![](https://img.shields.io/npm/l/pix-utils-js)
8
+
4
9
  Uma pequena biblioteca que irá te ajudar a lidar com chaves pix
5
10
 
6
11
 
@@ -26,7 +31,7 @@ Instale pix-utils-js com npm ou yarn
26
31
 
27
32
  | Função | Parametro | Retorno |
28
33
  | :---------- | :--------- | :---------------------------------- |
29
- | `identify` | `input: {pix: string}` | Pix `{ pix: string, type: string }` |
34
+ | `identify` | `input: {pix: string}` | Pix `{ pix: string, type: 'email' \| 'cpf' \| 'cnpj' \| 'random' \|'phone' }` |
30
35
 
31
36
  #### Validar uma chave pix
32
37
 
@@ -46,11 +51,12 @@ Instale pix-utils-js com npm ou yarn
46
51
  const { normalize } = 'pix-utils-js'
47
52
  console.log(normalize({pix: '000.000.000-00'})) // {pix: '00000000000', type: 'cpf'}
48
53
  console.log(normalize({pix: '00.000.000/0000-00'})) // {pix: '00000000000000', type: 'cnpj'}
54
+ console.log(normalize({pix: '+55 (11) 0000-0000'})) // {pix: '551100000000', type: 'phone'}
49
55
  ```
50
56
 
51
57
  | Função | Parametro | Retorno |
52
58
  | :---------- | :--------- | :---------------------------------- |
53
- | `normalize` | `input: {pix: string}` | Pix `{ pix: string, type: string }` |
59
+ | `normalize` | `input: {pix: string}` | Pix `{ pix: string, type: 'email' \| 'cpf' \| 'cnpj' \| 'random' \|'phone' }` |
54
60
 
55
61
 
56
62
 
package/index.js CHANGED
@@ -56,7 +56,7 @@ const normalize = (input) => {
56
56
 
57
57
  const { type } = identify({ pix })
58
58
 
59
- if(type === 'cpf' || type === 'cnpj') {
59
+ if(type === 'cpf' || type === 'cnpj' || type === 'phone') {
60
60
  pix = pix.replace(/[^0-9]/g, '')
61
61
  }
62
62
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pix-utils-js",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
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
@@ -75,4 +75,8 @@ describe("normalize", () => {
75
75
  it('should normalize cnpj key', (t) => {
76
76
  assert.deepEqual(normalize({ pix: "00.000.000/0000-00"}), { pix: '00000000000000', type: 'cnpj'});
77
77
  });
78
+
79
+ it('should normalize phone key', (t) => {
80
+ assert.deepEqual(normalize({ pix: "+55 (11) 0000-0000"}), { pix: '551100000000', type: 'phone'});
81
+ });
78
82
  })
@@ -10,7 +10,7 @@ class Validator {
10
10
  }
11
11
 
12
12
  isPhoneNumber(phoneNumber) {
13
- const phoneNumberRegex = /^(\d{3}-\d{3}-\d{4}|\d{10}|\(\d{3}\)\s*\d{3}-\d{4}|\d{3}\s\d{3}\s\d{4})$/;
13
+ const phoneNumberRegex = /^(\+\d{2}\s*)?(\(\d{2}\))?\s*(\d{4,5}-?\d{4})$/
14
14
  return phoneNumberRegex.test(phoneNumber)
15
15
  }
16
16