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 🙏

© 2025 – Pkg Stats / Ryan Hefner

identity-number

v0.0.4

Published

A simple identity number library

Readme

Identity

介绍

这是一个用于处理中国身份证号码的 TypeScript 类。我来详细解释其功能和实现:

基本结构

类名为 Identity,用于处理身份证号码 包含两个私有属性:_id(存储身份证号)和_isValid(存储验证结果)

主要功能

  • 身份证号码验证
  • 性别判断
  • 出生日期计算
  • 年龄计算
  • 地区信息获取
  • 星座计算
  • 身份证号脱敏

    验证机制 - 类实现了三层验证: 1. 格式验证:使用正则表达式检查基本格式 2. 日期验证:检查身份证中的日期是否有效 3. 校验码验证:使用加权求和算法验证最后一位校验码

重要方法说明:

constructor:构造函数,接收身份证号并立即验证 isValidDate:验证身份证中的日期是否有效 isValidCheckCode:验证校验码是否正确 validateId:综合验证身份证号 gender:获取性别(奇数为男,偶数为女) birth:获取出生日期字符串 age:计算当前年龄 regionCode:获取地区编码 constellation:计算星座 desensitization:身份证号脱敏处理

注意事项:

所有 getter 方法在返回值前都会调用 ensureValid()确保身份证号有效 日期计算考虑了闰年等特殊情况 年龄计算精确到天 脱敏处理可自定义脱敏字符和范围

使用示例:

const id = new Identity("11010519491231002X");
console.log(id.gender); // 输出性别
console.log(id.birth); // 输出出生日期
console.log(id.age); // 输出年龄
console.log(id.regionCode); // 输出地区编码
console.log(id.desensitization()); // 输出脱敏后的身份证号