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

idcard-util

v1.0.2

Published

An utility class for Chinese citizenship certificate

Downloads

8

Readme

idcard-util

Build Status Coverage Status

中国公民身份证工具类

Installation

npm i idcard-util

Usage

var IdCard = require('idcard');
var cardInfo = IdCard('42110219910512018X');

console.log(cardInfo);

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.log(cardInfo.getParityCode());

> X

getSex() {Object}
Return the sex of the card owner

console.log(cardInfo.getSex());

> { sex: 0, desc: 'female', desc_cn: '女' }

getBirthDay(format) {Date}
Return the birthday of the card owner

console.log(cardInfo.getBirthDay());

> '1991-05-11T16:00:00.000Z'

console.log(cardInfo.getBirthDay('yyyy年MM月dd日'));

> '1991年05月12日'

getAge() {Number}
Return the age of the card owner

console.log(cardInfo.getAge());

> 26

genRandom() {String}
Generate a random idcard number

console.log(cardInfo.genRandom());

> 440300197505035517

repair() {String}

  1. Update the card number form first generation to the second generation.
  2. Fill the 18th digit if it is missing.
  3. Fix the 18th digit if it is wrong.
console.log(cardInfo.repair());

> {
>   result: 'success',
>   reason: '修复成功',
>   value: '42110219910512018X'
> }