idcard-util
中国公民身份证工具类
Installation
npm i idcard-util
Usage
var IdCard = ;var cardInfo = ; console;
If this is a valid card, it will show the information about this card.
IdCard _card: '42110219910512018X' _isValid: result: true reason: '' _areaCode: '421102' _yearCode: '1991' _monthCode: '05' _dayCode: '12' _sequenceCode: '018' _parityCode: 'X'
Otherwise the error message will be displayed
IdCard _card: '421102199155120188' _isValid: result: false reason: '生日校验失败'
Methods
getParityCode() {Number|String}
Calculate the parity code according to the first 17 digits
console; > X
getSex() {Object}
Return the sex of the card owner
console; > sex: 0 desc: 'female' desc_cn: '女'
getBirthDay(format) {Date}
Return the birthday of the card owner
console; > '1991-05-11T16:00:00.000Z' console; > '1991年05月12日'
getAge() {Number}
Return the age of the card owner
console; > 26
genRandom() {String}
Generate a random idcard number
console; > 440300197505035517
repair() {String}
- Update the card number form first generation to the second generation.
- Fill the 18th digit if it is missing.
- Fix the 18th digit if it is wrong.
console; > > result: 'success'> reason: '修复成功'> value: '42110219910512018X'>