1.0.2 • Published 5 years ago

egg-idcard v1.0.2

Weekly downloads
1
License
MIT
Repository
-
Last release
5 years ago

egg-idcard

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Install

$ npm i egg-idcard --save

Usage

// {app_root}/config/plugin.js
exports.idcard = {
  enable: true,
  package: 'egg-idcard',
};

Configuration

// {app_root}/config/config.default.js
exports.idcard = {
};

see config/config.default.js for more detail.

Example

身份证有效性验证

this.app.idcard.verify('123456789');
// {"valid":false, "msg":"请检查身份证号码格式是否合法"}
this.app.idcard.verify('330102199001206292');
// {"valid":false, "msg":"身份证号码18位校验位错误"}
this.app.idcard.verify('330102199001206293');
// {"valid":true,"msg":""}

身份证号码信息提取

this.app.idcard.info('330102199001206293');
// {"valid":true,"msg":"","area":{"province":{"code":"330000","name":"浙江省"},"city":{"code":"330100","name":"杭州市"},"district":{"code":"330102","name":"上城区"}},"birthday":"19900120","age":29,"gender":"M"}

随机生成身份证号码

this.app.idcard.random();
// 330102199001206293

城市编码转换2017版

this.app.idcard.area('330102');
// {"province":{"code":"330000","name":"浙江省"},"city":{"code":"330100","name":"杭州市"},"district":{"code":"330102","name":"上城区"}}

15位身份证号码补全

this.app.idcard.repair('330102900120629');
// 330102199001206293

Questions & Suggestions

Please open an issue here.

License

MIT