@indodev/toolkit 0.6.0 → 0.7.0
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/dist/email-validator/index.cjs +10 -0
- package/dist/email-validator/index.cjs.map +1 -1
- package/dist/email-validator/index.d.cts +1 -1
- package/dist/email-validator/index.d.ts +1 -1
- package/dist/email-validator/index.js +10 -1
- package/dist/email-validator/index.js.map +1 -1
- package/dist/{parse-BmmsNlJt.d.cts → errors--47zprcf.d.cts} +41 -7
- package/dist/{parse-BmmsNlJt.d.ts → errors--47zprcf.d.ts} +41 -7
- package/dist/{email-validator-R9L5unIw.d.cts → errors-DdutHLae.d.cts} +23 -1
- package/dist/{email-validator-R9L5unIw.d.ts → errors-DdutHLae.d.ts} +23 -1
- package/dist/index.cjs +271 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +264 -25
- package/dist/index.js.map +1 -1
- package/dist/{compare-Ku_8OhuU.d.cts → mask-CToJqmrd.d.cts} +79 -1
- package/dist/{compare-Ku_8OhuU.d.ts → mask-CToJqmrd.d.ts} +79 -1
- package/dist/nik/index.cjs +21 -12
- package/dist/nik/index.cjs.map +1 -1
- package/dist/nik/index.d.cts +2 -2
- package/dist/nik/index.d.ts +2 -2
- package/dist/nik/index.js +21 -12
- package/dist/nik/index.js.map +1 -1
- package/dist/npwp/index.cjs +10 -0
- package/dist/npwp/index.cjs.map +1 -1
- package/dist/npwp/index.d.cts +23 -1
- package/dist/npwp/index.d.ts +23 -1
- package/dist/npwp/index.js +10 -1
- package/dist/npwp/index.js.map +1 -1
- package/dist/parse-B3UzEHq3.d.cts +155 -0
- package/dist/parse-B3UzEHq3.d.ts +155 -0
- package/dist/parse-DlrgrRfY.d.cts +155 -0
- package/dist/parse-DlrgrRfY.d.ts +155 -0
- package/dist/phone/index.cjs +36 -12
- package/dist/phone/index.cjs.map +1 -1
- package/dist/phone/index.d.cts +1 -1
- package/dist/phone/index.d.ts +1 -1
- package/dist/phone/index.js +36 -13
- package/dist/phone/index.js.map +1 -1
- package/dist/plate/index.cjs +57 -0
- package/dist/plate/index.cjs.map +1 -1
- package/dist/plate/index.d.cts +1 -1
- package/dist/plate/index.d.ts +1 -1
- package/dist/plate/index.js +56 -1
- package/dist/plate/index.js.map +1 -1
- package/dist/text/index.cjs +31 -8
- package/dist/text/index.cjs.map +1 -1
- package/dist/text/index.d.cts +2 -63
- package/dist/text/index.d.ts +2 -63
- package/dist/text/index.js +31 -8
- package/dist/text/index.js.map +1 -1
- package/dist/{utils-DT8-jt63.d.cts → utils-D4A4ro8M.d.cts} +21 -9
- package/dist/{utils-DT8-jt63.d.ts → utils-D4A4ro8M.d.ts} +21 -9
- package/dist/vin/index.cjs +64 -0
- package/dist/vin/index.cjs.map +1 -1
- package/dist/vin/index.d.cts +1 -1
- package/dist/vin/index.d.ts +1 -1
- package/dist/vin/index.js +63 -1
- package/dist/vin/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/types-i5e6R0AS.d.cts +0 -39
- package/dist/types-i5e6R0AS.d.ts +0 -39
- package/dist/utils-DDVlOusI.d.cts +0 -30
- package/dist/utils-DDVlOusI.d.ts +0 -30
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates an Indonesian license plate number format.
|
|
3
|
+
* Format: [1-2 letters] [1-4 digits] [1-3 letters]
|
|
4
|
+
*
|
|
5
|
+
* @param plate - The plate number string to validate
|
|
6
|
+
* @returns `true` if valid, `false` otherwise
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* validatePlate('B 1234 ABC'); // true
|
|
11
|
+
* validatePlate('AB 1 CD'); // true
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
declare function validatePlate(plate: string): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Gets the region name from a license plate number.
|
|
17
|
+
*
|
|
18
|
+
* @param plate - The plate number
|
|
19
|
+
* @returns Region name or null if not found
|
|
20
|
+
*/
|
|
21
|
+
declare function getRegionFromPlate(plate: string): string | null;
|
|
22
|
+
/**
|
|
23
|
+
* Formats a license plate number with spaces (e.g., B 1234 ABC).
|
|
24
|
+
*
|
|
25
|
+
* @param plate - The plate number
|
|
26
|
+
* @returns Formatted plate string
|
|
27
|
+
*/
|
|
28
|
+
declare function formatPlate(plate: string): string;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Error thrown when an invalid vehicle plate is provided to a function.
|
|
32
|
+
* Extends native Error with a `code` property for programmatic error handling.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* try {
|
|
37
|
+
* requirePlate('invalid');
|
|
38
|
+
* } catch (error) {
|
|
39
|
+
* if (error instanceof InvalidPlateError) {
|
|
40
|
+
* console.log(error.code); // 'INVALID_PLATE'
|
|
41
|
+
* }
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
declare class InvalidPlateError extends Error {
|
|
48
|
+
readonly code: "INVALID_PLATE";
|
|
49
|
+
constructor(message?: string);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Information extracted from a valid Indonesian license plate number.
|
|
54
|
+
*
|
|
55
|
+
* Contains parsed data including the plate prefix, number, suffix,
|
|
56
|
+
* type classification, and formatted representation.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const info: PlateInfo = {
|
|
61
|
+
* prefix: 'B',
|
|
62
|
+
* number: '1234',
|
|
63
|
+
* suffix: 'ABC',
|
|
64
|
+
* type: 'private',
|
|
65
|
+
* formatted: 'B 1234 ABC',
|
|
66
|
+
* isValid: true,
|
|
67
|
+
* };
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
72
|
+
interface PlateInfo {
|
|
73
|
+
/**
|
|
74
|
+
* Plate prefix (letters before number).
|
|
75
|
+
* Indicates the region where the vehicle is registered.
|
|
76
|
+
*/
|
|
77
|
+
prefix: string;
|
|
78
|
+
/**
|
|
79
|
+
* Plate number (digits).
|
|
80
|
+
*/
|
|
81
|
+
number: string;
|
|
82
|
+
/**
|
|
83
|
+
* Plate suffix (letters after number, if any).
|
|
84
|
+
*/
|
|
85
|
+
suffix: string;
|
|
86
|
+
/**
|
|
87
|
+
* Type of vehicle registration.
|
|
88
|
+
* - 'private': Private vehicle
|
|
89
|
+
* - 'public': Public transportation
|
|
90
|
+
* - 'diplomat': Diplomatic vehicle
|
|
91
|
+
* - `null`: Unknown or invalid type
|
|
92
|
+
*/
|
|
93
|
+
type: 'private' | 'public' | 'diplomat' | null;
|
|
94
|
+
/**
|
|
95
|
+
* Formatted plate string with proper spacing.
|
|
96
|
+
* @example 'B 1234 ABC'
|
|
97
|
+
*/
|
|
98
|
+
formatted: string;
|
|
99
|
+
/**
|
|
100
|
+
* Whether the plate passed validation.
|
|
101
|
+
* If `false`, other fields may contain partial data.
|
|
102
|
+
*/
|
|
103
|
+
isValid: boolean;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Parses an Indonesian license plate number into its component parts.
|
|
108
|
+
*
|
|
109
|
+
* Extracts the prefix (region code), number, and suffix (optional letters)
|
|
110
|
+
* from a plate number. Also determines the plate type and returns a
|
|
111
|
+
* formatted representation.
|
|
112
|
+
*
|
|
113
|
+
* @param plate - The plate string to parse
|
|
114
|
+
* @returns PlateInfo object with extracted components, or null if invalid
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* Private plate:
|
|
118
|
+
* ```typescript
|
|
119
|
+
* parsePlate('B 1234 ABC');
|
|
120
|
+
* // {
|
|
121
|
+
* // prefix: 'B',
|
|
122
|
+
* // number: '1234',
|
|
123
|
+
* // suffix: 'ABC',
|
|
124
|
+
* // type: 'private',
|
|
125
|
+
* // formatted: 'B 1234 ABC',
|
|
126
|
+
* // isValid: true
|
|
127
|
+
* // }
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* Public transport plate:
|
|
132
|
+
* ```typescript
|
|
133
|
+
* parsePlate('AB 1 CD');
|
|
134
|
+
* // {
|
|
135
|
+
* // prefix: 'AB',
|
|
136
|
+
* // number: '1',
|
|
137
|
+
* // suffix: 'CD',
|
|
138
|
+
* // type: 'public',
|
|
139
|
+
* // formatted: 'AB 1 CD',
|
|
140
|
+
* // isValid: true
|
|
141
|
+
* // }
|
|
142
|
+
* ```
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* Invalid plate returns null:
|
|
146
|
+
* ```typescript
|
|
147
|
+
* parsePlate('invalid');
|
|
148
|
+
* // null
|
|
149
|
+
* ```
|
|
150
|
+
*
|
|
151
|
+
* @public
|
|
152
|
+
*/
|
|
153
|
+
declare function parsePlate(plate: string): PlateInfo | null;
|
|
154
|
+
|
|
155
|
+
export { InvalidPlateError as I, type PlateInfo as P, formatPlate as f, getRegionFromPlate as g, parsePlate as p, validatePlate as v };
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates a Vehicle Identification Number (VIN) based on ISO 3779.
|
|
3
|
+
*
|
|
4
|
+
* Checks for:
|
|
5
|
+
* - Exactly 17 characters length.
|
|
6
|
+
* - Exclusion of characters I, O, and Q.
|
|
7
|
+
* - Checksum validation using the check digit at position 9.
|
|
8
|
+
*
|
|
9
|
+
* @param vin - The VIN string to validate
|
|
10
|
+
* @returns boolean indicating if the VIN is valid
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { validateVIN } from '@indodev/toolkit/vin';
|
|
15
|
+
*
|
|
16
|
+
* validateVIN('1HBHA82L7ZB000001'); // true
|
|
17
|
+
* validateVIN('1HBHA82I7ZB000001'); // false (contains 'I')
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
declare function validateVIN(vin: string): boolean;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* VIN Validation options.
|
|
24
|
+
*/
|
|
25
|
+
interface VINOptions {
|
|
26
|
+
/**
|
|
27
|
+
* Whether to include error messages in the validation result.
|
|
28
|
+
*/
|
|
29
|
+
includeDetails?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Detailed validation result.
|
|
33
|
+
*/
|
|
34
|
+
interface VINValidationResult {
|
|
35
|
+
isValid: boolean;
|
|
36
|
+
error?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Information extracted from a valid Vehicle Identification Number (VIN).
|
|
40
|
+
*
|
|
41
|
+
* Contains parsed data including the world manufacturer identifier (WMI),
|
|
42
|
+
* vehicle descriptor section (VDS), check digit, model year code, plant code,
|
|
43
|
+
* and serial number.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const info: VINInfo = {
|
|
48
|
+
* wmi: '1HB',
|
|
49
|
+
* vds: 'HA82L7',
|
|
50
|
+
* checkDigit: 'Z',
|
|
51
|
+
* modelYearCode: 'B',
|
|
52
|
+
* plantCode: '7',
|
|
53
|
+
* serialNumber: 'ZB000001',
|
|
54
|
+
* isValid: true,
|
|
55
|
+
* };
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
interface VINInfo {
|
|
61
|
+
/**
|
|
62
|
+
* World manufacturer identifier (positions 1-3).
|
|
63
|
+
* Identifies the manufacturer and vehicle type.
|
|
64
|
+
*/
|
|
65
|
+
wmi: string;
|
|
66
|
+
/**
|
|
67
|
+
* Vehicle descriptor section (positions 4-9).
|
|
68
|
+
* Contains information about the vehicle attributes.
|
|
69
|
+
*/
|
|
70
|
+
vds: string;
|
|
71
|
+
/**
|
|
72
|
+
* Check digit (position 9).
|
|
73
|
+
* Used for VIN validation checksum.
|
|
74
|
+
*/
|
|
75
|
+
checkDigit: string;
|
|
76
|
+
/**
|
|
77
|
+
* Model year code (position 10).
|
|
78
|
+
* Indicates the vehicle's model year.
|
|
79
|
+
*/
|
|
80
|
+
modelYearCode: string;
|
|
81
|
+
/**
|
|
82
|
+
* Plant code (position 11).
|
|
83
|
+
* Identifies the manufacturing plant.
|
|
84
|
+
*/
|
|
85
|
+
plantCode: string;
|
|
86
|
+
/**
|
|
87
|
+
* Serial number (positions 12-17).
|
|
88
|
+
* Uniquely identifies the vehicle.
|
|
89
|
+
*/
|
|
90
|
+
serialNumber: string;
|
|
91
|
+
/**
|
|
92
|
+
* Whether the VIN passed validation.
|
|
93
|
+
* If `false`, other fields may contain partial data.
|
|
94
|
+
*/
|
|
95
|
+
isValid: boolean;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Error thrown when an invalid VIN is provided to a function.
|
|
100
|
+
* Extends native Error with a `code` property for programmatic error handling.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* try {
|
|
105
|
+
* requireVIN('invalid');
|
|
106
|
+
* } catch (error) {
|
|
107
|
+
* if (error instanceof InvalidVINError) {
|
|
108
|
+
* console.log(error.code); // 'INVALID_VIN'
|
|
109
|
+
* }
|
|
110
|
+
* }
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* @public
|
|
114
|
+
*/
|
|
115
|
+
declare class InvalidVINError extends Error {
|
|
116
|
+
readonly code: "INVALID_VIN";
|
|
117
|
+
constructor(message?: string);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Parses a Vehicle Identification Number (VIN) into its component parts.
|
|
122
|
+
*
|
|
123
|
+
* Extracts the WMI (World Manufacturer Identifier), VDS (Vehicle Descriptor Section),
|
|
124
|
+
* check digit, model year code, plant code, and serial number from a VIN.
|
|
125
|
+
*
|
|
126
|
+
* @param vin - The VIN string to parse
|
|
127
|
+
* @returns VINInfo object with extracted components, or null if invalid
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* Valid VIN:
|
|
131
|
+
* ```typescript
|
|
132
|
+
* parseVIN('1HBHA82L7ZB000001');
|
|
133
|
+
* // {
|
|
134
|
+
* // wmi: '1HB',
|
|
135
|
+
* // vds: 'HA82L7',
|
|
136
|
+
* // checkDigit: '7',
|
|
137
|
+
* // modelYearCode: 'Z',
|
|
138
|
+
* // plantCode: 'B',
|
|
139
|
+
* // serialNumber: '0000001',
|
|
140
|
+
* // isValid: true
|
|
141
|
+
* // }
|
|
142
|
+
* ```
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* Invalid VIN returns null:
|
|
146
|
+
* ```typescript
|
|
147
|
+
* parseVIN('invalid');
|
|
148
|
+
* // null
|
|
149
|
+
* ```
|
|
150
|
+
*
|
|
151
|
+
* @public
|
|
152
|
+
*/
|
|
153
|
+
declare function parseVIN(vin: string): VINInfo | null;
|
|
154
|
+
|
|
155
|
+
export { InvalidVINError as I, type VINOptions as V, type VINValidationResult as a, type VINInfo as b, parseVIN as p, validateVIN as v };
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates a Vehicle Identification Number (VIN) based on ISO 3779.
|
|
3
|
+
*
|
|
4
|
+
* Checks for:
|
|
5
|
+
* - Exactly 17 characters length.
|
|
6
|
+
* - Exclusion of characters I, O, and Q.
|
|
7
|
+
* - Checksum validation using the check digit at position 9.
|
|
8
|
+
*
|
|
9
|
+
* @param vin - The VIN string to validate
|
|
10
|
+
* @returns boolean indicating if the VIN is valid
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { validateVIN } from '@indodev/toolkit/vin';
|
|
15
|
+
*
|
|
16
|
+
* validateVIN('1HBHA82L7ZB000001'); // true
|
|
17
|
+
* validateVIN('1HBHA82I7ZB000001'); // false (contains 'I')
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
declare function validateVIN(vin: string): boolean;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* VIN Validation options.
|
|
24
|
+
*/
|
|
25
|
+
interface VINOptions {
|
|
26
|
+
/**
|
|
27
|
+
* Whether to include error messages in the validation result.
|
|
28
|
+
*/
|
|
29
|
+
includeDetails?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Detailed validation result.
|
|
33
|
+
*/
|
|
34
|
+
interface VINValidationResult {
|
|
35
|
+
isValid: boolean;
|
|
36
|
+
error?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Information extracted from a valid Vehicle Identification Number (VIN).
|
|
40
|
+
*
|
|
41
|
+
* Contains parsed data including the world manufacturer identifier (WMI),
|
|
42
|
+
* vehicle descriptor section (VDS), check digit, model year code, plant code,
|
|
43
|
+
* and serial number.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const info: VINInfo = {
|
|
48
|
+
* wmi: '1HB',
|
|
49
|
+
* vds: 'HA82L7',
|
|
50
|
+
* checkDigit: 'Z',
|
|
51
|
+
* modelYearCode: 'B',
|
|
52
|
+
* plantCode: '7',
|
|
53
|
+
* serialNumber: 'ZB000001',
|
|
54
|
+
* isValid: true,
|
|
55
|
+
* };
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
interface VINInfo {
|
|
61
|
+
/**
|
|
62
|
+
* World manufacturer identifier (positions 1-3).
|
|
63
|
+
* Identifies the manufacturer and vehicle type.
|
|
64
|
+
*/
|
|
65
|
+
wmi: string;
|
|
66
|
+
/**
|
|
67
|
+
* Vehicle descriptor section (positions 4-9).
|
|
68
|
+
* Contains information about the vehicle attributes.
|
|
69
|
+
*/
|
|
70
|
+
vds: string;
|
|
71
|
+
/**
|
|
72
|
+
* Check digit (position 9).
|
|
73
|
+
* Used for VIN validation checksum.
|
|
74
|
+
*/
|
|
75
|
+
checkDigit: string;
|
|
76
|
+
/**
|
|
77
|
+
* Model year code (position 10).
|
|
78
|
+
* Indicates the vehicle's model year.
|
|
79
|
+
*/
|
|
80
|
+
modelYearCode: string;
|
|
81
|
+
/**
|
|
82
|
+
* Plant code (position 11).
|
|
83
|
+
* Identifies the manufacturing plant.
|
|
84
|
+
*/
|
|
85
|
+
plantCode: string;
|
|
86
|
+
/**
|
|
87
|
+
* Serial number (positions 12-17).
|
|
88
|
+
* Uniquely identifies the vehicle.
|
|
89
|
+
*/
|
|
90
|
+
serialNumber: string;
|
|
91
|
+
/**
|
|
92
|
+
* Whether the VIN passed validation.
|
|
93
|
+
* If `false`, other fields may contain partial data.
|
|
94
|
+
*/
|
|
95
|
+
isValid: boolean;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Error thrown when an invalid VIN is provided to a function.
|
|
100
|
+
* Extends native Error with a `code` property for programmatic error handling.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* try {
|
|
105
|
+
* requireVIN('invalid');
|
|
106
|
+
* } catch (error) {
|
|
107
|
+
* if (error instanceof InvalidVINError) {
|
|
108
|
+
* console.log(error.code); // 'INVALID_VIN'
|
|
109
|
+
* }
|
|
110
|
+
* }
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* @public
|
|
114
|
+
*/
|
|
115
|
+
declare class InvalidVINError extends Error {
|
|
116
|
+
readonly code: "INVALID_VIN";
|
|
117
|
+
constructor(message?: string);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Parses a Vehicle Identification Number (VIN) into its component parts.
|
|
122
|
+
*
|
|
123
|
+
* Extracts the WMI (World Manufacturer Identifier), VDS (Vehicle Descriptor Section),
|
|
124
|
+
* check digit, model year code, plant code, and serial number from a VIN.
|
|
125
|
+
*
|
|
126
|
+
* @param vin - The VIN string to parse
|
|
127
|
+
* @returns VINInfo object with extracted components, or null if invalid
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* Valid VIN:
|
|
131
|
+
* ```typescript
|
|
132
|
+
* parseVIN('1HBHA82L7ZB000001');
|
|
133
|
+
* // {
|
|
134
|
+
* // wmi: '1HB',
|
|
135
|
+
* // vds: 'HA82L7',
|
|
136
|
+
* // checkDigit: '7',
|
|
137
|
+
* // modelYearCode: 'Z',
|
|
138
|
+
* // plantCode: 'B',
|
|
139
|
+
* // serialNumber: '0000001',
|
|
140
|
+
* // isValid: true
|
|
141
|
+
* // }
|
|
142
|
+
* ```
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* Invalid VIN returns null:
|
|
146
|
+
* ```typescript
|
|
147
|
+
* parseVIN('invalid');
|
|
148
|
+
* // null
|
|
149
|
+
* ```
|
|
150
|
+
*
|
|
151
|
+
* @public
|
|
152
|
+
*/
|
|
153
|
+
declare function parseVIN(vin: string): VINInfo | null;
|
|
154
|
+
|
|
155
|
+
export { InvalidVINError as I, type VINOptions as V, type VINValidationResult as a, type VINInfo as b, parseVIN as p, validateVIN as v };
|
package/dist/phone/index.cjs
CHANGED
|
@@ -660,28 +660,42 @@ function maskPhoneNumber(phone, options = {}) {
|
|
|
660
660
|
if (toMask.length < 4) {
|
|
661
661
|
return phone;
|
|
662
662
|
}
|
|
663
|
-
const {
|
|
664
|
-
|
|
665
|
-
if (
|
|
663
|
+
const { maskChar, separator, visibleStart, visibleEnd, start, end, char } = options;
|
|
664
|
+
const hasLegacyOptions = start !== void 0 || end !== void 0 || char !== void 0;
|
|
665
|
+
if (hasLegacyOptions) {
|
|
666
|
+
console.warn(
|
|
667
|
+
"[DEPRECATED] Mask options start/end/char are deprecated. Use visibleStart/visibleEnd/maskChar instead. These old names will be removed in v1.0.0."
|
|
668
|
+
);
|
|
669
|
+
}
|
|
670
|
+
const effectiveStart = visibleStart !== void 0 ? visibleStart : start !== void 0 ? start : 4;
|
|
671
|
+
const effectiveEnd = visibleEnd !== void 0 ? visibleEnd : end !== void 0 ? end : 4;
|
|
672
|
+
const effectiveChar = maskChar !== void 0 ? maskChar : char !== void 0 ? char : "*";
|
|
673
|
+
if (effectiveStart + effectiveEnd >= toMask.length) {
|
|
666
674
|
if (toMask.length < 10) {
|
|
667
675
|
const minMaskLength = 1;
|
|
668
676
|
const availableForVisible = toMask.length - minMaskLength;
|
|
669
677
|
if (availableForVisible >= 2) {
|
|
670
|
-
|
|
671
|
-
|
|
678
|
+
const newStart = Math.floor(availableForVisible / 2);
|
|
679
|
+
const newEnd = availableForVisible - newStart;
|
|
680
|
+
const startPart2 = toMask.substring(0, newStart);
|
|
681
|
+
const endPart2 = toMask.substring(toMask.length - newEnd);
|
|
682
|
+
const masked2 = startPart2 + effectiveChar + endPart2;
|
|
683
|
+
if (separator) {
|
|
684
|
+
return `${startPart2}${separator}${effectiveChar}${separator}${endPart2}`;
|
|
685
|
+
}
|
|
686
|
+
return masked2;
|
|
672
687
|
} else {
|
|
673
688
|
return toMask;
|
|
674
689
|
}
|
|
675
|
-
} else {
|
|
676
|
-
return toMask;
|
|
677
690
|
}
|
|
691
|
+
return toMask;
|
|
678
692
|
}
|
|
679
|
-
const startPart = toMask.substring(0,
|
|
680
|
-
const endPart = toMask.substring(toMask.length -
|
|
681
|
-
const maskLength = toMask.length -
|
|
682
|
-
const masked = startPart +
|
|
693
|
+
const startPart = toMask.substring(0, effectiveStart);
|
|
694
|
+
const endPart = toMask.substring(toMask.length - effectiveEnd);
|
|
695
|
+
const maskLength = toMask.length - effectiveStart - effectiveEnd;
|
|
696
|
+
const masked = startPart + effectiveChar.repeat(maskLength) + endPart;
|
|
683
697
|
if (separator) {
|
|
684
|
-
return `${masked.substring(0,
|
|
698
|
+
return `${masked.substring(0, effectiveStart)}${separator}${masked.substring(effectiveStart, masked.length - effectiveEnd)}${separator}${masked.substring(masked.length - effectiveEnd)}`;
|
|
685
699
|
}
|
|
686
700
|
return masked;
|
|
687
701
|
}
|
|
@@ -773,6 +787,16 @@ function isProvider(phone, providerName) {
|
|
|
773
787
|
return operator.toLowerCase() === providerName.toLowerCase();
|
|
774
788
|
}
|
|
775
789
|
|
|
790
|
+
// src/phone/errors.ts
|
|
791
|
+
var InvalidPhoneError = class extends Error {
|
|
792
|
+
constructor(message = "Invalid phone number provided") {
|
|
793
|
+
super(message);
|
|
794
|
+
this.code = "INVALID_PHONE";
|
|
795
|
+
this.name = "InvalidPhoneError";
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
|
|
799
|
+
exports.InvalidPhoneError = InvalidPhoneError;
|
|
776
800
|
exports.cleanPhoneNumber = cleanPhoneNumber;
|
|
777
801
|
exports.comparePhones = comparePhones;
|
|
778
802
|
exports.formatPhoneNumber = formatPhoneNumber;
|