pix-utils-js 1.0.1 → 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
@@ -51,6 +51,7 @@ Instale pix-utils-js com npm ou yarn
51
51
  const { normalize } = 'pix-utils-js'
52
52
  console.log(normalize({pix: '000.000.000-00'})) // {pix: '00000000000', type: 'cpf'}
53
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'}
54
55
  ```
55
56
 
56
57
  | Função | Parametro | Retorno |
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.1",
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