id-scanner-lib 1.2.2 → 1.3.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.
Files changed (67) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +375 -363
  3. package/dist/id-scanner-core.esm.js +427 -221
  4. package/dist/id-scanner-core.esm.js.map +1 -1
  5. package/dist/id-scanner-core.js +427 -221
  6. package/dist/id-scanner-core.js.map +1 -1
  7. package/dist/id-scanner-core.min.js +1 -9
  8. package/dist/id-scanner-core.min.js.map +1 -1
  9. package/dist/id-scanner-ocr.esm.js +451 -276
  10. package/dist/id-scanner-ocr.esm.js.map +1 -1
  11. package/dist/id-scanner-ocr.js +451 -276
  12. package/dist/id-scanner-ocr.js.map +1 -1
  13. package/dist/id-scanner-ocr.min.js +1 -9
  14. package/dist/id-scanner-ocr.min.js.map +1 -1
  15. package/dist/id-scanner-qr.esm.js +483 -233
  16. package/dist/id-scanner-qr.esm.js.map +1 -1
  17. package/dist/id-scanner-qr.js +482 -232
  18. package/dist/id-scanner-qr.js.map +1 -1
  19. package/dist/id-scanner-qr.min.js +1 -9
  20. package/dist/id-scanner-qr.min.js.map +1 -1
  21. package/dist/id-scanner.js +2138 -358
  22. package/dist/id-scanner.js.map +1 -1
  23. package/dist/id-scanner.min.js +1 -9
  24. package/dist/id-scanner.min.js.map +1 -1
  25. package/package.json +27 -7
  26. package/src/demo/demo.ts +178 -62
  27. package/src/id-recognition/anti-fake-detector.ts +317 -0
  28. package/src/id-recognition/id-detector.ts +184 -155
  29. package/src/id-recognition/ocr-processor.ts +193 -146
  30. package/src/id-recognition/ocr-worker.ts +82 -72
  31. package/src/index-umd.ts +347 -110
  32. package/src/index.ts +866 -91
  33. package/src/ocr-module.ts +108 -60
  34. package/src/qr-module.ts +104 -54
  35. package/src/scanner/barcode-scanner.ts +145 -58
  36. package/src/scanner/qr-scanner.ts +86 -47
  37. package/src/utils/image-processing.ts +479 -294
  38. package/dist/core.d.ts +0 -77
  39. package/dist/demo/demo.d.ts +0 -14
  40. package/dist/id-recognition/data-extractor.d.ts +0 -105
  41. package/dist/id-recognition/id-detector.d.ts +0 -100
  42. package/dist/id-recognition/ocr-processor.d.ts +0 -64
  43. package/dist/id-scanner.esm.js +0 -94656
  44. package/dist/id-scanner.esm.js.map +0 -1
  45. package/dist/index-umd.d.ts +0 -96
  46. package/dist/index.d.ts +0 -78
  47. package/dist/ocr-module.d.ts +0 -67
  48. package/dist/qr-module.d.ts +0 -68
  49. package/dist/scanner/barcode-scanner.d.ts +0 -90
  50. package/dist/scanner/qr-scanner.d.ts +0 -80
  51. package/dist/types/core.d.ts +0 -77
  52. package/dist/types/demo/demo.d.ts +0 -14
  53. package/dist/types/id-recognition/data-extractor.d.ts +0 -105
  54. package/dist/types/id-recognition/id-detector.d.ts +0 -100
  55. package/dist/types/id-recognition/ocr-processor.d.ts +0 -64
  56. package/dist/types/index-umd.d.ts +0 -96
  57. package/dist/types/index.d.ts +0 -78
  58. package/dist/types/ocr-module.d.ts +0 -67
  59. package/dist/types/qr-module.d.ts +0 -68
  60. package/dist/types/scanner/barcode-scanner.d.ts +0 -90
  61. package/dist/types/scanner/qr-scanner.d.ts +0 -80
  62. package/dist/types/utils/camera.d.ts +0 -81
  63. package/dist/types/utils/image-processing.d.ts +0 -75
  64. package/dist/types/utils/types.d.ts +0 -65
  65. package/dist/utils/camera.d.ts +0 -81
  66. package/dist/utils/image-processing.d.ts +0 -75
  67. package/dist/utils/types.d.ts +0 -65
@@ -1,96 +0,0 @@
1
- /**
2
- * @file ID扫描识别库UMD格式入口文件
3
- * @description 专门为UMD格式构建的入口,使用静态导入而非动态导入
4
- * @module IDScannerLib
5
- * @version 1.1.0
6
- * @license MIT
7
- */
8
- import { CameraOptions } from './utils/camera';
9
- import { IDCardInfo } from './utils/types';
10
- import type { QRScannerOptions } from './scanner/qr-scanner';
11
- import type { BarcodeScannerOptions } from './scanner/barcode-scanner';
12
- import { QRScanner } from './scanner/qr-scanner';
13
- import { BarcodeScanner } from './scanner/barcode-scanner';
14
- import { IDCardDetector } from './id-recognition/id-detector';
15
- import { OCRProcessor } from './id-recognition/ocr-processor';
16
- import { DataExtractor } from './id-recognition/data-extractor';
17
- import { ImageProcessor } from './utils/image-processing';
18
- /**
19
- * IDScanner配置选项接口
20
- */
21
- export interface IDScannerOptions {
22
- cameraOptions?: CameraOptions;
23
- qrScannerOptions?: QRScannerOptions;
24
- barcodeScannerOptions?: BarcodeScannerOptions;
25
- onQRCodeScanned?: (result: string) => void;
26
- onBarcodeScanned?: (result: string) => void;
27
- onIDCardScanned?: (info: IDCardInfo) => void;
28
- onError?: (error: Error) => void;
29
- }
30
- /**
31
- * IDScanner 主类
32
- * UMD版本使用静态导入实现
33
- */
34
- export declare class IDScanner {
35
- private options;
36
- private camera;
37
- private qrScanner;
38
- private barcodeScanner;
39
- private idDetector;
40
- private ocrProcessor;
41
- private dataExtractor;
42
- private scanMode;
43
- private videoElement;
44
- /**
45
- * 构造函数
46
- * @param options 配置选项
47
- */
48
- constructor(options?: IDScannerOptions);
49
- /**
50
- * 初始化模块
51
- * 根据需要初始化OCR引擎
52
- */
53
- initialize(): Promise<void>;
54
- /**
55
- * 启动二维码扫描
56
- * @param videoElement HTML视频元素
57
- */
58
- startQRScanner(videoElement: HTMLVideoElement): Promise<void>;
59
- /**
60
- * 启动条形码扫描
61
- * @param videoElement HTML视频元素
62
- */
63
- startBarcodeScanner(videoElement: HTMLVideoElement): Promise<void>;
64
- /**
65
- * 启动身份证扫描
66
- * @param videoElement HTML视频元素
67
- */
68
- startIDCardScanner(videoElement: HTMLVideoElement): Promise<void>;
69
- /**
70
- * 停止扫描
71
- */
72
- stop(): void;
73
- /**
74
- * 处理二维码扫描结果
75
- */
76
- private handleQRScan;
77
- /**
78
- * 处理条形码扫描结果
79
- */
80
- private handleBarcodeScan;
81
- /**
82
- * 处理身份证检测结果
83
- */
84
- private handleIDDetection;
85
- /**
86
- * 处理错误
87
- */
88
- private handleError;
89
- /**
90
- * 释放资源
91
- */
92
- terminate(): Promise<void>;
93
- }
94
- export { IDCardInfo } from './utils/types';
95
- export { CameraOptions } from './utils/camera';
96
- export { QRScanner, BarcodeScanner, IDCardDetector, OCRProcessor, DataExtractor, ImageProcessor };
package/dist/index.d.ts DELETED
@@ -1,78 +0,0 @@
1
- /**
2
- * @file ID扫描识别库主入口文件
3
- * @description 提供身份证识别与二维码、条形码扫描功能的纯前端TypeScript库
4
- * @module IDScannerLib
5
- * @version 1.0.0
6
- * @license MIT
7
- */
8
- import { CameraOptions } from './utils/camera';
9
- import { IDCardInfo } from './utils/types';
10
- import type { QRScannerOptions } from './scanner/qr-scanner';
11
- import type { BarcodeScannerOptions } from './scanner/barcode-scanner';
12
- /**
13
- * IDScanner配置选项接口
14
- */
15
- export interface IDScannerOptions {
16
- cameraOptions?: CameraOptions;
17
- qrScannerOptions?: QRScannerOptions;
18
- barcodeScannerOptions?: BarcodeScannerOptions;
19
- onQRCodeScanned?: (result: string) => void;
20
- onBarcodeScanned?: (result: string) => void;
21
- onIDCardScanned?: (info: IDCardInfo) => void;
22
- onError?: (error: Error) => void;
23
- }
24
- /**
25
- * IDScanner 主类
26
- *
27
- * 整合二维码、条形码扫描和身份证识别功能,提供统一的接口
28
- * 使用动态导入实现按需加载
29
- */
30
- export declare class IDScanner {
31
- private options;
32
- private camera;
33
- private scanMode;
34
- private videoElement;
35
- private qrModule;
36
- private ocrModule;
37
- private isQRModuleLoaded;
38
- private isOCRModuleLoaded;
39
- /**
40
- * 构造函数
41
- * @param options 配置选项
42
- */
43
- constructor(options?: IDScannerOptions);
44
- /**
45
- * 初始化模块
46
- * 根据需要初始化OCR引擎
47
- */
48
- initialize(): Promise<void>;
49
- /**
50
- * 启动二维码扫描
51
- * @param videoElement HTML视频元素
52
- */
53
- startQRScanner(videoElement: HTMLVideoElement): Promise<void>;
54
- /**
55
- * 启动条形码扫描
56
- * @param videoElement HTML视频元素
57
- */
58
- startBarcodeScanner(videoElement: HTMLVideoElement): Promise<void>;
59
- /**
60
- * 启动身份证扫描
61
- * @param videoElement HTML视频元素
62
- */
63
- startIDCardScanner(videoElement: HTMLVideoElement): Promise<void>;
64
- /**
65
- * 停止扫描
66
- */
67
- stop(): void;
68
- /**
69
- * 处理错误
70
- */
71
- private handleError;
72
- /**
73
- * 释放资源
74
- */
75
- terminate(): Promise<void>;
76
- }
77
- export { IDCardInfo } from './utils/types';
78
- export { CameraOptions } from './utils/camera';
@@ -1,67 +0,0 @@
1
- /**
2
- * @file OCR模块入口文件
3
- * @description 包含身份证OCR识别相关功能
4
- * @module IDScannerOCR
5
- * @version 1.0.0
6
- * @license MIT
7
- */
8
- import { IDCardInfo } from './utils/types';
9
- import { CameraOptions } from './utils/camera';
10
- /**
11
- * OCR模块配置选项
12
- */
13
- export interface OCRModuleOptions {
14
- cameraOptions?: CameraOptions;
15
- onIDCardScanned?: (info: IDCardInfo) => void;
16
- onError?: (error: Error) => void;
17
- }
18
- /**
19
- * OCR模块类
20
- *
21
- * 提供身份证检测和OCR文字识别功能
22
- */
23
- export declare class OCRModule {
24
- private options;
25
- private idDetector;
26
- private ocrProcessor;
27
- private dataExtractor;
28
- private camera;
29
- private isRunning;
30
- private videoElement;
31
- /**
32
- * 构造函数
33
- * @param options 配置选项
34
- */
35
- constructor(options?: OCRModuleOptions);
36
- /**
37
- * 初始化OCR引擎
38
- *
39
- * @returns Promise<void>
40
- */
41
- initialize(): Promise<void>;
42
- /**
43
- * 启动身份证扫描
44
- * @param videoElement HTML视频元素
45
- */
46
- startIDCardScanner(videoElement: HTMLVideoElement): Promise<void>;
47
- /**
48
- * 停止扫描
49
- */
50
- stop(): void;
51
- /**
52
- * 处理身份证检测结果
53
- */
54
- private handleIDDetection;
55
- /**
56
- * 处理错误
57
- */
58
- private handleError;
59
- /**
60
- * 释放资源
61
- */
62
- terminate(): Promise<void>;
63
- }
64
- export { IDCardDetector } from './id-recognition/id-detector';
65
- export { OCRProcessor } from './id-recognition/ocr-processor';
66
- export { DataExtractor } from './id-recognition/data-extractor';
67
- export { IDCardInfo } from './utils/types';
@@ -1,68 +0,0 @@
1
- /**
2
- * @file 二维码和条形码扫描模块
3
- * @description 包含二维码和条形码扫描功能
4
- * @module IDScannerQR
5
- * @version 1.0.0
6
- * @license MIT
7
- */
8
- import { QRScannerOptions } from './scanner/qr-scanner';
9
- import { BarcodeScannerOptions } from './scanner/barcode-scanner';
10
- import { CameraOptions } from './utils/camera';
11
- /**
12
- * 扫描模块配置选项
13
- */
14
- export interface ScannerModuleOptions {
15
- cameraOptions?: CameraOptions;
16
- qrScannerOptions?: QRScannerOptions;
17
- barcodeScannerOptions?: BarcodeScannerOptions;
18
- onQRCodeScanned?: (result: string) => void;
19
- onBarcodeScanned?: (result: string) => void;
20
- onError?: (error: Error) => void;
21
- }
22
- /**
23
- * 扫描模块类
24
- *
25
- * 提供独立的二维码和条形码扫描功能
26
- */
27
- export declare class ScannerModule {
28
- private options;
29
- private qrScanner;
30
- private barcodeScanner;
31
- private camera;
32
- private scanMode;
33
- private videoElement;
34
- /**
35
- * 构造函数
36
- * @param options 配置选项
37
- */
38
- constructor(options?: ScannerModuleOptions);
39
- /**
40
- * 启动二维码扫描
41
- * @param videoElement HTML视频元素
42
- */
43
- startQRScanner(videoElement: HTMLVideoElement): Promise<void>;
44
- /**
45
- * 启动条形码扫描
46
- * @param videoElement HTML视频元素
47
- */
48
- startBarcodeScanner(videoElement: HTMLVideoElement): Promise<void>;
49
- /**
50
- * 停止扫描
51
- */
52
- stop(): void;
53
- /**
54
- * 处理二维码扫描结果
55
- */
56
- private handleQRScan;
57
- /**
58
- * 处理条形码扫描结果
59
- */
60
- private handleBarcodeScan;
61
- /**
62
- * 处理错误
63
- */
64
- private handleError;
65
- }
66
- export { QRScanner, QRScannerOptions } from './scanner/qr-scanner';
67
- export { BarcodeScanner, BarcodeScannerOptions } from './scanner/barcode-scanner';
68
- export { Camera, CameraOptions } from './utils/camera';
@@ -1,90 +0,0 @@
1
- /**
2
- * @file 条形码扫描模块
3
- * @description 提供实时条形码扫描和识别功能
4
- * @module BarcodeScanner
5
- */
6
- /**
7
- * 条形码扫描器配置选项
8
- *
9
- * @interface BarcodeScannerOptions
10
- * @property {number} [scanInterval] - 扫描间隔时间(毫秒),默认为200ms
11
- * @property {Function} [onScan] - 扫描成功回调函数
12
- * @property {Function} [onError] - 错误处理回调函数
13
- */
14
- export interface BarcodeScannerOptions {
15
- scanInterval?: number;
16
- onScan?: (result: string) => void;
17
- onError?: (error: Error) => void;
18
- }
19
- /**
20
- * 条形码扫描器类
21
- *
22
- * 提供实时扫描和识别摄像头中的条形码的功能
23
- * 注意:当前实现是简化版,实际项目中建议集成专门的条形码识别库如ZXing或Quagga.js
24
- *
25
- * @example
26
- * ```typescript
27
- * // 创建条形码扫描器
28
- * const barcodeScanner = new BarcodeScanner({
29
- * scanInterval: 100, // 每100ms扫描一次
30
- * onScan: (result) => {
31
- * console.log('扫描到条形码:', result);
32
- * },
33
- * onError: (error) => {
34
- * console.error('扫描错误:', error);
35
- * }
36
- * });
37
- *
38
- * // 启动扫描
39
- * const videoElement = document.getElementById('video') as HTMLVideoElement;
40
- * await barcodeScanner.start(videoElement);
41
- *
42
- * // 停止扫描
43
- * barcodeScanner.stop();
44
- * ```
45
- */
46
- export declare class BarcodeScanner {
47
- private options;
48
- private camera;
49
- private scanning;
50
- private scanTimer;
51
- /**
52
- * 创建条形码扫描器实例
53
- *
54
- * @param {BarcodeScannerOptions} [options] - 扫描器配置选项
55
- */
56
- constructor(options?: BarcodeScannerOptions);
57
- /**
58
- * 启动条形码扫描
59
- *
60
- * 初始化相机并开始连续扫描视频帧中的条形码
61
- *
62
- * @param {HTMLVideoElement} videoElement - 用于显示相机画面的video元素
63
- * @returns {Promise<void>} 启动完成的Promise
64
- * @throws 如果无法访问相机,将通过onError回调报告错误
65
- */
66
- start(videoElement: HTMLVideoElement): Promise<void>;
67
- /**
68
- * 执行一次条形码扫描
69
- *
70
- * 内部方法,捕获当前视频帧并尝试识别其中的条形码
71
- *
72
- * @private
73
- */
74
- private scan;
75
- /**
76
- * 条形码检测方法
77
- *
78
- * 注意:这是一个简化实现,实际需要集成专门的条形码识别库
79
- *
80
- * @private
81
- * @param {ImageData} imageData - 要检测条形码的图像数据
82
- */
83
- private detectBarcode;
84
- /**
85
- * 停止条形码扫描
86
- *
87
- * 停止扫描循环并释放相机资源
88
- */
89
- stop(): void;
90
- }
@@ -1,80 +0,0 @@
1
- /**
2
- * @file 二维码扫描模块
3
- * @description 提供实时二维码扫描和识别功能
4
- * @module QRScanner
5
- */
6
- /**
7
- * 二维码扫描器配置选项
8
- *
9
- * @interface QRScannerOptions
10
- * @property {number} [scanInterval] - 扫描间隔时间(毫秒),默认为200ms
11
- * @property {Function} [onScan] - 扫描成功回调函数
12
- * @property {Function} [onError] - 错误处理回调函数
13
- */
14
- export interface QRScannerOptions {
15
- scanInterval?: number;
16
- onScan?: (result: string) => void;
17
- onError?: (error: Error) => void;
18
- }
19
- /**
20
- * 二维码扫描器类
21
- *
22
- * 提供实时扫描和识别摄像头中的二维码的功能
23
- *
24
- * @example
25
- * ```typescript
26
- * // 创建二维码扫描器
27
- * const qrScanner = new QRScanner({
28
- * scanInterval: 100, // 每100ms扫描一次
29
- * onScan: (result) => {
30
- * console.log('扫描到二维码:', result);
31
- * },
32
- * onError: (error) => {
33
- * console.error('扫描错误:', error);
34
- * }
35
- * });
36
- *
37
- * // 启动扫描
38
- * const videoElement = document.getElementById('video') as HTMLVideoElement;
39
- * await qrScanner.start(videoElement);
40
- *
41
- * // 停止扫描
42
- * qrScanner.stop();
43
- * ```
44
- */
45
- export declare class QRScanner {
46
- private options;
47
- private camera;
48
- private scanning;
49
- private scanTimer;
50
- /**
51
- * 创建二维码扫描器实例
52
- *
53
- * @param {QRScannerOptions} [options] - 扫描器配置选项
54
- */
55
- constructor(options?: QRScannerOptions);
56
- /**
57
- * 启动二维码扫描
58
- *
59
- * 初始化相机并开始连续扫描视频帧中的二维码
60
- *
61
- * @param {HTMLVideoElement} videoElement - 用于显示相机画面的video元素
62
- * @returns {Promise<void>} 启动完成的Promise
63
- * @throws 如果无法访问相机,将通过onError回调报告错误
64
- */
65
- start(videoElement: HTMLVideoElement): Promise<void>;
66
- /**
67
- * 执行一次二维码扫描
68
- *
69
- * 内部方法,捕获当前视频帧并尝试识别其中的二维码
70
- *
71
- * @private
72
- */
73
- private scan;
74
- /**
75
- * 停止二维码扫描
76
- *
77
- * 停止扫描循环并释放相机资源
78
- */
79
- stop(): void;
80
- }
@@ -1,77 +0,0 @@
1
- /**
2
- * @file 轻量级扫描库核心
3
- * @description 不包含OCR功能的轻量版,只提供二维码和条形码扫描功能
4
- * @module IDScannerCore
5
- * @version 1.0.0
6
- * @license MIT
7
- */
8
- import { QRScannerOptions } from './scanner/qr-scanner';
9
- import { BarcodeScannerOptions } from './scanner/barcode-scanner';
10
- import { CameraOptions } from './utils/camera';
11
- /**
12
- * IDScannerCore配置选项
13
- */
14
- export interface IDScannerCoreOptions {
15
- cameraOptions?: CameraOptions;
16
- qrScannerOptions?: QRScannerOptions;
17
- barcodeScannerOptions?: BarcodeScannerOptions;
18
- onQRCodeScanned?: (result: string) => void;
19
- onBarcodeScanned?: (result: string) => void;
20
- onError?: (error: Error) => void;
21
- }
22
- /**
23
- * IDScannerCore 轻量级扫描类
24
- *
25
- * 提供二维码和条形码扫描功能,不包含OCR身份证识别功能
26
- */
27
- export declare class IDScannerCore {
28
- private options;
29
- private qrScanner;
30
- private barcodeScanner;
31
- private camera;
32
- private scanMode;
33
- private videoElement;
34
- /**
35
- * 构造函数
36
- * @param options 配置选项
37
- */
38
- constructor(options?: IDScannerCoreOptions);
39
- /**
40
- * 初始化扫描器
41
- */
42
- initialize(): Promise<void>;
43
- /**
44
- * 启动二维码扫描
45
- * @param videoElement HTML视频元素
46
- */
47
- startQRScanner(videoElement: HTMLVideoElement): Promise<void>;
48
- /**
49
- * 启动条形码扫描
50
- * @param videoElement HTML视频元素
51
- */
52
- startBarcodeScanner(videoElement: HTMLVideoElement): Promise<void>;
53
- /**
54
- * 停止扫描
55
- */
56
- stop(): void;
57
- /**
58
- * 处理二维码扫描结果
59
- */
60
- private handleQRScan;
61
- /**
62
- * 处理条形码扫描结果
63
- */
64
- private handleBarcodeScan;
65
- /**
66
- * 处理错误
67
- */
68
- private handleError;
69
- /**
70
- * 释放资源
71
- */
72
- terminate(): Promise<void>;
73
- }
74
- export { QRScanner, QRScannerOptions } from './scanner/qr-scanner';
75
- export { BarcodeScanner, BarcodeScannerOptions } from './scanner/barcode-scanner';
76
- export { Camera, CameraOptions } from './utils/camera';
77
- export { ImageProcessor } from './utils/image-processing';
@@ -1,14 +0,0 @@
1
- export declare class IDScannerDemo {
2
- private scanner;
3
- private videoElement;
4
- private resultContainer;
5
- private switchButton;
6
- constructor(videoElementId: string, resultContainerId: string, switchButtonId: string);
7
- initialize(): Promise<void>;
8
- private currentMode;
9
- private toggleScanMode;
10
- private handleQRCodeResult;
11
- private handleIDCardResult;
12
- private handleError;
13
- stop(): void;
14
- }
@@ -1,105 +0,0 @@
1
- /**
2
- * @file 数据提取工具类
3
- * @description 提供身份证信息的验证和格式化功能
4
- * @module DataExtractor
5
- */
6
- import { IDCardInfo } from '../utils/types';
7
- /**
8
- * 数据提取工具类
9
- *
10
- * 提供身份证信息的验证、提取和增强功能,可以从身份证号码中提取出生日期、性别等信息,
11
- * 并对OCR识别结果进行补充和验证
12
- *
13
- * @example
14
- * ```typescript
15
- * // 验证身份证号码
16
- * const isValid = DataExtractor.validateIDNumber('110101199001011234');
17
- *
18
- * // 从身份证号码提取出生日期
19
- * const birthDate = DataExtractor.extractBirthDateFromID('110101199001011234');
20
- * // 结果: '1990-01-01'
21
- *
22
- * // 增强OCR识别结果
23
- * const enhancedInfo = DataExtractor.enhanceIDCardInfo({
24
- * name: '张三',
25
- * idNumber: '110101199001011234'
26
- * });
27
- * // 结果会自动补充性别和出生日期
28
- * ```
29
- */
30
- export declare class DataExtractor {
31
- /**
32
- * 验证身份证号码格式
33
- *
34
- * 检查身份证号码的长度、格式和出生日期部分是否有效
35
- *
36
- * @param {string} idNumber - 要验证的身份证号码
37
- * @returns {boolean} 是否是有效的身份证号码
38
- */
39
- static validateIDNumber(idNumber: string): boolean;
40
- /**
41
- * 从身份证号码提取出生日期
42
- *
43
- * @param {string} idNumber - 身份证号码
44
- * @returns {string|null} 格式化的出生日期(YYYY-MM-DD),如果身份证号码无效则返回null
45
- */
46
- static extractBirthDateFromID(idNumber: string): string | null;
47
- /**
48
- * 从身份证号码提取性别
49
- *
50
- * 根据身份证号码第17位判断性别,奇数为男,偶数为女
51
- *
52
- * @param {string} idNumber - 身份证号码
53
- * @returns {string|null} '男'或'女',如果身份证号码无效则返回null
54
- */
55
- static extractGenderFromID(idNumber: string): string | null;
56
- /**
57
- * 从身份证号码提取地区编码
58
- *
59
- * @param {string} idNumber - 身份证号码
60
- * @returns {string|null} 地区编码(前6位),如果身份证号码无效则返回null
61
- */
62
- static extractRegionFromID(idNumber: string): string | null;
63
- /**
64
- * 合并并优化身份证信息
65
- *
66
- * 使用多个来源的数据进行交叉验证和补充,如果OCR识别结果缺少某些信息,
67
- * 但有身份证号码,则可以从号码中提取出生日期和性别等信息
68
- *
69
- * @param {IDCardInfo} ocrInfo - OCR识别到的身份证信息
70
- * @param {string} [idNumber] - 可选的外部提供的身份证号码,优先级高于OCR识别结果
71
- * @returns {IDCardInfo} 增强后的身份证信息
72
- */
73
- static enhanceIDCardInfo(ocrInfo: IDCardInfo, idNumber?: string): IDCardInfo;
74
- /**
75
- * 提取并验证身份证信息
76
- *
77
- * @param idCardInfo 初步提取的身份证信息
78
- * @returns 验证和增强后的身份证信息
79
- */
80
- extractAndValidate(idCardInfo: IDCardInfo): IDCardInfo;
81
- /**
82
- * 规范化身份证号码
83
- */
84
- private normalizeIDNumber;
85
- /**
86
- * 验证身份证号码是否有效
87
- */
88
- private validateIDNumber;
89
- /**
90
- * 从身份证号中提取出生日期
91
- */
92
- private extractBirthDateFromID;
93
- /**
94
- * 从身份证号中提取性别信息
95
- */
96
- private extractGenderFromID;
97
- /**
98
- * 规范化日期格式
99
- */
100
- private normalizeDate;
101
- /**
102
- * 规范化地址信息
103
- */
104
- private normalizeAddress;
105
- }