identity-number 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 hzqhxy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,56 @@
1
+ ### Identity
2
+
3
+ #### 介绍
4
+
5
+ 这是一个用于处理中国身份证号码的 TypeScript 类。我来详细解释其功能和实现:
6
+
7
+ #### 基本结构
8
+
9
+ 类名为 Identity,用于处理身份证号码
10
+ 包含两个私有属性:\_id(存储身份证号)和\_isValid(存储验证结果)
11
+
12
+ #### 主要功能
13
+
14
+ - 身份证号码验证
15
+ - 性别判断
16
+ - 出生日期计算
17
+ - 年龄计算
18
+ - 地区信息获取
19
+ - 星座计算
20
+ - 身份证号脱敏
21
+ > 验证机制
22
+ - 类实现了三层验证:
23
+ 1. 格式验证:使用正则表达式检查基本格式
24
+ 2. 日期验证:检查身份证中的日期是否有效
25
+ 3. 校验码验证:使用加权求和算法验证最后一位校验码
26
+
27
+ #### 重要方法说明:
28
+
29
+ constructor:构造函数,接收身份证号并立即验证
30
+ isValidDate:验证身份证中的日期是否有效
31
+ isValidCheckCode:验证校验码是否正确
32
+ validateId:综合验证身份证号
33
+ gender:获取性别(奇数为男,偶数为女)
34
+ birth:获取出生日期字符串
35
+ age:计算当前年龄
36
+ regionCode:获取地区编码
37
+ constellation:计算星座
38
+ desensitization:身份证号脱敏处理
39
+
40
+ #### 注意事项:
41
+
42
+ 所有 getter 方法在返回值前都会调用 ensureValid()确保身份证号有效
43
+ 日期计算考虑了闰年等特殊情况
44
+ 年龄计算精确到天
45
+ 脱敏处理可自定义脱敏字符和范围
46
+
47
+ #### 使用示例:
48
+
49
+ ```ts
50
+ const id = new Identity("11010519491231002X");
51
+ console.log(id.gender); // 输出性别
52
+ console.log(id.birth); // 输出出生日期
53
+ console.log(id.age); // 输出年龄
54
+ console.log(id.regionCode); // 输出地区编码
55
+ console.log(id.desensitization()); // 输出脱敏后的身份证号
56
+ ```