@wener/common 1.0.5 → 2.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/lib/cn/ChineseResidentIdNo.js +41 -0
- package/lib/cn/ChineseResidentIdNo.mod.js +1 -0
- package/lib/cn/ChineseResidentIdNo.test.js +22 -0
- package/lib/cn/DivisionCode.js +214 -280
- package/lib/cn/DivisionCode.mod.js +1 -0
- package/lib/cn/DivisionCode.test.js +134 -0
- package/lib/cn/Mod11.js +86 -0
- package/lib/cn/Mod31.js +98 -0
- package/lib/cn/UnifiedSocialCreditCode.js +130 -109
- package/lib/cn/UnifiedSocialCreditCode.mod.js +1 -0
- package/lib/cn/UnifiedSocialCreditCode.test.js +16 -0
- package/lib/cn/index.js +1 -4
- package/lib/cn/mod.js +6 -0
- package/lib/cn/types.d.js +0 -2
- package/lib/consola/createStandardConsolaReporter.js +6 -6
- package/lib/consola/formatLogObject.js +147 -34
- package/lib/consola/index.js +0 -1
- package/lib/data/formatSort.js +5 -6
- package/lib/data/formatSort.test.js +34 -0
- package/lib/data/index.js +0 -1
- package/lib/data/maybeNumber.js +11 -5
- package/lib/data/parseSort.js +28 -22
- package/lib/data/parseSort.test.js +188 -0
- package/lib/data/resolvePagination.js +27 -16
- package/lib/data/resolvePagination.test.js +232 -0
- package/lib/data/types.d.js +0 -2
- package/lib/dayjs/dayjs.js +38 -0
- package/lib/dayjs/formatDuration.js +58 -0
- package/lib/dayjs/formatDuration.test.js +90 -0
- package/lib/dayjs/index.js +3 -0
- package/lib/dayjs/parseDuration.js +32 -0
- package/lib/decimal/index.js +1 -0
- package/lib/decimal/parseDecimal.js +13 -0
- package/lib/foundation/schema/SexType.js +14 -0
- package/lib/foundation/schema/index.js +1 -0
- package/lib/foundation/schema/parseSexType.js +18 -0
- package/lib/foundation/schema/types.js +5 -0
- package/lib/index.js +0 -1
- package/lib/jsonschema/JsonSchema.js +78 -52
- package/lib/jsonschema/JsonSchema.test.js +137 -0
- package/lib/jsonschema/index.js +0 -1
- package/lib/jsonschema/types.d.js +5 -3
- package/lib/meta/defineFileType.js +103 -20
- package/lib/meta/defineInit.js +250 -31
- package/lib/meta/defineMetadata.js +140 -24
- package/lib/meta/defineMetadata.test.js +13 -0
- package/lib/meta/index.js +0 -1
- package/lib/password/PHC.js +87 -63
- package/lib/password/PHC.test.js +539 -0
- package/lib/password/Password.js +295 -30
- package/lib/password/Password.test.js +362 -0
- package/lib/password/createArgon2PasswordAlgorithm.js +191 -35
- package/lib/password/createBase64PasswordAlgorithm.js +141 -8
- package/lib/password/createBcryptPasswordAlgorithm.js +168 -13
- package/lib/password/createPBKDF2PasswordAlgorithm.js +228 -46
- package/lib/password/createScryptPasswordAlgorithm.js +211 -55
- package/lib/password/index.js +0 -1
- package/lib/password/server/index.js +0 -1
- package/lib/resource/Identifiable.js +1 -0
- package/lib/resource/ListQuery.js +119 -0
- package/lib/resource/getTitleOfResource.js +10 -0
- package/lib/resource/index.js +2 -0
- package/lib/resource/schema/AnyResourceSchema.js +89 -0
- package/lib/resource/schema/BaseResourceSchema.js +29 -0
- package/lib/resource/schema/ResourceActionType.js +118 -0
- package/lib/resource/schema/ResourceStatus.js +93 -0
- package/lib/resource/schema/ResourceType.js +24 -0
- package/lib/resource/schema/index.js +5 -0
- package/lib/resource/schema/types.js +89 -0
- package/lib/resource/schema/types.test.js +14 -0
- package/lib/schema/SchemaRegistry.js +45 -0
- package/lib/schema/SchemaRegistry.mod.js +2 -0
- package/lib/schema/TypeSchema.d.js +1 -0
- package/lib/schema/createSchemaData.js +173 -0
- package/lib/schema/findJsonSchemaByPath.js +49 -0
- package/lib/schema/getSchemaCache.js +11 -0
- package/lib/schema/getSchemaOptions.js +24 -0
- package/lib/schema/index.js +6 -0
- package/lib/schema/toJsonSchema.js +441 -0
- package/lib/schema/toJsonSchema.test.js +27 -0
- package/lib/schema/validate.js +124 -0
- package/lib/tools/generateSchema.js +197 -39
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js +143 -55
- package/lib/utils/getEstimateProcessTime.js +20 -0
- package/lib/utils/index.js +1 -0
- package/package.json +38 -17
- package/src/cn/ChineseResidentIdNo.mod.ts +7 -0
- package/src/cn/ChineseResidentIdNo.test.ts +18 -0
- package/src/cn/ChineseResidentIdNo.ts +66 -0
- package/src/cn/DivisionCode.mod.ts +7 -0
- package/src/cn/DivisionCode.test.ts +3 -13
- package/src/cn/DivisionCode.ts +132 -195
- package/src/cn/{Mod11Checksum.ts → Mod11.ts} +3 -1
- package/src/cn/{Mod31Checksum.ts → Mod31.ts} +2 -0
- package/src/cn/UnifiedSocialCreditCode.mod.ts +7 -0
- package/src/cn/UnifiedSocialCreditCode.test.ts +2 -2
- package/src/cn/UnifiedSocialCreditCode.ts +105 -125
- package/src/cn/__snapshots__/ChineseResidentIdNo.test.ts.snap +14 -0
- package/src/cn/__snapshots__/UnifiedSocialCreditCode.test.ts.snap +18 -12
- package/src/cn/index.ts +1 -3
- package/src/cn/mod.ts +3 -0
- package/src/consola/formatLogObject.ts +12 -4
- package/src/data/maybeNumber.ts +5 -1
- package/src/data/resolvePagination.test.ts +1 -1
- package/src/data/resolvePagination.ts +18 -7
- package/src/data/types.d.ts +12 -0
- package/src/dayjs/dayjs.ts +40 -0
- package/src/dayjs/formatDuration.test.ts +14 -0
- package/src/dayjs/formatDuration.ts +86 -0
- package/src/dayjs/index.ts +3 -0
- package/src/dayjs/parseDuration.ts +40 -0
- package/src/decimal/index.ts +1 -0
- package/src/decimal/parseDecimal.ts +16 -0
- package/src/foundation/schema/SexType.ts +21 -0
- package/src/foundation/schema/index.ts +1 -0
- package/src/foundation/schema/parseSexType.ts +19 -0
- package/src/foundation/schema/types.ts +8 -0
- package/src/jsonschema/JsonSchema.test.ts +17 -0
- package/src/jsonschema/JsonSchema.ts +2 -2
- package/src/jsonschema/types.d.ts +63 -12
- package/src/password/Password.ts +2 -2
- package/src/resource/Identifiable.ts +3 -0
- package/src/resource/ListQuery.ts +53 -0
- package/src/resource/getTitleOfResource.tsx +6 -0
- package/src/resource/index.ts +4 -0
- package/src/resource/schema/AnyResourceSchema.ts +113 -0
- package/src/resource/schema/BaseResourceSchema.ts +32 -0
- package/src/resource/schema/ResourceActionType.ts +123 -0
- package/src/resource/schema/ResourceStatus.ts +94 -0
- package/src/resource/schema/ResourceType.ts +25 -0
- package/src/resource/schema/index.ts +5 -0
- package/src/resource/schema/types.test.ts +18 -0
- package/src/resource/schema/types.ts +105 -0
- package/src/schema/SchemaRegistry.mod.ts +1 -0
- package/src/schema/SchemaRegistry.ts +46 -0
- package/src/schema/TypeSchema.d.ts +32 -0
- package/src/schema/createSchemaData.ts +81 -0
- package/src/schema/findJsonSchemaByPath.ts +37 -0
- package/src/schema/getSchemaCache.ts +21 -0
- package/src/schema/getSchemaOptions.ts +24 -0
- package/src/schema/index.ts +7 -0
- package/src/schema/toJsonSchema.test.ts +37 -0
- package/src/schema/toJsonSchema.ts +200 -0
- package/src/schema/validate.ts +135 -0
- package/src/tools/generateSchema.ts +28 -28
- package/src/utils/getEstimateProcessTime.ts +36 -0
- package/src/utils/index.ts +1 -0
- package/lib/cn/DivisionCode.js.map +0 -1
- package/lib/cn/Mod11Checksum.js +0 -42
- package/lib/cn/Mod11Checksum.js.map +0 -1
- package/lib/cn/Mod31Checksum.js +0 -48
- package/lib/cn/Mod31Checksum.js.map +0 -1
- package/lib/cn/ResidentIdentityCardNumber.js +0 -50
- package/lib/cn/ResidentIdentityCardNumber.js.map +0 -1
- package/lib/cn/UnifiedSocialCreditCode.js.map +0 -1
- package/lib/cn/formatDate.js +0 -15
- package/lib/cn/formatDate.js.map +0 -1
- package/lib/cn/index.js.map +0 -1
- package/lib/cn/parseSex.js +0 -22
- package/lib/cn/parseSex.js.map +0 -1
- package/lib/cn/types.d.js.map +0 -1
- package/lib/consola/createStandardConsolaReporter.js.map +0 -1
- package/lib/consola/formatLogObject.js.map +0 -1
- package/lib/consola/index.js.map +0 -1
- package/lib/data/formatSort.js.map +0 -1
- package/lib/data/index.js.map +0 -1
- package/lib/data/maybeNumber.js.map +0 -1
- package/lib/data/parseSort.js.map +0 -1
- package/lib/data/resolvePagination.js.map +0 -1
- package/lib/data/types.d.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/jsonschema/JsonSchema.js.map +0 -1
- package/lib/jsonschema/index.js.map +0 -1
- package/lib/jsonschema/types.d.js.map +0 -1
- package/lib/meta/defineFileType.js.map +0 -1
- package/lib/meta/defineInit.js.map +0 -1
- package/lib/meta/defineMetadata.js.map +0 -1
- package/lib/meta/index.js.map +0 -1
- package/lib/password/PHC.js.map +0 -1
- package/lib/password/Password.js.map +0 -1
- package/lib/password/createArgon2PasswordAlgorithm.js.map +0 -1
- package/lib/password/createBase64PasswordAlgorithm.js.map +0 -1
- package/lib/password/createBcryptPasswordAlgorithm.js.map +0 -1
- package/lib/password/createPBKDF2PasswordAlgorithm.js.map +0 -1
- package/lib/password/createScryptPasswordAlgorithm.js.map +0 -1
- package/lib/password/index.js.map +0 -1
- package/lib/password/server/index.js.map +0 -1
- package/lib/search/AdvanceSearch.js +0 -10
- package/lib/search/AdvanceSearch.js.map +0 -1
- package/lib/search/formatAdvanceSearch.js +0 -64
- package/lib/search/formatAdvanceSearch.js.map +0 -1
- package/lib/search/index.js +0 -2
- package/lib/search/index.js.map +0 -1
- package/lib/search/optimizeAdvanceSearch.js +0 -89
- package/lib/search/optimizeAdvanceSearch.js.map +0 -1
- package/lib/search/parseAdvanceSearch.js +0 -20
- package/lib/search/parseAdvanceSearch.js.map +0 -1
- package/lib/search/parser.d.js +0 -3
- package/lib/search/parser.d.js.map +0 -1
- package/lib/search/parser.js +0 -3065
- package/lib/search/parser.js.map +0 -1
- package/lib/search/types.d.js +0 -3
- package/lib/search/types.d.js.map +0 -1
- package/lib/tools/generateSchema.js.map +0 -1
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js.map +0 -1
- package/src/cn/ResidentIdentityCardNumber.test.ts +0 -17
- package/src/cn/ResidentIdentityCardNumber.ts +0 -96
- package/src/cn/__snapshots__/ResidentIdentityCardNumber.test.ts.snap +0 -15
- package/src/cn/formatDate.ts +0 -12
- package/src/cn/parseSex.ts +0 -13
- package/src/search/AdvanceSearch.test.ts +0 -149
- package/src/search/AdvanceSearch.ts +0 -14
- package/src/search/Makefile +0 -2
- package/src/search/__snapshots__/AdvanceSearch.test.ts.snap +0 -675
- package/src/search/formatAdvanceSearch.ts +0 -52
- package/src/search/index.ts +0 -1
- package/src/search/optimizeAdvanceSearch.ts +0 -77
- package/src/search/parseAdvanceSearch.ts +0 -23
- package/src/search/parser.d.ts +0 -8
- package/src/search/parser.js +0 -2794
- package/src/search/parser.peggy +0 -237
- package/src/search/types.d.ts +0 -45
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
import { SexType, SexTypeSchema } from "../foundation/schema/index.js";
|
|
3
|
+
import { Mod11 } from "./Mod11.js";
|
|
4
|
+
export var ChineseResidentIdNoRegex = RegExp("^(?<division>[1-9]\\d{5})(?<year>(18|19|20)\\d{2})(?<month>0[1-9]|1[0-2])(?<day>0[1-9]|[12]\\d|3[01])(?<sequence>\\d{3})(?<checkDigit>[0-9Xx])$");
|
|
5
|
+
export var ParsedChineseResidentIdNoSchema = z.object({
|
|
6
|
+
raw: z.string().regex(ChineseResidentIdNoRegex, "\u65E0\u6548\u768418\u4F4D\u8EAB\u4EFD\u8BC1\u53F7\u7801\u683C\u5F0F").describe("\u8EAB\u4EFD\u8BC1\u53F7\u7801"),
|
|
7
|
+
addressCode: z.string().length(6).describe("\u5730\u5740\u7801 "),
|
|
8
|
+
birthDate: z.iso.date().describe("\u51FA\u751F\u65E5\u671F"),
|
|
9
|
+
sequence: z.int().max(999).min(0).describe("\u987A\u5E8F\u7801"),
|
|
10
|
+
checkDigit: z.int().min(0).max(10).describe("\u6821\u9A8C\u7801"),
|
|
11
|
+
sex: SexTypeSchema.describe("\u6027\u522B"),
|
|
12
|
+
age: z.number().optional(),
|
|
13
|
+
valid: z.boolean().optional().describe("\u662F\u5426\u6709\u6548")
|
|
14
|
+
}).describe("\u5C45\u6C11\u8EAB\u4EFD\u8BC1\u53F7\u7801\u89E3\u6790\u5185\u5BB9");
|
|
15
|
+
export function parseChineseResidentIdNo(idNo) {
|
|
16
|
+
var reg = ChineseResidentIdNoRegex;
|
|
17
|
+
var match = idNo.match(reg);
|
|
18
|
+
if (!match || !match.groups) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
var _match_groups = match.groups, division = _match_groups.division, year = _match_groups.year, month = _match_groups.month, day = _match_groups.day, sequence = _match_groups.sequence, checkDigit = _match_groups.checkDigit;
|
|
22
|
+
var seq = parseInt(sequence, 10);
|
|
23
|
+
return {
|
|
24
|
+
raw: idNo,
|
|
25
|
+
addressCode: division,
|
|
26
|
+
birthDate: "".concat(year, "-").concat(month, "-").concat(day),
|
|
27
|
+
sequence: seq,
|
|
28
|
+
checkDigit: checkDigit.toUpperCase() === "X" ? 10 : parseInt(checkDigit),
|
|
29
|
+
sex: seq % 2 === 0 ? SexType.Male : SexType.Female,
|
|
30
|
+
age: new Date().getFullYear() - parseInt(year, 10),
|
|
31
|
+
valid: Mod11.validate(idNo)
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export function formatChineseResidentIdNo(param) {
|
|
35
|
+
var addressCode = param.addressCode, birthDate = param.birthDate, sequence = param.sequence, checkDigit = param.checkDigit;
|
|
36
|
+
var date = typeof birthDate === "string" ? birthDate.replace(/-/g, "") : "".concat(birthDate.getFullYear()).concat(String(birthDate.getMonth() + 1).padStart(2, "0")).concat(String(birthDate.getDate()).padStart(2, "0"));
|
|
37
|
+
var seq = String(sequence).padStart(3, "0");
|
|
38
|
+
var major = "".concat(addressCode).concat(date).concat(seq);
|
|
39
|
+
var check = typeof checkDigit === "number" ? checkDigit === 10 ? "X" : String(checkDigit) : (checkDigit === null || checkDigit === void 0 ? void 0 : checkDigit.toUpperCase()) || Mod11.compute(major);
|
|
40
|
+
return "".concat(major).concat(check);
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ChineseResidentIdNoRegex as regex, parseChineseResidentIdNo as parse, formatChineseResidentIdNo as format, ParsedChineseResidentIdNoSchema as ResultSchema } from "./ChineseResidentIdNo.js";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { ChineseResidentIdNo } from "./mod.js";
|
|
3
|
+
describe("ChineseResidentIdNo", function () {
|
|
4
|
+
it("should parse", function () {
|
|
5
|
+
for (var _i = 0, _iter = [
|
|
6
|
+
"11010519491231002X"
|
|
7
|
+
]; _i < _iter.length; _i++) {
|
|
8
|
+
var a = _iter[_i];
|
|
9
|
+
var out = ChineseResidentIdNo.parse(a);
|
|
10
|
+
expect(out).toBeTruthy();
|
|
11
|
+
expect(ChineseResidentIdNo.format(out)).toBe(a);
|
|
12
|
+
expect(out).toMatchSnapshot();
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
it("should format with partial", function () {
|
|
16
|
+
expect(ChineseResidentIdNo.format({
|
|
17
|
+
addressCode: "110105",
|
|
18
|
+
birthDate: new Date("1949-12-31"),
|
|
19
|
+
sequence: 2
|
|
20
|
+
})).toBe("11010519491231002X");
|
|
21
|
+
});
|
|
22
|
+
});
|
package/lib/cn/DivisionCode.js
CHANGED
|
@@ -1,224 +1,230 @@
|
|
|
1
|
-
|
|
1
|
+
import z from 'zod/v4';
|
|
2
|
+
export var DivisionLevel = Object.freeze({
|
|
3
|
+
__proto__: null,
|
|
4
|
+
Province: 'Province',
|
|
5
|
+
City: 'City',
|
|
6
|
+
County: 'County',
|
|
7
|
+
Town: 'Town',
|
|
8
|
+
Village: 'Village'
|
|
9
|
+
});
|
|
10
|
+
var DivisionLevels = [
|
|
11
|
+
DivisionLevel.Province,
|
|
12
|
+
DivisionLevel.City,
|
|
13
|
+
DivisionLevel.County,
|
|
14
|
+
DivisionLevel.Town,
|
|
15
|
+
DivisionLevel.Village
|
|
16
|
+
];
|
|
17
|
+
export var DivisionLevelSchema = z.union([
|
|
18
|
+
z.literal(DivisionLevel.Province).describe('省级').meta({
|
|
19
|
+
ordinal: 1
|
|
20
|
+
}),
|
|
21
|
+
z.literal(DivisionLevel.City).describe('地级').meta({
|
|
22
|
+
ordinal: 2
|
|
23
|
+
}),
|
|
24
|
+
z.literal(DivisionLevel.County).describe('县级').meta({
|
|
25
|
+
ordinal: 3
|
|
26
|
+
}),
|
|
27
|
+
z.literal(DivisionLevel.Town).describe('乡镇级').meta({
|
|
28
|
+
ordinal: 4
|
|
29
|
+
}),
|
|
30
|
+
z.literal(DivisionLevel.Village).describe('村级').meta({
|
|
31
|
+
ordinal: 5
|
|
32
|
+
})
|
|
33
|
+
]).describe('行政区划级别');
|
|
34
|
+
export var ParsedDivisionCodeSchema = z.object({
|
|
35
|
+
code: z.string().describe('行政区划代码'),
|
|
36
|
+
name: z.string().describe('行政区划名称'),
|
|
37
|
+
level: DivisionLevelSchema,
|
|
38
|
+
codes: z.string().array(),
|
|
39
|
+
names: z.string().array(),
|
|
40
|
+
latitude: z.number().optional().describe('纬度'),
|
|
41
|
+
longitude: z.number().optional().describe('经度')
|
|
42
|
+
});
|
|
43
|
+
export var DivisionCodeRegex = RegExp("^(?<province>\\d{2})(?<city>\\d{2})?(?<county>\\d{2})?(?<town>\\d{3})?(?<village>\\d{3})?$");
|
|
44
|
+
var CodeNames = [
|
|
45
|
+
{
|
|
46
|
+
value: '11',
|
|
47
|
+
name: '北京市'
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
value: '12',
|
|
51
|
+
name: '天津市'
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
value: '13',
|
|
55
|
+
name: '河北省'
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
value: '14',
|
|
59
|
+
name: '山西省'
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
value: '15',
|
|
63
|
+
name: '内蒙古自治区'
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
value: '21',
|
|
67
|
+
name: '辽宁省'
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
value: '22',
|
|
71
|
+
name: '吉林省'
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
value: '23',
|
|
75
|
+
name: '黑龙江省'
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
value: '31',
|
|
79
|
+
name: '上海市'
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
value: '32',
|
|
83
|
+
name: '江苏省'
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
value: '33',
|
|
87
|
+
name: '浙江省'
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
value: '34',
|
|
91
|
+
name: '安徽省'
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
value: '35',
|
|
95
|
+
name: '福建省'
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
value: '36',
|
|
99
|
+
name: '江西省'
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
value: '37',
|
|
103
|
+
name: '山东省'
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
value: '41',
|
|
107
|
+
name: '河南省'
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
value: '42',
|
|
111
|
+
name: '湖北省'
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
value: '43',
|
|
115
|
+
name: '湖南省'
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
value: '44',
|
|
119
|
+
name: '广东省'
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
value: '45',
|
|
123
|
+
name: '广西壮族自治区'
|
|
124
|
+
},
|
|
2
125
|
{
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
length: 2,
|
|
6
|
-
size: 2,
|
|
7
|
-
label: '省'
|
|
126
|
+
value: '46',
|
|
127
|
+
name: '海南省'
|
|
8
128
|
},
|
|
9
129
|
{
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
length: 4,
|
|
13
|
-
size: 2,
|
|
14
|
-
label: '市'
|
|
130
|
+
value: '50',
|
|
131
|
+
name: '重庆市'
|
|
15
132
|
},
|
|
16
133
|
{
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
length: 6,
|
|
20
|
-
size: 2,
|
|
21
|
-
label: '区县'
|
|
134
|
+
value: '51',
|
|
135
|
+
name: '四川省'
|
|
22
136
|
},
|
|
23
137
|
{
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
length: 9,
|
|
27
|
-
size: 3,
|
|
28
|
-
label: '乡镇'
|
|
138
|
+
value: '52',
|
|
139
|
+
name: '贵州省'
|
|
29
140
|
},
|
|
30
141
|
{
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
142
|
+
value: '53',
|
|
143
|
+
name: '云南省'
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
value: '54',
|
|
147
|
+
name: '西藏自治区'
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
value: '61',
|
|
151
|
+
name: '陕西省'
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
value: '62',
|
|
155
|
+
name: '甘肃省'
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
value: '63',
|
|
159
|
+
name: '青海省'
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
value: '64',
|
|
163
|
+
name: '宁夏回族自治区'
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
value: '65',
|
|
167
|
+
name: '新疆维吾尔自治区'
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
value: '71',
|
|
171
|
+
name: '台湾省'
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
value: '81',
|
|
175
|
+
name: '香港特别行政区'
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
value: '82',
|
|
179
|
+
name: '澳门特别行政区'
|
|
36
180
|
}
|
|
37
181
|
];
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
{
|
|
63
|
-
value: '14',
|
|
64
|
-
label: '山西省'
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
value: '15',
|
|
68
|
-
label: '内蒙古自治区'
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
value: '21',
|
|
72
|
-
label: '辽宁省'
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
value: '22',
|
|
76
|
-
label: '吉林省'
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
value: '23',
|
|
80
|
-
label: '黑龙江省'
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
value: '31',
|
|
84
|
-
label: '上海市'
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
value: '32',
|
|
88
|
-
label: '江苏省'
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
value: '33',
|
|
92
|
-
label: '浙江省'
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
value: '34',
|
|
96
|
-
label: '安徽省'
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
value: '35',
|
|
100
|
-
label: '福建省'
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
value: '36',
|
|
104
|
-
label: '江西省'
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
value: '37',
|
|
108
|
-
label: '山东省'
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
value: '41',
|
|
112
|
-
label: '河南省'
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
value: '42',
|
|
116
|
-
label: '湖北省'
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
value: '43',
|
|
120
|
-
label: '湖南省'
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
value: '44',
|
|
124
|
-
label: '广东省'
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
value: '45',
|
|
128
|
-
label: '广西壮族自治区'
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
value: '46',
|
|
132
|
-
label: '海南省'
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
value: '50',
|
|
136
|
-
label: '重庆市'
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
value: '51',
|
|
140
|
-
label: '四川省'
|
|
141
|
-
},
|
|
142
|
-
{
|
|
143
|
-
value: '52',
|
|
144
|
-
label: '贵州省'
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
value: '53',
|
|
148
|
-
label: '云南省'
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
value: '54',
|
|
152
|
-
label: '西藏自治区'
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
value: '61',
|
|
156
|
-
label: '陕西省'
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
value: '62',
|
|
160
|
-
label: '甘肃省'
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
value: '63',
|
|
164
|
-
label: '青海省'
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
value: '64',
|
|
168
|
-
label: '宁夏回族自治区'
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
value: '65',
|
|
172
|
-
label: '新疆维吾尔自治区'
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
value: '71',
|
|
176
|
-
label: '台湾省'
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
value: '81',
|
|
180
|
-
label: '香港特别行政区'
|
|
181
|
-
},
|
|
182
|
-
{
|
|
183
|
-
value: '82',
|
|
184
|
-
label: '澳门特别行政区'
|
|
182
|
+
export function parseDivisionCode(code) {
|
|
183
|
+
var match = DivisionCodeRegex.exec(code);
|
|
184
|
+
if (!match) {
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
var _match_groups;
|
|
188
|
+
var _ref = (_match_groups = match.groups) !== null && _match_groups !== void 0 ? _match_groups : {}, province = _ref.province, city = _ref.city, county = _ref.county, town = _ref.town, village = _ref.village;
|
|
189
|
+
if (!province) {
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
|
192
|
+
var codes = [
|
|
193
|
+
province,
|
|
194
|
+
city,
|
|
195
|
+
county,
|
|
196
|
+
town,
|
|
197
|
+
village
|
|
198
|
+
].filter(Boolean);
|
|
199
|
+
var names = [];
|
|
200
|
+
{
|
|
201
|
+
var name = CodeNames.find(function(cn) {
|
|
202
|
+
return cn.value === province;
|
|
203
|
+
});
|
|
204
|
+
if (name) {
|
|
205
|
+
names.push(name.name);
|
|
185
206
|
}
|
|
186
|
-
];
|
|
187
|
-
function parse(code) {
|
|
188
|
-
if (!code) return;
|
|
189
|
-
code = String(code);
|
|
190
|
-
const match = DivisionCode.regex.exec(code);
|
|
191
|
-
if (!match) return;
|
|
192
|
-
const { province, city, county, town, village } = match.groups ?? {};
|
|
193
|
-
if (!province) return;
|
|
194
|
-
let codes = [
|
|
195
|
-
province,
|
|
196
|
-
city,
|
|
197
|
-
county,
|
|
198
|
-
town,
|
|
199
|
-
village
|
|
200
|
-
].filter(Boolean);
|
|
201
|
-
return {
|
|
202
|
-
province,
|
|
203
|
-
city,
|
|
204
|
-
county,
|
|
205
|
-
town,
|
|
206
|
-
village,
|
|
207
|
-
codes: codes,
|
|
208
|
-
level: codes.length
|
|
209
|
-
};
|
|
210
207
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
208
|
+
var level = DivisionLevels[codes.length - 1];
|
|
209
|
+
return {
|
|
210
|
+
code: code,
|
|
211
|
+
name: names.join(''),
|
|
212
|
+
level: level,
|
|
213
|
+
codes: codes,
|
|
214
|
+
names: names
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
export function formatDivisionCode(param) {
|
|
218
|
+
var province = param.province, city = param.city, county = param.county, town = param.town, village = param.village, _param_codes = param.codes, codes = _param_codes === void 0 ? [] : _param_codes;
|
|
219
|
+
if (!codes.length) {
|
|
220
|
+
for(var i = 0; i < [
|
|
215
221
|
province,
|
|
216
222
|
city,
|
|
217
223
|
county,
|
|
218
224
|
town,
|
|
219
225
|
village
|
|
220
226
|
].length; i++){
|
|
221
|
-
|
|
227
|
+
var x = [
|
|
222
228
|
province,
|
|
223
229
|
city,
|
|
224
230
|
county,
|
|
@@ -228,84 +234,12 @@ const DivisionCodeLevels = [
|
|
|
228
234
|
if (x === undefined || x === null || x === '') {
|
|
229
235
|
break;
|
|
230
236
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
DivisionCode.format = format;
|
|
237
|
-
// export function random(level: DivisionCodeLevel = 'County'): string {
|
|
238
|
-
// const l = DivisionCodeLevels.find((v) => v.code === level) || DivisionCodeLevels[2];
|
|
239
|
-
// const l1 = randomPick(provinces);
|
|
240
|
-
// if (l.level === 1) {
|
|
241
|
-
// return String(l1[0]);
|
|
242
|
-
// }
|
|
243
|
-
// return l1 + String(Math.floor(Math.random() * parseFloat(`1e${l.length - 2}`) - 1));
|
|
244
|
-
// }
|
|
245
|
-
})(DivisionCode || (DivisionCode = {}));
|
|
246
|
-
// export type DivisionCodeLevel = 'Village' | 'Town' | 'County' | 'City' | 'Province';
|
|
247
|
-
// export interface ParsedDivisionCode {
|
|
248
|
-
// level: DivisionCodeLevel;
|
|
249
|
-
// code: string;
|
|
250
|
-
// name?: string;
|
|
251
|
-
// fullName?: string;
|
|
252
|
-
// names: string[];
|
|
253
|
-
// // 村级(村委会、居委会)
|
|
254
|
-
// // 12 位
|
|
255
|
-
// village?: CodeName;
|
|
256
|
-
// // 乡级(乡镇、街道)
|
|
257
|
-
// // 9 位
|
|
258
|
-
// town?: CodeName;
|
|
259
|
-
// // 县级(区县)
|
|
260
|
-
// // 6 位 - 常用 - 2985 个
|
|
261
|
-
// county?: CodeName;
|
|
262
|
-
// // 地级(城市)
|
|
263
|
-
// // 4 位 - 343 个
|
|
264
|
-
// city?: CodeName;
|
|
265
|
-
// // 省级(省份、直辖市、自治区)
|
|
266
|
-
// // 2 位 - 32 个
|
|
267
|
-
// province: CodeName;
|
|
268
|
-
//
|
|
269
|
-
// children?: Array<{ code: string; name?: string }>;
|
|
270
|
-
// }
|
|
271
|
-
// export interface CodeName {
|
|
272
|
-
// code: string;
|
|
273
|
-
// name: string;
|
|
274
|
-
// }
|
|
275
|
-
// export function getSimpleProvinceLabel(value: string) {
|
|
276
|
-
// if (!value) {
|
|
277
|
-
// return;
|
|
278
|
-
// }
|
|
279
|
-
// let label = value;
|
|
280
|
-
// if (/[0-9]/.test(label)) {
|
|
281
|
-
// label = label.slice(0, 2);
|
|
282
|
-
// label = options.find((v) => v.value === label)?.label || label;
|
|
283
|
-
// }
|
|
284
|
-
// return label.replace(/省|市|(回族|维吾尔|壮族)?自治区|特别行政区$/, '');
|
|
285
|
-
// }
|
|
286
|
-
export function randomPick(s) {
|
|
287
|
-
return s[Math.floor(Math.random() * s.length)];
|
|
288
|
-
}
|
|
289
|
-
function lookup(opts) {
|
|
290
|
-
const { values, root } = opts;
|
|
291
|
-
const found = [];
|
|
292
|
-
let currentLevel = root;
|
|
293
|
-
for (const v of values){
|
|
294
|
-
const node = currentLevel.find((n)=>n.value === v);
|
|
295
|
-
if (!node) {
|
|
296
|
-
break;
|
|
297
|
-
}
|
|
298
|
-
found.push(node);
|
|
299
|
-
if (node.children) {
|
|
300
|
-
currentLevel = node.children;
|
|
301
|
-
} else {
|
|
302
|
-
break;
|
|
237
|
+
var size = 2;
|
|
238
|
+
if (i > 2) {
|
|
239
|
+
size = 3;
|
|
240
|
+
}
|
|
241
|
+
codes.push(String(x).padStart(size, '0').slice(0, size));
|
|
303
242
|
}
|
|
304
243
|
}
|
|
305
|
-
return
|
|
306
|
-
found
|
|
307
|
-
};
|
|
244
|
+
return codes.join('');
|
|
308
245
|
}
|
|
309
|
-
export var DivisionCode;
|
|
310
|
-
|
|
311
|
-
//# sourceMappingURL=DivisionCode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DivisionCodeRegex as regex, ParsedDivisionCodeSchema as ResultSchema, parseDivisionCode as parse, formatDivisionCode as format } from "./DivisionCode.js";
|