@wener/common 1.0.3 → 1.0.5
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/DivisionCode.js.map +1 -1
- package/lib/cn/Mod11Checksum.js.map +1 -1
- package/lib/cn/Mod31Checksum.js.map +1 -1
- package/lib/cn/ResidentIdentityCardNumber.js.map +1 -1
- package/lib/cn/UnifiedSocialCreditCode.js.map +1 -1
- package/lib/cn/formatDate.js.map +1 -1
- package/lib/cn/parseSex.js.map +1 -1
- package/lib/cn/types.d.js.map +1 -1
- package/lib/consola/createStandardConsolaReporter.js +18 -0
- package/lib/consola/createStandardConsolaReporter.js.map +1 -0
- package/lib/consola/formatLogObject.js +125 -0
- package/lib/consola/formatLogObject.js.map +1 -0
- package/lib/consola/index.js +3 -0
- package/lib/consola/index.js.map +1 -0
- package/lib/data/formatSort.js +15 -0
- package/lib/data/formatSort.js.map +1 -0
- package/lib/data/index.js +4 -0
- package/lib/data/index.js.map +1 -0
- package/lib/data/maybeNumber.js +22 -0
- package/lib/data/maybeNumber.js.map +1 -0
- package/lib/data/parseSort.js +95 -0
- package/lib/data/parseSort.js.map +1 -0
- package/lib/data/resolvePagination.js +36 -0
- package/lib/data/resolvePagination.js.map +1 -0
- package/lib/data/types.d.js +3 -0
- package/lib/data/types.d.js.map +1 -0
- package/lib/index.js +6 -2
- package/lib/index.js.map +1 -1
- package/lib/jsonschema/JsonSchema.js +6 -6
- package/lib/jsonschema/JsonSchema.js.map +1 -1
- package/lib/jsonschema/types.d.js.map +1 -1
- package/lib/meta/defineFileType.js.map +1 -1
- package/lib/meta/defineInit.js.map +1 -1
- package/lib/meta/defineMetadata.js.map +1 -1
- package/lib/password/PHC.js +8 -8
- package/lib/password/PHC.js.map +1 -1
- package/lib/password/Password.js.map +1 -1
- package/lib/password/createArgon2PasswordAlgorithm.js.map +1 -1
- package/lib/password/createBase64PasswordAlgorithm.js.map +1 -1
- package/lib/password/createBcryptPasswordAlgorithm.js.map +1 -1
- package/lib/password/createPBKDF2PasswordAlgorithm.js.map +1 -1
- package/lib/password/createScryptPasswordAlgorithm.js.map +1 -1
- package/lib/search/AdvanceSearch.js.map +1 -1
- package/lib/search/formatAdvanceSearch.js.map +1 -1
- package/lib/search/optimizeAdvanceSearch.js.map +1 -1
- package/lib/search/parseAdvanceSearch.js.map +1 -1
- package/lib/search/parser.d.js.map +1 -1
- package/lib/search/types.d.js.map +1 -1
- package/lib/tools/generateSchema.js +43 -0
- package/lib/tools/generateSchema.js.map +1 -0
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js.map +1 -1
- package/package.json +19 -5
- package/src/cn/DivisionCode.test.ts +38 -45
- package/src/cn/DivisionCode.ts +140 -184
- package/src/cn/Mod11Checksum.ts +17 -17
- package/src/cn/Mod31Checksum.ts +25 -25
- package/src/cn/ResidentIdentityCardNumber.test.ts +12 -16
- package/src/cn/ResidentIdentityCardNumber.ts +82 -82
- package/src/cn/UnifiedSocialCreditCode.test.ts +11 -11
- package/src/cn/UnifiedSocialCreditCode.ts +115 -120
- package/src/cn/__snapshots__/ResidentIdentityCardNumber.test.ts.snap +1 -1
- package/src/cn/formatDate.ts +10 -10
- package/src/cn/parseSex.ts +11 -25
- package/src/cn/types.d.ts +43 -43
- package/src/consola/createStandardConsolaReporter.ts +31 -0
- package/src/consola/formatLogObject.ts +171 -0
- package/src/consola/index.ts +2 -0
- package/src/data/formatSort.test.ts +13 -0
- package/src/data/formatSort.ts +18 -0
- package/src/data/index.ts +5 -0
- package/src/data/maybeNumber.ts +23 -0
- package/src/data/parseSort.test.ts +67 -0
- package/src/data/parseSort.ts +108 -0
- package/src/data/resolvePagination.test.ts +58 -0
- package/src/data/resolvePagination.ts +60 -0
- package/src/data/types.d.ts +33 -0
- package/src/index.ts +8 -2
- package/src/jsonschema/JsonSchema.test.ts +13 -22
- package/src/jsonschema/JsonSchema.ts +146 -178
- package/src/jsonschema/types.d.ts +151 -161
- package/src/meta/defineFileType.tsx +54 -54
- package/src/meta/defineInit.ts +32 -53
- package/src/meta/defineMetadata.test.ts +5 -7
- package/src/meta/defineMetadata.ts +28 -46
- package/src/password/PHC.test.ts +186 -277
- package/src/password/PHC.ts +243 -243
- package/src/password/Password.test.ts +38 -50
- package/src/password/Password.ts +73 -95
- package/src/password/createArgon2PasswordAlgorithm.ts +65 -69
- package/src/password/createBase64PasswordAlgorithm.ts +9 -9
- package/src/password/createBcryptPasswordAlgorithm.ts +20 -22
- package/src/password/createPBKDF2PasswordAlgorithm.ts +49 -61
- package/src/password/createScryptPasswordAlgorithm.ts +48 -59
- package/src/search/AdvanceSearch.test.ts +136 -143
- package/src/search/AdvanceSearch.ts +6 -6
- package/src/search/formatAdvanceSearch.ts +44 -53
- package/src/search/optimizeAdvanceSearch.ts +70 -83
- package/src/search/parseAdvanceSearch.ts +16 -19
- package/src/search/parser.d.ts +3 -3
- package/src/search/types.d.ts +28 -54
- package/src/tools/generateSchema.ts +39 -0
- package/src/tools/renderJsonSchemaToMarkdownDoc.ts +69 -69
- package/lib/normalizePagination.js +0 -14
- package/lib/normalizePagination.js.map +0 -1
- package/lib/parseSort.js +0 -106
- package/lib/parseSort.js.map +0 -1
- package/src/normalizePagination.ts +0 -25
- package/src/parseSort.test.ts +0 -42
- package/src/parseSort.ts +0 -133
package/src/cn/Mod31Checksum.ts
CHANGED
|
@@ -4,33 +4,33 @@
|
|
|
4
4
|
* Mod31-3
|
|
5
5
|
*/
|
|
6
6
|
export class Mod31Checksum {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
weights = [1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28];
|
|
8
|
+
chars = '0123456789ABCDEFGHJKLMNPQRTUWXY';
|
|
9
|
+
numbers: Record<string, number> = this.chars.split('').reduce(
|
|
10
|
+
(acc, cur, i) => {
|
|
11
|
+
acc[cur] = i;
|
|
12
|
+
return acc;
|
|
13
|
+
},
|
|
14
|
+
{} as Record<string, number>,
|
|
15
|
+
);
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
toChar(n: number) {
|
|
18
|
+
return this.chars[n];
|
|
19
|
+
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
toNumber(c: string) {
|
|
22
|
+
return this.numbers[c];
|
|
23
|
+
}
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
validate(s: string) {
|
|
26
|
+
return s.at(-1) === this.compute(s.slice(0, s.length - 1));
|
|
27
|
+
}
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
compute(s: string) {
|
|
30
|
+
let sum = 0;
|
|
31
|
+
for (let i = 0; i < s.length; i++) {
|
|
32
|
+
sum += this.numbers[s[i]] * this.weights[i];
|
|
33
|
+
}
|
|
34
|
+
return this.toChar(31 - (sum % 31));
|
|
35
|
+
}
|
|
36
36
|
}
|
|
@@ -2,20 +2,16 @@ import { describe, expect, it } from 'vitest';
|
|
|
2
2
|
import { ResidentIdentityCardNumber } from './ResidentIdentityCardNumber';
|
|
3
3
|
|
|
4
4
|
describe('ResidentIdentityCardNumber', () => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
sequence: 2,
|
|
18
|
-
}),
|
|
19
|
-
).toBe('11010519491231002X');
|
|
20
|
-
});
|
|
5
|
+
it('should parse', () => {
|
|
6
|
+
for (const a of ['11010519491231002X']) {
|
|
7
|
+
let out = ResidentIdentityCardNumber.parse(a);
|
|
8
|
+
expect(ResidentIdentityCardNumber.format(out)).toBe(a);
|
|
9
|
+
expect(out).toMatchSnapshot();
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
it('should format with partial', () => {
|
|
13
|
+
expect(
|
|
14
|
+
ResidentIdentityCardNumber.format({ division: '110105', birthDate: new Date('1949-12-31'), sequence: 2 }),
|
|
15
|
+
).toBe('11010519491231002X');
|
|
16
|
+
});
|
|
21
17
|
});
|
|
@@ -2,95 +2,95 @@ import { formatDate } from './formatDate';
|
|
|
2
2
|
import { Mod11Checksum } from './Mod11Checksum';
|
|
3
3
|
|
|
4
4
|
export namespace ResidentIdentityCardNumber {
|
|
5
|
-
|
|
5
|
+
export const Checksum = new Mod11Checksum();
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
/*
|
|
8
8
|
export const length = 18;
|
|
9
9
|
export const pattern = /^\d{6}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[0-9Xx]$/;
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
12
|
+
export function parse(s: string): ParsedResidentIdentityCardNumber {
|
|
13
|
+
const division = s.slice(0, 6);
|
|
14
|
+
const birthDate = s.slice(6, 14);
|
|
15
|
+
const sequence = parseInt(s.slice(14, 17), 10);
|
|
16
|
+
const checksum = s.slice(17, 18);
|
|
17
|
+
const valid = Checksum.validate(s);
|
|
18
|
+
const sex = sequence % 2 === 1 ? 'Male' : 'Female';
|
|
19
|
+
return {
|
|
20
|
+
division,
|
|
21
|
+
birthDate,
|
|
22
|
+
sequence,
|
|
23
|
+
checksum,
|
|
24
|
+
valid,
|
|
25
|
+
sex,
|
|
26
|
+
male: sex === 'Male',
|
|
27
|
+
female: sex === 'Female',
|
|
28
|
+
age: new Date().getFullYear() - parseInt(birthDate.slice(0, 4), 10),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
32
|
+
export function format({
|
|
33
|
+
division,
|
|
34
|
+
birthDate,
|
|
35
|
+
sequence,
|
|
36
|
+
checksum,
|
|
37
|
+
}: {
|
|
38
|
+
division: string;
|
|
39
|
+
birthDate: string | Date;
|
|
40
|
+
sequence: number | string;
|
|
41
|
+
checksum?: string;
|
|
42
|
+
}) {
|
|
43
|
+
if (typeof birthDate !== 'string') {
|
|
44
|
+
birthDate = formatDate(birthDate, 'yyyyMMDD');
|
|
45
|
+
}
|
|
46
|
+
if (birthDate.includes('-')) {
|
|
47
|
+
birthDate = birthDate.replace(/-/g, '');
|
|
48
|
+
}
|
|
49
|
+
typeof sequence === 'number' && (sequence = sequence.toString());
|
|
50
|
+
sequence = sequence.padStart(3, '0');
|
|
51
|
+
const base = [division, birthDate, sequence].join('');
|
|
52
|
+
if (base.length !== 17) throw new Error('Invalid params');
|
|
53
|
+
checksum ||= Checksum.compute(base);
|
|
54
|
+
return base + checksum;
|
|
55
|
+
}
|
|
56
56
|
}
|
|
57
57
|
export interface ParsedResidentIdentityCardNumber {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
58
|
+
/**
|
|
59
|
+
* @title 行政区划代码
|
|
60
|
+
*/
|
|
61
|
+
division: string;
|
|
62
|
+
/**
|
|
63
|
+
* @title 出生日期
|
|
64
|
+
* 格式 yyyyMMDD
|
|
65
|
+
*/
|
|
66
|
+
birthDate: string;
|
|
67
|
+
/**
|
|
68
|
+
* @title 顺序码
|
|
69
|
+
*/
|
|
70
|
+
sequence: number;
|
|
71
|
+
/**
|
|
72
|
+
* @title 校验位
|
|
73
|
+
*/
|
|
74
|
+
checksum: string;
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
76
|
+
/**
|
|
77
|
+
* @title 是否有效
|
|
78
|
+
*/
|
|
79
|
+
valid: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* @title 是否男性
|
|
82
|
+
*/
|
|
83
|
+
male: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* @title 是否女性
|
|
86
|
+
*/
|
|
87
|
+
female: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* @title 性别
|
|
90
|
+
*/
|
|
91
|
+
sex: 'Male' | 'Female';
|
|
92
|
+
/**
|
|
93
|
+
* @title 年龄
|
|
94
|
+
*/
|
|
95
|
+
age: number;
|
|
96
96
|
}
|
|
@@ -2,15 +2,15 @@ import { describe, expect, it } from 'vitest';
|
|
|
2
2
|
import { UnifiedSocialCreditCode } from './UnifiedSocialCreditCode';
|
|
3
3
|
|
|
4
4
|
describe('UnifiedSocialCreditCode', () => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
it('should parse', () => {
|
|
6
|
+
for (const a of [
|
|
7
|
+
//
|
|
8
|
+
'91330106673959654P',
|
|
9
|
+
'91330106MA2CFLDG4R',
|
|
10
|
+
]) {
|
|
11
|
+
let out = UnifiedSocialCreditCode.parse(a);
|
|
12
|
+
expect(UnifiedSocialCreditCode.format(out)).toBe(a);
|
|
13
|
+
expect(out).toMatchSnapshot();
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
16
|
});
|
|
@@ -6,143 +6,138 @@ import { Mod31Checksum } from './Mod31Checksum';
|
|
|
6
6
|
* - GB 11714-1997 全国组织机构代码编制规则
|
|
7
7
|
*/
|
|
8
8
|
export namespace UnifiedSocialCreditCode {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
interface CodeValue {
|
|
10
|
+
label: string;
|
|
11
|
+
children?: Record<string, CodeValue>;
|
|
12
|
+
}
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
children: {
|
|
45
|
-
1: { label: '其他' },
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
};
|
|
14
|
+
const CodeLabels: Record<string, CodeValue> = {
|
|
15
|
+
1: {
|
|
16
|
+
label: '机构编制',
|
|
17
|
+
children: {
|
|
18
|
+
1: { label: '机关' },
|
|
19
|
+
2: { label: '事业单位' },
|
|
20
|
+
3: { label: '中央编办直接管理机构编制的群众团体' },
|
|
21
|
+
9: { label: '其他' },
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
5: {
|
|
25
|
+
label: '民政',
|
|
26
|
+
children: {
|
|
27
|
+
1: { label: '社会团体' },
|
|
28
|
+
2: { label: '民办非企业单位' },
|
|
29
|
+
3: { label: '基金会' },
|
|
30
|
+
9: { label: '其他' },
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
9: {
|
|
34
|
+
label: '工商',
|
|
35
|
+
children: {
|
|
36
|
+
1: { label: '企业' },
|
|
37
|
+
2: { label: '个体工商户' },
|
|
38
|
+
3: { label: '农民专业合作社' },
|
|
39
|
+
9: { label: '其他' },
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
Y: { label: '其他', children: { 1: { label: '其他' } } },
|
|
43
|
+
};
|
|
49
44
|
|
|
50
|
-
|
|
45
|
+
export const pattern = /^([159][1239]|Y1)[0-9]{6}[0-9A-HJ-NP-RTUWXY]{10}$/; // 无 I O Z S V
|
|
51
46
|
|
|
52
|
-
|
|
47
|
+
export const Checksum = new Mod31Checksum();
|
|
53
48
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
49
|
+
export function parse(s: string): ParsedUnifiedSocialCreditCode {
|
|
50
|
+
let bureau = s[0];
|
|
51
|
+
let subjectType = s[1];
|
|
52
|
+
let division = s.slice(2, 8); // 第3~8位,共6位,正确
|
|
53
|
+
let subject = s.slice(8, 17); // 第9~17位,共9位
|
|
54
|
+
let checksum = s.slice(17, 18); // 第18位,校验码
|
|
60
55
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
56
|
+
const labels: string[] = [];
|
|
57
|
+
let l1 = CodeLabels[bureau];
|
|
58
|
+
l1 && labels.push(l1?.label);
|
|
59
|
+
let l2 = l1?.children?.[subjectType];
|
|
60
|
+
l2 && labels.push(l2?.label);
|
|
66
61
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
62
|
+
return {
|
|
63
|
+
bureau,
|
|
64
|
+
subjectType,
|
|
65
|
+
division,
|
|
66
|
+
subject,
|
|
67
|
+
checksum,
|
|
68
|
+
codes: [bureau, subjectType, division, subject],
|
|
69
|
+
labels,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
77
72
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
73
|
+
export function format({
|
|
74
|
+
bureau,
|
|
75
|
+
subjectType,
|
|
76
|
+
division,
|
|
77
|
+
subject,
|
|
78
|
+
checksum,
|
|
79
|
+
}: {
|
|
80
|
+
bureau: string;
|
|
81
|
+
subjectType: string;
|
|
82
|
+
division: string;
|
|
83
|
+
subject: string;
|
|
84
|
+
checksum?: string;
|
|
85
|
+
}): string {
|
|
86
|
+
const base = `${bureau}${subjectType}${division}${subject}`;
|
|
87
|
+
checksum ||= Checksum.compute(base);
|
|
88
|
+
return `${base}${checksum}`;
|
|
89
|
+
}
|
|
95
90
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
91
|
+
export function next(s: string, delta: number = 1) {
|
|
92
|
+
const sp = s.split('').map((v) => Checksum.numbers[v]);
|
|
93
|
+
for (let i = sp.length - 1; i >= 0; i--) {
|
|
94
|
+
if ((delta > 0 && sp[i] < 30) || (delta < 0 && sp[i] > 0)) {
|
|
95
|
+
sp[i] += delta;
|
|
96
|
+
break;
|
|
97
|
+
} else if (delta > 0 && sp[i] === 30) {
|
|
98
|
+
sp[i] = 0;
|
|
99
|
+
} else if (delta < 0 && sp[i] === 0) {
|
|
100
|
+
sp[i] = 30;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return sp.map((v) => Checksum.chars[v]).join('');
|
|
104
|
+
}
|
|
110
105
|
}
|
|
111
106
|
|
|
112
107
|
/**
|
|
113
108
|
* 解析后的统一社会信用代码信息
|
|
114
109
|
*/
|
|
115
110
|
interface ParsedUnifiedSocialCreditCode {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
111
|
+
/**
|
|
112
|
+
* @title 登记管理部门代码
|
|
113
|
+
* 对应统一社会信用代码的第1位字符,用于标识发证机构类别(登记管理部门)。
|
|
114
|
+
*/
|
|
115
|
+
bureau: string;
|
|
121
116
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
117
|
+
/**
|
|
118
|
+
* @title 机构类别代码
|
|
119
|
+
* 对应统一社会信用代码的第2位字符,用于标识被赋码主体的类型(如企业、事业单位、社会组织等)。
|
|
120
|
+
*/
|
|
121
|
+
subjectType: string;
|
|
127
122
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
123
|
+
/**
|
|
124
|
+
* @title 登记管理机关行政区划代码
|
|
125
|
+
* 对应统一社会信用代码的第3至第8位字符,用于标识该主体登记机关所在的行政区划。
|
|
126
|
+
*/
|
|
127
|
+
division: string;
|
|
133
128
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
129
|
+
/**
|
|
130
|
+
* @title 主体标识码
|
|
131
|
+
* 对应统一社会信用代码的第9至第17位字符,用于标识特定的市场主体或法人单位。
|
|
132
|
+
*/
|
|
133
|
+
subject: string;
|
|
139
134
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
135
|
+
/**
|
|
136
|
+
* @title 校验码
|
|
137
|
+
* 对应统一社会信用代码的最后一位字符,用特定算法计算,用于校验代码有效性。
|
|
138
|
+
*/
|
|
139
|
+
checksum: string;
|
|
145
140
|
|
|
146
|
-
|
|
147
|
-
|
|
141
|
+
codes: string[];
|
|
142
|
+
labels: string[];
|
|
148
143
|
}
|
package/src/cn/formatDate.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export function formatDate(date: Date, format: 'yyyyMMDD') {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
switch (format) {
|
|
3
|
+
case 'yyyyMMDD': {
|
|
4
|
+
const year = date.getFullYear();
|
|
5
|
+
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
|
6
|
+
const day = date.getDate().toString().padStart(2, '0');
|
|
7
|
+
return `${year}${month}${day}`;
|
|
8
|
+
}
|
|
9
|
+
default:
|
|
10
|
+
throw new Error(`Invalid format`);
|
|
11
|
+
}
|
|
12
12
|
}
|
package/src/cn/parseSex.ts
CHANGED
|
@@ -1,27 +1,13 @@
|
|
|
1
|
-
export function parseSex(s: string):
|
|
2
|
-
|
|
3
|
-
| {
|
|
4
|
-
sex: 'Male' | 'Female';
|
|
5
|
-
male: boolean;
|
|
6
|
-
female: boolean;
|
|
7
|
-
} {
|
|
8
|
-
if (!s) return undefined;
|
|
1
|
+
export function parseSex(s: string): undefined | { sex: 'Male' | 'Female'; male: boolean; female: boolean } {
|
|
2
|
+
if (!s) return undefined;
|
|
9
3
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
case 'female':
|
|
20
|
-
return {
|
|
21
|
-
sex: 'Female',
|
|
22
|
-
male: false,
|
|
23
|
-
female: true,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
return undefined;
|
|
4
|
+
switch (s.toLowerCase()) {
|
|
5
|
+
case '男':
|
|
6
|
+
case 'male':
|
|
7
|
+
return { sex: 'Male', male: true, female: false };
|
|
8
|
+
case '女':
|
|
9
|
+
case 'female':
|
|
10
|
+
return { sex: 'Female', male: false, female: true };
|
|
11
|
+
}
|
|
12
|
+
return undefined;
|
|
27
13
|
}
|