npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bankcard

v3.1.1

Published

通过银行卡号查询银行和卡类型,支持浏览器端和node

Downloads

188

Readme

bankcard

npm GitHub Build Status

通过银行卡号查询银行卡信息,支持浏览器端和 node 端

安装

npm install bankcard
yarn add bankcard
pnpm add bankcard

使用

  • es
import { searchCardBin } from 'bankcard';
searchCardBin('622305453434432224');
  • node
const { searchCardBin } = require('bankcard');
searchCardBin('622305453434432224');
  • 浏览器引入

在浏览器中使用 script 标签直接引入文件,并使用全局变量 bankcard

npm 包的 bankcard/dist 目录下提供了 bankcard.js 以及 bankcard.min.js。你也可以通过 UNPKG 进行下载。或者在测试中直接使用 UNPKG 线上版本注意版本

<script src="https://unpkg.com/bankcard@latest/dist/bankcard.min.js"></script>
<script>
  bankcard.searchCardBin("622305453434432224");
  bankcard.validateCardInfo("622305453434432224");
</script>

示例

API

type CardInfo = {
  bankName: string; // 银行名称
  bankCode: string; // 银行编码
  cardBin: string; // 银行卡卡Bin
  cardType: CardType; // 卡类型
  cardTypeName: CardTypeName; // 卡类型名称
  len: number; // 卡号长度
};

searchCardBin

根据银行卡号查询卡 Bin 的银行卡信息。

searchCardBin(bankCardNo: string, options?: {
  multiple?: boolean;  // 支持查询多个值,返回结果将变成数组,默认 false 。不常用,仅少数不同银行的卡 bin 存在重复。
  data?: CardInfo[]; // 自定义数据
});

无结果返回 null,有结果返回:CardInfo

multiple=true ,返回:CardInfo[]

validateCardInfo

验证银行卡号。

validateCardInfo(bankCardNo: string, options?: {
  data?: CardInfo[]; // 自定义数据
});

返回:

{
  validated: boolean, // 验证结果
  errorCode: string; // 错误码
  message: string, // 错误信息
  cardInfo: CardInfo | null; // 当验证成功返回 CardInfo ,否则返回 null
}

先查询卡 Bin,再校验卡号长度。如果验证失败 validatedfalse

errorCode message 有以下值:

| errorCode | message | | --------- | ---------------- | | 01 | 找不到该银行卡号 | | 02 | 银行卡号格式错误 |

banks

全部银行列表。

[
  {
    code: 'ABC',
    name: '中国农业银行'
  }
  // ...
];

cards

全部银行卡信息列表。

CardInfo[];

CardType

卡类型。

{
  DC: "DC",
  CC: "CC",
  SCC: "SCC",
  PC: "PC"
}

CardTypeName

卡类型名称。

{
  DC: "储蓄卡",
  CC: "信用卡",
  SCC: "准贷记卡",
  PC: "预付费卡"
}

其他

部分银行卡不符合 Luhn 算法。如招商银行的运通卡、中国银行借记卡等等。可参阅《支付宝为什么不采用银行卡 Luhn 算法校验卡号?》。