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

id-card-of-china

v1.0.1

Published

一个基于「公民身份身份号码」规则获取身份证号码中包含的基础信息组件(JS)

Downloads

58

Readme

Identity Card Of China (JS)

中华人民共和国身份证(The identity card of the people's Republic of China)

PHP 版本:https://github.com/medz/id-card-of-china

id-card-of-china 是一个基于「公民身份号码」规则获取公民身份号码中包含的基础信息组件。

安装

# npm
npm i id-card-of-china
# Yarn
yarn add id-card-of-china

使用

import Identity from "id-card-of-china";

const peopleIdentity = new Identity("350301198906180060");

APIs

基于 src/identity.interface.ts 实例

  • legal:检查公民身份号码是否合法
  • birthday:获取公民身份号码中包含的生日信息
  • gender:获取身份证包含的性别信息
  • region: 获取身份证包含的地区信息,返回 sec/region.interface.ts 实例

region 对象 APIs

  • code: 获取 GB/T 2260 的地区行政代码
  • province:获取省份名称或者直辖市名称
  • city:获取城市名称,如果是直辖市则返回 ''
  • county:获取区县名称
  • tree:获取地区层级数组
  • treeString:获取地区完整字符串,支持传递一个参数作为省市区的分隔符

演示

import Identity from "id-card-of-china";

const peopleIdentity = new Identity("350301198906180060");

const peopleIdentity = new Identity(peopleIDNumber);
const peopleRegion = peopleIdentity.region();

console.log(
    peopleIdentity.legal(),    // true | false
    peopleIdentity.birthday(), // 1989-06-18
    peopleIdentity.gender(),   // 女 | 男
    peopleRegion.code(),       // 350302
    peopleRegion.province(),   // 福建省
    peopleRegion.city(),       // 莆田市
    peopleRegion.county(),     // 城厢区
    peopleRegion.tree(),       // ["福建省", "莆田市", "城厢区"]
    peopleRegion.treeString(' ') // 福建省 莆田市 城厢区
);

疑问解答

  1. 问:为什么不添加年龄、星座还有属相等信息?

    答:因为年龄需要专门的时间组件去计算,星座如果是「粗略」计算可以获得,但是没有意义,属相更加复杂,负责任的转换这些属性都比简单转换复杂,简单转换出来的不够准确。同样也失去了包本身该有的功能,例如年龄可以交给「时间组件」等。

  2. 问:这个包到底干啥的?

    答:这个包就是提取公民身份号码所包含的基础信息

  3. 问:可以用来验证人或者其他的吗?

    答:不基于公安部的 API 验证的身份证组件都不能叫验证组件,现在所有的 ID Card 组件都只能提取公民身份号码所包含的信息,如果说验证,那唯一能验证的就是公民身份号码是否是一个合法的公民身份号码。

LICENSE

This component follows the MIT open source agreement.