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

v4.2.0

Published

校验身份证合法性,获取身份证详细信息

Downloads

599

Readme

校验身份证[第二代]合法性,获取身份证详细信息

Build Status via Travis CI Coverage Status NPM version

安装:npm install idcard

API

verify

info

generateIdcard

constellation

getAge

upgrade15To18

var idCard = require('idcard');
/**
* param:idcard(string)
* return boolean
*/
idCard.verify('440882199100201232');//false
var idCard = require('idcard');
/**
* param:idcard(string)
* return object
*/
idCard.info('440882199100201232');

返回结果:

//身份证合法时返回的数据结构
{ 
	valid: true,//身份证是否合法的标志
	gender: 'M',//M->男,F->女
	birthday: 19910210,//
	province: {
		code: '440000',//行政区域编码
		text: '广东省' 
	},
	city: { 
		code: '440800', 
		text: '湛江市' 
	},
	area: { 
		code: '440882', 
		text: '雷州市' 
	},
	cardType: 1,//身份证类型,1->大陆,2->港澳台
	cardText: '大陆',
	address: '广东省湛江市雷州市',
	age:24,
	constellation:'水瓶'//星座 
}
//身份证非法时返回的数据结构
{
	valid: false
}
var idCard = require('idcard');
/**
* return string
*/
idCard.generateIdcard();//返回随机身份证号码
var idCard = require('idcard');
/**
* return string
*/
idCard.constellation(19910210);//水瓶
idCard.constellation('1991/02/10','/');//水瓶
var idCard = require('idcard');
/**
* return number
*/
idCard.getAge(19910210);//25 (调用时的日期:2016/03/23)
var idCard = require('idcard');
/**
* return Object
*/
var result = idCard.upgrade15To18(422201720809227);
result结构:
{
	code: 0,
	msg: '身份证15位升级到18位成功',
	card: '18位的身份证'
}

身份证中第十八位数字的计算方法

  • 将前面的身份证号码17位数分别乘以不同的系数。从第一位到第十七位的系数分别为:7、9、10、5、8、4、2、1、6、3、7、9、10、5、8、4、2;
  • 将这17位数字和系数相乘的结果相加;
  • 用加出来和除以11,看余数是多少
  • 余数只可能有0 、1、 2、 3、 4、 5、 6、 7、 8、 9、 10这11个数字。其分别对应的最后一位身份证的号码为1、0、X、9、8、7、6、5、4、3、2;
  • 通过上面得知如果余数是2,就会在身份证的第18位数字上出现罗马数字的Ⅹ。如果余数是10,身份证的最后一位号码就是2。
  • 第一代身份证十五位数升为第二代身份证十八位数:第一步,在原十五位数身份证的第六位数后面插入19 ,这样身份证号码即为十七位数;第二步,按照国家规定的统一公式计算出第十八位数,作为校验码放在第二代身份证的尾号。

身份证倒数第二位:偶数性别为女,奇数为男

更新区域代码脚本 (4.1.0)

  1. 将上一个版本的area.json, city.json, province.json, 拷贝到province_city_area_code.js文件中的provinces, citys, areas变量
  2. node bin/get_gov_data.js http://www.mca.gov.cn/article/sj/tjbz/a/2017/201801/201801151447.html (此步骤自动爬取相应链接区域代码并添加到history文件夹内, 链接替换为相应年份的区域代码网址)
  3. node bin/gen_gov_data.js (此步骤将history文件夹内所有code汇总成一份govCode.json文件)
  4. node bin/gen_area_data.js (注意, 此脚本会覆盖原先的json文件, 请先做好备份)
  5. node bin/checkDiff.js可以看到更新情况

版本更新

  • 4.1.0 更新自动化脚本, 更改更新区域代码步骤, 新增history文件夹, 保留历史(1980~????)以来所有行政区域代码
  • 4.0.0 区域代码更新自动化,感谢SwenChan同学贡献代码
  • 3.4.0 升级行政区域代码, 同时将行政区域代码抽出, 独立为三个文件(province, city.json, area.json), 添加增量更新脚本
  • 3.3.1 升级行政区划代码至2016年7月31日
  • 3.3.0 新增接口upgrade15To18,用于将15身份证升级到18位
  • 3.2.0 新增接口getAge,用于返回年龄
  • 3.1.0 info接口增加返回星座,新增接口constellation,用于获取星座
  • 3.0.0 更新地级市和县级市的行政区域代码,同时将行政区域代码独立出来。
  • 2.0.0 版本完善info接口,对于身份证校验不准确时也返回相应的归属地信息。

附录:行政区域代码