clabe-validator 1.7.1
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.txt +21 -0
- package/README.md +159 -0
- package/dist/clabe.d.ts +39 -0
- package/dist/clabe.dev.js +1071 -0
- package/dist/clabe.js +1071 -0
- package/dist/clabe.min.js +3 -0
- package/dist/clabe.umd.cjs +1084 -0
- package/package.json +112 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-2021 individual contributors to CLABE Validator
|
|
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,159 @@
|
|
|
1
|
+
# CLABE Validator
|
|
2
|
+
<img src=https://centerkey.com/graphics/center-key-logo.svg align=right width=200 alt=logo>
|
|
3
|
+
|
|
4
|
+
_JavaScript library to analyze or create a CLABE number for a Mexican bank account_
|
|
5
|
+
|
|
6
|
+
[](https://github.com/center-key/clabe-validator/blob/main/LICENSE.txt)
|
|
7
|
+
[](https://www.npmjs.com/package/clabe-validator)
|
|
8
|
+
[](https://snyk.io/test/github/center-key/clabe-validator)
|
|
9
|
+
[](https://www.jsdelivr.com/package/npm/clabe-validator)
|
|
10
|
+
[](https://github.com/center-key/clabe-validator/actions?query=workflow%3Abuild)
|
|
11
|
+
|
|
12
|
+
CLABE (Clave Bancaria Estandarizada — Spanish for "standardized banking code") is a banking
|
|
13
|
+
standard from the Mexican Bank Association (Asociación de Bancos de México — ABM) for
|
|
14
|
+
uniform numbering of bank accounts. CLABE numbers are 18 digits long.
|
|
15
|
+
See: https://en.wikipedia.org/wiki/CLABE
|
|
16
|
+
|
|
17
|
+
## A) Online Form
|
|
18
|
+
Try it out:<br>
|
|
19
|
+
[https://centerkey.com/clabe](https://centerkey.com/clabe/)
|
|
20
|
+
|
|
21
|
+
## B) Setup
|
|
22
|
+
### Web browser
|
|
23
|
+
Include in a web page:
|
|
24
|
+
```html
|
|
25
|
+
<script src=clabe.min.js></script>
|
|
26
|
+
```
|
|
27
|
+
or from the [jsdelivr.com CDN](https://www.jsdelivr.com/package/npm/clabe-validator):
|
|
28
|
+
```html
|
|
29
|
+
<script src=https://cdn.jsdelivr.net/npm/clabe-validator@1.7/dist/clabe.min.js></script>
|
|
30
|
+
```
|
|
31
|
+
### Node.js server
|
|
32
|
+
Install package for node:
|
|
33
|
+
```shell
|
|
34
|
+
$ npm install clabe-validator
|
|
35
|
+
```
|
|
36
|
+
Import package:
|
|
37
|
+
```javascript
|
|
38
|
+
import { clabe } from 'clabe-validator';
|
|
39
|
+
```
|
|
40
|
+
Or for older CommonJS/UMD environments:
|
|
41
|
+
```javascript
|
|
42
|
+
const { clabe } = require('clabe-validator'); //deprecated
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Note:** _Release v1.4.0 contains a significant number of bank and city code additions plus
|
|
46
|
+
updates to reflect financial institution mergers and name changes._
|
|
47
|
+
|
|
48
|
+
## C) Validator Usage
|
|
49
|
+
Pass the CLABE number as an 18-character string into `clabe.validate(clabeNum)`.
|
|
50
|
+
|
|
51
|
+
### 1. Example JavaScript code
|
|
52
|
+
```javascript
|
|
53
|
+
const clabeNum = '002010077777777771';
|
|
54
|
+
const clabeCheck = clabe.validate(clabeNum);
|
|
55
|
+
console.log(clabeCheck.ok ? '¡Que bueno!' : '¡Muy mal!');
|
|
56
|
+
console.log('Your bank: ' + clabeCheck.bank);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 2. Example JSON result for a valid CLABE number
|
|
60
|
+
```javascript
|
|
61
|
+
{
|
|
62
|
+
ok: true,
|
|
63
|
+
formatOk: true,
|
|
64
|
+
error: null,
|
|
65
|
+
message: 'Valid',
|
|
66
|
+
clabe: '002010077777777771',
|
|
67
|
+
tag: 'BANAMEX',
|
|
68
|
+
bank: 'Banco Nacional de México, S.A.',
|
|
69
|
+
city: 'Aguascalientes MX-AGU',
|
|
70
|
+
account: '07777777777',
|
|
71
|
+
code: { bank: '002', city: '010' },
|
|
72
|
+
checksum: 1,
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 3. Example JSON result for an invalid CLABE number
|
|
77
|
+
```javascript
|
|
78
|
+
{
|
|
79
|
+
ok: false,
|
|
80
|
+
formatOk: true,
|
|
81
|
+
error: 'invalid-city',
|
|
82
|
+
message: 'Invalid city code: 000',
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
The `formatOk` field indicates if the CLABE's length and checksum are both valid (even if the bank
|
|
86
|
+
code or city code are unknown).
|
|
87
|
+
|
|
88
|
+
### 4. Possible errors
|
|
89
|
+
| Error code | Error message | Format Ok |
|
|
90
|
+
| -------------------- | ----------------------------------------------- | ----------|
|
|
91
|
+
| `invalid-length` | Must be exactly 18 digits long | `false` |
|
|
92
|
+
| `invalid-characters` | Must be only numeric digits (no letters) | `false` |
|
|
93
|
+
| `invalid-checksum` | Invalid checksum, last digit should be: [DIGIT] | `false` |
|
|
94
|
+
| `invalid-bank` | Invalid bank code: [CODE] | `true` |
|
|
95
|
+
| `invalid-city` | Invalid city code: [CODE] | `true` |
|
|
96
|
+
|
|
97
|
+
## D) Calculator Usage
|
|
98
|
+
Pass the bank code, city code, and account number into
|
|
99
|
+
`clabe.calculate(bankCode, cityCode, accountNumber)`
|
|
100
|
+
and get the 18-character CLABE number back.
|
|
101
|
+
|
|
102
|
+
```javascript
|
|
103
|
+
const clabeNum = clabe.calculate(2, 10, 7777777777);
|
|
104
|
+
console.log(clabeNum === '002010077777777771'); //true
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## E) TypeScript Declarations
|
|
108
|
+
The **TypeScript Declaration File** file is [clabe.d.ts](dist/clabe.d.ts) in the **dist** folder.
|
|
109
|
+
|
|
110
|
+
The `clabe.validate(clabeNum: string)` function returns a `ClabeCheck` object:
|
|
111
|
+
```typescript
|
|
112
|
+
type ClabeCheck = {
|
|
113
|
+
ok: boolean,
|
|
114
|
+
formatOk: boolean,
|
|
115
|
+
error: string | null,
|
|
116
|
+
message: string,
|
|
117
|
+
clabe: string | null,
|
|
118
|
+
tag: string | null,
|
|
119
|
+
bank: string | null,
|
|
120
|
+
city: string | null,
|
|
121
|
+
account: string,
|
|
122
|
+
code: { bank: string, city: string },
|
|
123
|
+
checksum: number | null,
|
|
124
|
+
};
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Example TypeScript usage with explicit types:
|
|
128
|
+
```typescript
|
|
129
|
+
import { clabe, ClabeCheck } from 'clabe-validator';
|
|
130
|
+
|
|
131
|
+
const clabeNum: string = '002010077777777771';
|
|
132
|
+
const clabeCheck: ClabeCheck = clabe.validate(clabeNum); //{ ok: true, error: null, ... }
|
|
133
|
+
const bankCode: string = clabeCheck.code.bank; //'002'
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## F) Contributor Notes
|
|
137
|
+
To be a contributor, **fork** the project and run the commands `npm install` and `npm test` on your
|
|
138
|
+
local clone. Make your edits and rerun the tests. Pull requests welcome.
|
|
139
|
+
|
|
140
|
+
## G) Genesis
|
|
141
|
+
The origin of this project goes back to when I needed to send money to Guanajuato, Mexico to pay
|
|
142
|
+
nurses who were providing medical care of a relative.
|
|
143
|
+
I was initially unable to transfer funds because the money transfer service reported that the CLABE
|
|
144
|
+
number I supplied was invalid.
|
|
145
|
+
Through a little sleuthing and a lot of luck, I discovered that a financial services company had
|
|
146
|
+
accidentally omitted the very last modulo operation in their CLABE checksum calculation.
|
|
147
|
+
The result was that Mexican bank account numbers ending in a zero were rejected.
|
|
148
|
+
|
|
149
|
+
This project was created to fix the checksum bug.
|
|
150
|
+
It is an open source community project and is not supported by any company.
|
|
151
|
+
<br>
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
Feel free to submit questions at:<br>
|
|
155
|
+
[github.com/center-key/clabe-validator/issues](https://github.com/center-key/clabe-validator/issues)
|
|
156
|
+
|
|
157
|
+
CLABE Validator code is open source under the [MIT License](LICENSE.txt),
|
|
158
|
+
and the documentation is published under the
|
|
159
|
+
[CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0) license.
|
package/dist/clabe.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//! clabe-validator v1.7.1 ~ https://github.com/center-key/clabe-validator ~ MIT License
|
|
2
|
+
|
|
3
|
+
export declare type ClabeBank = {
|
|
4
|
+
tag?: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare type ClabeBanksMap = {
|
|
8
|
+
[bankCode: number]: ClabeBank;
|
|
9
|
+
};
|
|
10
|
+
export declare type ClabeCity = [number, string];
|
|
11
|
+
export declare type ClabeCitiesMap = {
|
|
12
|
+
[cityCode: number]: string;
|
|
13
|
+
};
|
|
14
|
+
export declare type ClabeCheck = {
|
|
15
|
+
ok: boolean;
|
|
16
|
+
formatOk: boolean;
|
|
17
|
+
error: string | null;
|
|
18
|
+
message: string;
|
|
19
|
+
clabe: string | null;
|
|
20
|
+
tag: string | null;
|
|
21
|
+
bank: string | null;
|
|
22
|
+
city: string | null;
|
|
23
|
+
account: string;
|
|
24
|
+
code: {
|
|
25
|
+
bank: string;
|
|
26
|
+
city: string;
|
|
27
|
+
};
|
|
28
|
+
checksum: number | null;
|
|
29
|
+
};
|
|
30
|
+
declare const clabe: {
|
|
31
|
+
version: string;
|
|
32
|
+
computeChecksum(clabeNum17: string): number | null;
|
|
33
|
+
validate(clabeNum: string): ClabeCheck;
|
|
34
|
+
calculate(bankCode: number, cityCode: number, accountNumber: number): string;
|
|
35
|
+
banksMap: ClabeBanksMap;
|
|
36
|
+
cities: ClabeCity[];
|
|
37
|
+
citiesMap: ClabeCitiesMap;
|
|
38
|
+
};
|
|
39
|
+
export { clabe };
|