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 🙏

© 2026 – Pkg Stats / Ryan Hefner

china-id-card

v2.2.1

Published

China citizen identification number

Downloads

1,565

Readme

China ID Card Validator

基于 GB 11643-1999 标准的中华人民共和国公民身份证号码验证工具库

NPM version Build Status Coverage Status NPM downloads Size license

English · 在线文档 · 国内访问 · 更新日志 · 标准 PDF

✨ 特性

  • 0 依赖 - 无任何第三方依赖,安全可靠
  • 格式验证 - 检查身份证基本格式
  • 🏙️ 省份校验 - 验证省份代码有效性
  • 🎂 生日校验 - 验证出生日期合法性
  • 🔐 校验码验证 - 使用加权算法验证校验位
  • 🔄 15/18位转换 - 支持相互转换
  • 📊 信息解析 - 解析省份、出生日期、性别、年龄
  • 🔒 脱敏处理 - 隐藏部分身份证号码

🖥 环境支持

  • Node.js 18+
  • 现代浏览器
  • Deno / Bun

📦 安装

pnpm add china-id-card
npm install china-id-card
bun add china-id-card

🔨 使用

import { isValid, parse, mask } from 'china-id-card'

const info = parse('622922197808118498')
// → { isValid: true, province: '甘肃省', birthDate: '1978-08-11', gender: 'male', age: 46, ... }

isValid('622922197808118498')  // → true
mask('622922197808118498')     // → '622***********8498'

API

isValid(id: string): boolean

快速验证身份证是否有效。

import { isValid } from 'china-id-card';
isValid('110101199001011001'); // true

parse(id: string): IDCardInfo

解析身份证详细信息,返回对象包含以下字段:

| 字段 | 类型 | 说明 | | --------------- | ------------------ | --------------------- | | isValid | boolean | 身份证是否有效 | | provinceCode | string | 省份代码 | | province | string | 省份名称 | | birthDate | string | 出生日期 (YYYY-MM-DD) | | gender | 'male' | 'female' | 性别 | | age | number | 年龄 | | fifteenDigit | string | null | 15位身份证号码 | | eighteenDigit | string | null | 18位身份证号码 |

mask(id: string): string

对身份证进行脱敏处理,显示前3位和后4位。

toEighteen(id: string): string | null

将15位身份证转换为18位。

getCheckCode(id: string): string | null

计算18位身份证的校验码。

checkBaseFormat(id: string): boolean

检验身份证基本格式(长度和字符规则)。

checkProvince(id: string): boolean

检验省份代码是否有效。

📖 文档

🤝 贡献

欢迎提交 Pull Request 和 Issue!

📄 许可证

MIT License


Made by Tony