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.4

Published

中华人民共和国公民身份号码验证工具库 (GB 11643-1999)

Downloads

931

Readme

NPM version Build Status Coverage Status NPM downloads Size license

简体中文 | English

特性

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

安装

pnpm 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) | boolean | 快速验证身份证是否有效 | | parse(id) | IDCardInfo | 解析完整身份证信息 | | mask(id) | string | 脱敏处理(显示前3后4位) | | toEighteen(id) | string \| null | 15位转18位 | | getCheckCode(id) | string \| null | 计算校验码 |

校验函数

| 函数 | 返回类型 | 说明 | | --------------------- | --------- | ------------ | | checkBaseFormat(id) | boolean | 检验基本格式 | | checkProvince(id) | boolean | 检验省份代码 |

IDCardInfo 类型

interface IDCardInfo {
  isValid: boolean; // 身份证是否有效
  provinceCode: string; // 省份代码 (如: '62')
  province: string; // 省份名称 (如: '甘肃省')
  birthDate: string; // 出生日期 (YYYY-MM-DD)
  gender: 'male' | 'female'; // 性别
  age: number; // 年龄
  fifteenDigit: string | null; // 15位身份证
  eighteenDigit: string | null; // 18位身份证
}

许可证

MIT License


Made by tonyc726