Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

clabe-validator

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clabe-validator

Analyze or create a CLABE number for a Mexican bank account (written in TypeScript)

  • 1.5.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.3K
decreased by-0.21%
Maintainers
1
Weekly downloads
 
Created
Source

CLABE Validator

<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

License:MIT npm Vulnerabilities Hits Build

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

A) Online form

Try it out:
https://centerkey.com/clabe

B) Setup

Web browser

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@1.5/dist/clabe.min.js></script>
Node.js server

Install package for node:

$ npm install clabe-validator

Import package:

import { clabe } from 'clabe-validator';

Or for older CommonJS environments:

const clabe = require('clabe-validator');  //deprecated

Note: Release v1.4.0 contains a significant number of bank and city code additions plus updates to reflect financial institution mergers and name changes.

C) Validator usage

Pass the CLABE number as an 18-character string into clabe.validate(clabeNum).

1. Example JavaScript code
const clabeNum = '002010077777777771';
const clabeCheck = clabe.validate(clabeNum);
console.log(clabeCheck.ok ? '¡Que bueno!' : '¡Muy mal!');
console.log('Your bank: ' + clabeCheck.bank);
2. Example JSON result for a valid CLABE number
{
   ok:       true,
   error:    null,
   formatOk: true,
   tag:      'BANAMEX',
   bank:     'Banco Nacional de México, S.A.',
   city:     'Aguascalientes MX-AGU',
   account:  '07777777777'
}
3. Example JSON result for an invalid CLABE number
{
   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 invalid).

4. Possible errors
Error codeError messageFormat Ok
invalid-lengthMust be exactly 18 digits longfalse
invalid-charactersMust be only numeric digits (no letters)false
invalid-checksumInvalid checksum, last digit should be: [DIGIT]false
invalid-bankInvalid bank code: [CODE]true
invalid-cityInvalid city code: [CODE]true

D) Calculator usage

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

E) TypeScript declarations

The TypeScript Declaration File file is clabe.d.ts in the dist folder.

The clabe.validate(clabeNum: string) function returns a ClabeCheck object:

type ClabeCheck = {
   ok:       boolean,
   error:    string | null,
   formatOk: boolean,
   message:  string,
   tag:      string | null,
   bank:     string | null,
   city:     string | null,
   account:  string,
   code:     { bank: string, city: string },
   checksum: number | null,
   };

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'

F) Contributor Notes

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.



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.

Keywords

FAQs

Package last updated on 12 Feb 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc