Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
clabe-validator
Advanced tools
Readme
<img src=https://centerkey.com/graphics/center-key-logo.svg align=right width=200 alt=logo>
JavaScript library to analyze or create a CLABE number for a Mexican bank account
CLABE (Clave Bancaria Estandarizada — Spanish for "standardized banking code") is a banking standard from the Mexican Bank Association (Asociación de Bancos de México — ABM) for uniform numbering of bank accounts. CLABE numbers are 18 digits long. See: https://en.wikipedia.org/wiki/CLABE
Try it out:
https://centerkey.com/clabe
Include in a web page:
<script src=clabe.min.js></script>
or from the jsdelivr.com CDN:
<script src=https://cdn.jsdelivr.net/npm/clabe-validator@2.2/dist/clabe.min.js></script>
Install package for node:
$ npm install clabe-validator
Import package:
import { clabe } from 'clabe-validator';
Pass the CLABE number as an 18-character string into clabe.validate(clabeNum)
.
const clabeNum = '002010077777777771';
const clabeCheck = clabe.validate(clabeNum);
console.log(clabeCheck.ok ? '¡Que bueno!' : '¡Muy mal!');
console.log('Your bank: ' + clabeCheck.bank);
{
ok: true,
formatOk: true,
error: null,
message: 'Valid',
clabe: '002010077777777771',
tag: 'BANAMEX',
bank: 'Banco Nacional de México',
city: 'Aguascalientes MX-AGU',
multiple: false,
total: 1,
account: '07777777777',
code: { bank: '002', city: '010' },
checksum: 1,
}
{
ok: false,
formatOk: true,
error: 'invalid-city',
message: 'Invalid city code: 000',
}
The formatOk
field indicates if the CLABE's length and checksum are both valid (even if the bank
code or city code are unknown).
Error code | Error message | Format Ok |
---|---|---|
invalid-length | Must be exactly 18 digits long | false |
invalid-characters | Must be only numeric digits (no letters) | false |
invalid-checksum | Invalid checksum, last digit should be: [DIGIT] | false |
invalid-bank | Invalid bank code: [CODE] | true |
invalid-city | Invalid city code: [CODE] | true |
Pass the bank code, city code, and account number into
clabe.calculate(bankCode, cityCode, accountNumber)
and get the 18-character CLABE number back.
const clabeNum = clabe.calculate(2, 10, 7777777777);
console.log(clabeNum === '002010077777777771'); //true
See the TypeScript declarations at the top of the clabe.ts file.
The clabe.validate(clabeNum: string)
function returns a ClabeCheck
object:
type ClabeCheck = {
ok: boolean, //todo está bien
formatOk: boolean, //valid length and checksum
error: string | null, //failure code, example: 'invalid-city'
message: string, //displayable status information
clabe: string | null, //full 18-digit number
tag: string | null, //bank short name, example: 'BANAMEX'
bank: string | null, //bank long name, example: 'Banco Nacional'
city: string | null, //branch or plaza name
multiple: boolean, //more than one city share the same code
total: number, //number of cities
account: string, //11-digit zero-padded bank account number
code: { bank: string, city: string }, //3-digit codes
checksum: number | null, //control digit (0 to 9)
};
Example TypeScript usage with explicit types:
import { clabe, ClabeCheck } from 'clabe-validator';
const clabeNum: string = '002010077777777771';
const clabeCheck: ClabeCheck = clabe.validate(clabeNum); //{ ok: true, error: null, ... }
const bankCode: string = clabeCheck.code.bank; //'002'
To be a contributor, fork the project and run the commands npm install
and npm test
on your local clone.
Make your edits and rerun the tests.
Pull requests welcome. Since the pacakge version number is updated during the release process, leave the version number unchanged.
The origin of this project goes back to when I needed to send money to Guanajuato, Mexico to pay nurses who were providing medical care of a relative. I was initially unable to transfer funds because the money transfer service reported that the CLABE number I supplied was invalid. Through a little sleuthing and a lot of luck, I discovered that a financial services company had accidentally omitted the very last modulo operation in their CLABE checksum calculation. The result was that valid Mexican bank account numbers with certain combinations of digits were erroneously rejected.
This project was created to fix the checksum bug. It is an open source community project and is not supported by any company.
Check out the runScriptsConfig
section in package.json for an
interesting approach to organizing build tasks.
CLI Build Tools for package.json
Feel free to submit questions at:
github.com/center-key/clabe-validator/issues
CLABE Validator code is open source under the MIT License, and the documentation is published under the CC BY-SA 4.0 license.
FAQs
Analyze or create a CLABE number for a Mexican bank account (written in functional TypeScript)
The npm package clabe-validator receives a total of 3,093 weekly downloads. As such, clabe-validator popularity was classified as popular.
We found that clabe-validator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.