@indodev/toolkit 0.3.0 → 0.3.1
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/{compare-BIodyGn7.d.cts → compare-CZadJMGl.d.cts} +1 -1
- package/dist/{compare-BIodyGn7.d.ts → compare-CZadJMGl.d.ts} +1 -1
- package/dist/index.cjs +71 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -107
- package/dist/index.d.ts +4 -107
- package/dist/index.js +71 -1
- package/dist/index.js.map +1 -1
- package/dist/npwp/index.cjs +95 -0
- package/dist/npwp/index.cjs.map +1 -0
- package/dist/npwp/index.d.cts +76 -0
- package/dist/npwp/index.d.ts +76 -0
- package/dist/npwp/index.js +90 -0
- package/dist/npwp/index.js.map +1 -0
- package/dist/plate/index.cjs +99 -0
- package/dist/plate/index.cjs.map +1 -0
- package/dist/plate/index.d.cts +8 -0
- package/dist/plate/index.d.ts +8 -0
- package/dist/plate/index.js +94 -0
- package/dist/plate/index.js.map +1 -0
- package/dist/text/index.d.cts +1 -1
- package/dist/text/index.d.ts +1 -1
- package/dist/types-i5e6R0AS.d.cts +39 -0
- package/dist/types-i5e6R0AS.d.ts +39 -0
- package/dist/utils-DDVlOusI.d.cts +30 -0
- package/dist/utils-DDVlOusI.d.ts +30 -0
- package/dist/vin/index.cjs +84 -0
- package/dist/vin/index.cjs.map +1 -0
- package/dist/vin/index.d.cts +39 -0
- package/dist/vin/index.d.ts +39 -0
- package/dist/vin/index.js +74 -0
- package/dist/vin/index.js.map +1 -0
- package/package.json +11 -1
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
export { type VINOptions as V, type VINValidationResult as a, validateVIN as v };
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
export { type VINOptions as V, type VINValidationResult as a, validateVIN as v };
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
export { formatPlate as f, getRegionFromPlate as g, validatePlate as v };
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
export { formatPlate as f, getRegionFromPlate as g, validatePlate as v };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/vin/constants.ts
|
|
4
|
+
var VIN_LENGTH = 17;
|
|
5
|
+
var VIN_CHECK_DIGIT_INDEX = 8;
|
|
6
|
+
var VIN_MODULUS = 11;
|
|
7
|
+
var VIN_CHECK_DIGIT_X = "X";
|
|
8
|
+
var VIN_WEIGHTS = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2];
|
|
9
|
+
var VIN_CHAR_VALUES = {
|
|
10
|
+
"0": 0,
|
|
11
|
+
"1": 1,
|
|
12
|
+
"2": 2,
|
|
13
|
+
"3": 3,
|
|
14
|
+
"4": 4,
|
|
15
|
+
"5": 5,
|
|
16
|
+
"6": 6,
|
|
17
|
+
"7": 7,
|
|
18
|
+
"8": 8,
|
|
19
|
+
"9": 9,
|
|
20
|
+
"A": 1,
|
|
21
|
+
"B": 2,
|
|
22
|
+
"C": 3,
|
|
23
|
+
"D": 4,
|
|
24
|
+
"E": 5,
|
|
25
|
+
"F": 6,
|
|
26
|
+
"G": 7,
|
|
27
|
+
"H": 8,
|
|
28
|
+
"J": 1,
|
|
29
|
+
"K": 2,
|
|
30
|
+
"L": 3,
|
|
31
|
+
"M": 4,
|
|
32
|
+
"N": 5,
|
|
33
|
+
"P": 7,
|
|
34
|
+
"R": 9,
|
|
35
|
+
"S": 2,
|
|
36
|
+
"T": 3,
|
|
37
|
+
"U": 4,
|
|
38
|
+
"V": 5,
|
|
39
|
+
"W": 6,
|
|
40
|
+
"X": 7,
|
|
41
|
+
"Y": 8,
|
|
42
|
+
"Z": 9
|
|
43
|
+
};
|
|
44
|
+
var EXCLUDED_VIN_CHARS = ["I", "O", "Q"];
|
|
45
|
+
var VIN_VERSION = "1.0.0";
|
|
46
|
+
|
|
47
|
+
// src/vin/validate.ts
|
|
48
|
+
function validateVIN(vin) {
|
|
49
|
+
if (!vin || vin.length !== VIN_LENGTH) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
const normalizedVIN = vin.toUpperCase();
|
|
53
|
+
for (const char of EXCLUDED_VIN_CHARS) {
|
|
54
|
+
if (normalizedVIN.includes(char)) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
let sum = 0;
|
|
59
|
+
for (let i = 0; i < VIN_LENGTH; i++) {
|
|
60
|
+
const char = normalizedVIN[i];
|
|
61
|
+
const weight = VIN_WEIGHTS[i];
|
|
62
|
+
const val = VIN_CHAR_VALUES[char];
|
|
63
|
+
if (val === void 0) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
sum += val * weight;
|
|
67
|
+
}
|
|
68
|
+
const checkDigitValue = sum % VIN_MODULUS;
|
|
69
|
+
const expectedCheckDigit = checkDigitValue === 10 ? VIN_CHECK_DIGIT_X : checkDigitValue.toString();
|
|
70
|
+
const actualCheckDigit = normalizedVIN[VIN_CHECK_DIGIT_INDEX];
|
|
71
|
+
return actualCheckDigit === expectedCheckDigit;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
exports.EXCLUDED_VIN_CHARS = EXCLUDED_VIN_CHARS;
|
|
75
|
+
exports.VIN_CHAR_VALUES = VIN_CHAR_VALUES;
|
|
76
|
+
exports.VIN_CHECK_DIGIT_INDEX = VIN_CHECK_DIGIT_INDEX;
|
|
77
|
+
exports.VIN_CHECK_DIGIT_X = VIN_CHECK_DIGIT_X;
|
|
78
|
+
exports.VIN_LENGTH = VIN_LENGTH;
|
|
79
|
+
exports.VIN_MODULUS = VIN_MODULUS;
|
|
80
|
+
exports.VIN_VERSION = VIN_VERSION;
|
|
81
|
+
exports.VIN_WEIGHTS = VIN_WEIGHTS;
|
|
82
|
+
exports.validateVIN = validateVIN;
|
|
83
|
+
//# sourceMappingURL=index.cjs.map
|
|
84
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/vin/constants.ts","../../src/vin/validate.ts"],"names":[],"mappings":";;;AAGO,IAAM,UAAA,GAAa;AAKnB,IAAM,qBAAA,GAAwB;AAK9B,IAAM,WAAA,GAAc;AAKpB,IAAM,iBAAA,GAAoB;AAO1B,IAAM,cAAc,CAAC,CAAA,EAAG,GAAG,CAAA,EAAG,CAAA,EAAG,GAAG,CAAA,EAAG,CAAA,EAAG,EAAA,EAAI,CAAA,EAAG,GAAG,CAAA,EAAG,CAAA,EAAG,GAAG,CAAA,EAAG,CAAA,EAAG,GAAG,CAAC;AAMvE,IAAM,eAAA,GAA0C;AAAA,EACrD,GAAA,EAAK,CAAA;AAAA,EAAG,GAAA,EAAK,CAAA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AAA,MAAW,QAAQ,kBAAA,EAAoB;AACrC,IAAA,IAAI,aAAA,CAAc,QAAA,CAAS,IAAI,CAAA,EAAG;AAChC,MAAA,OAAO,KAAA;AAAA,IACT;AAAA,EACF;AAGA,EAAA,IAAI,GAAA,GAAM,CAAA;AACV,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,UAAA,EAAY,CAAA,EAAA,EAAK;AACnC,IAAA,MAAM,IAAA,GAAO,cAAc,CAAC,CAAA;AAC5B,IAAA,MAAM,MAAA,GAAS,YAAY,CAAC,CAAA;AAC5B,IAAA,MAAM,GAAA,GAAM,gBAAgB,IAAI,CAAA;AAEhC,IAAA,IAAI,QAAQ,MAAA,EAAW;AACrB,MAAA,OAAO,KAAA;AAAA,IACT;AAEA,IAAA,GAAA,IAAO,GAAA,GAAM,MAAA;AAAA,EACf;AAEA,EAAA,MAAM,kBAAkB,GAAA,GAAM,WAAA;AAC9B,EAAA,MAAM,kBAAA,GACJ,eAAA,KAAoB,EAAA,GAAK,iBAAA,GAAoB,gBAAgB,QAAA,EAAS;AACxE,EAAA,MAAM,gBAAA,GAAmB,cAAc,qBAAqB,CAAA;AAE5D,EAAA,OAAO,gBAAA,KAAqB,kBAAA;AAC9B","file":"index.cjs","sourcesContent":["/**\n * The standard length of a VIN (ISO 3779).\n */\nexport const VIN_LENGTH = 17;\n\n/**\n * The 0-based index of the check digit in the VIN (Position 9).\n */\nexport const VIN_CHECK_DIGIT_INDEX = 8;\n\n/**\n * The modulus used in the VIN checksum calculation.\n */\nexport const VIN_MODULUS = 11;\n\n/**\n * The character representing a checksum value of 10.\n */\nexport const VIN_CHECK_DIGIT_X = 'X';\n\n/**\n * Weights used in the VIN checksum calculation.\n * Each position (1-17) is multiplied by its corresponding weight.\n * Position 9 is the check digit itself (weight 0).\n */\nexport const VIN_WEIGHTS = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2];\n\n/**\n * Values assigned to each valid character for VIN calculation.\n * Invalid characters: I, O, Q are not allowed in VIN.\n */\nexport const VIN_CHAR_VALUES: Record<string, number> = {\n '0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9,\n 'A': 1, 'B': 2, 'C': 3, 'D': 4, 'E': 5, 'F': 6, 'G': 7, 'H': 8,\n 'J': 1, 'K': 2, 'L': 3, 'M': 4, 'N': 5, 'P': 7, 'R': 9,\n 'S': 2, 'T': 3, 'U': 4, 'V': 5, 'W': 6, 'X': 7, 'Y': 8, 'Z': 9,\n};\n\n/**\n * Characters excluded from VIN (I, O, Q).\n */\nexport const EXCLUDED_VIN_CHARS = ['I', 'O', 'Q'];\n\n/**\n * Version of the VIN utility module.\n */\nexport const VIN_VERSION = '1.0.0';\n\n","import {\n VIN_WEIGHTS,\n VIN_CHAR_VALUES,\n EXCLUDED_VIN_CHARS,\n VIN_LENGTH,\n VIN_CHECK_DIGIT_INDEX,\n VIN_MODULUS,\n VIN_CHECK_DIGIT_X,\n} from './constants';\n\n/**\n * Validates a Vehicle Identification Number (VIN) based on ISO 3779.\n *\n * Checks for:\n * - Exactly 17 characters length.\n * - Exclusion of characters I, O, and Q.\n * - Checksum validation using the check digit at position 9.\n *\n * @param vin - The VIN string to validate\n * @returns boolean indicating if the VIN is valid\n *\n * @example\n * ```typescript\n * import { validateVIN } from '@indodev/toolkit/vin';\n *\n * validateVIN('1HBHA82L7ZB000001'); // true\n * validateVIN('1HBHA82I7ZB000001'); // false (contains 'I')\n * ```\n */\nexport function validateVIN(vin: string): boolean {\n if (!vin || vin.length !== VIN_LENGTH) {\n return false;\n }\n\n const normalizedVIN = vin.toUpperCase();\n\n // 1. Check for excluded characters (I, O, Q)\n for (const char of EXCLUDED_VIN_CHARS) {\n if (normalizedVIN.includes(char)) {\n return false;\n }\n }\n\n // 2. Checksum validation (Position 9)\n let sum = 0;\n for (let i = 0; i < VIN_LENGTH; i++) {\n const char = normalizedVIN[i];\n const weight = VIN_WEIGHTS[i];\n const val = VIN_CHAR_VALUES[char];\n\n if (val === undefined) {\n return false; // Invalid character found\n }\n\n sum += val * weight;\n }\n\n const checkDigitValue = sum % VIN_MODULUS;\n const expectedCheckDigit =\n checkDigitValue === 10 ? VIN_CHECK_DIGIT_X : checkDigitValue.toString();\n const actualCheckDigit = normalizedVIN[VIN_CHECK_DIGIT_INDEX];\n\n return actualCheckDigit === expectedCheckDigit;\n}\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export { V as VINOptions, a as VINValidationResult, v as validateVIN } from '../types-i5e6R0AS.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The standard length of a VIN (ISO 3779).
|
|
5
|
+
*/
|
|
6
|
+
declare const VIN_LENGTH = 17;
|
|
7
|
+
/**
|
|
8
|
+
* The 0-based index of the check digit in the VIN (Position 9).
|
|
9
|
+
*/
|
|
10
|
+
declare const VIN_CHECK_DIGIT_INDEX = 8;
|
|
11
|
+
/**
|
|
12
|
+
* The modulus used in the VIN checksum calculation.
|
|
13
|
+
*/
|
|
14
|
+
declare const VIN_MODULUS = 11;
|
|
15
|
+
/**
|
|
16
|
+
* The character representing a checksum value of 10.
|
|
17
|
+
*/
|
|
18
|
+
declare const VIN_CHECK_DIGIT_X = "X";
|
|
19
|
+
/**
|
|
20
|
+
* Weights used in the VIN checksum calculation.
|
|
21
|
+
* Each position (1-17) is multiplied by its corresponding weight.
|
|
22
|
+
* Position 9 is the check digit itself (weight 0).
|
|
23
|
+
*/
|
|
24
|
+
declare const VIN_WEIGHTS: number[];
|
|
25
|
+
/**
|
|
26
|
+
* Values assigned to each valid character for VIN calculation.
|
|
27
|
+
* Invalid characters: I, O, Q are not allowed in VIN.
|
|
28
|
+
*/
|
|
29
|
+
declare const VIN_CHAR_VALUES: Record<string, number>;
|
|
30
|
+
/**
|
|
31
|
+
* Characters excluded from VIN (I, O, Q).
|
|
32
|
+
*/
|
|
33
|
+
declare const EXCLUDED_VIN_CHARS: string[];
|
|
34
|
+
/**
|
|
35
|
+
* Version of the VIN utility module.
|
|
36
|
+
*/
|
|
37
|
+
declare const VIN_VERSION = "1.0.0";
|
|
38
|
+
|
|
39
|
+
export { EXCLUDED_VIN_CHARS, VIN_CHAR_VALUES, VIN_CHECK_DIGIT_INDEX, VIN_CHECK_DIGIT_X, VIN_LENGTH, VIN_MODULUS, VIN_VERSION, VIN_WEIGHTS };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export { V as VINOptions, a as VINValidationResult, v as validateVIN } from '../types-i5e6R0AS.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The standard length of a VIN (ISO 3779).
|
|
5
|
+
*/
|
|
6
|
+
declare const VIN_LENGTH = 17;
|
|
7
|
+
/**
|
|
8
|
+
* The 0-based index of the check digit in the VIN (Position 9).
|
|
9
|
+
*/
|
|
10
|
+
declare const VIN_CHECK_DIGIT_INDEX = 8;
|
|
11
|
+
/**
|
|
12
|
+
* The modulus used in the VIN checksum calculation.
|
|
13
|
+
*/
|
|
14
|
+
declare const VIN_MODULUS = 11;
|
|
15
|
+
/**
|
|
16
|
+
* The character representing a checksum value of 10.
|
|
17
|
+
*/
|
|
18
|
+
declare const VIN_CHECK_DIGIT_X = "X";
|
|
19
|
+
/**
|
|
20
|
+
* Weights used in the VIN checksum calculation.
|
|
21
|
+
* Each position (1-17) is multiplied by its corresponding weight.
|
|
22
|
+
* Position 9 is the check digit itself (weight 0).
|
|
23
|
+
*/
|
|
24
|
+
declare const VIN_WEIGHTS: number[];
|
|
25
|
+
/**
|
|
26
|
+
* Values assigned to each valid character for VIN calculation.
|
|
27
|
+
* Invalid characters: I, O, Q are not allowed in VIN.
|
|
28
|
+
*/
|
|
29
|
+
declare const VIN_CHAR_VALUES: Record<string, number>;
|
|
30
|
+
/**
|
|
31
|
+
* Characters excluded from VIN (I, O, Q).
|
|
32
|
+
*/
|
|
33
|
+
declare const EXCLUDED_VIN_CHARS: string[];
|
|
34
|
+
/**
|
|
35
|
+
* Version of the VIN utility module.
|
|
36
|
+
*/
|
|
37
|
+
declare const VIN_VERSION = "1.0.0";
|
|
38
|
+
|
|
39
|
+
export { EXCLUDED_VIN_CHARS, VIN_CHAR_VALUES, VIN_CHECK_DIGIT_INDEX, VIN_CHECK_DIGIT_X, VIN_LENGTH, VIN_MODULUS, VIN_VERSION, VIN_WEIGHTS };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// src/vin/constants.ts
|
|
2
|
+
var VIN_LENGTH = 17;
|
|
3
|
+
var VIN_CHECK_DIGIT_INDEX = 8;
|
|
4
|
+
var VIN_MODULUS = 11;
|
|
5
|
+
var VIN_CHECK_DIGIT_X = "X";
|
|
6
|
+
var VIN_WEIGHTS = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2];
|
|
7
|
+
var VIN_CHAR_VALUES = {
|
|
8
|
+
"0": 0,
|
|
9
|
+
"1": 1,
|
|
10
|
+
"2": 2,
|
|
11
|
+
"3": 3,
|
|
12
|
+
"4": 4,
|
|
13
|
+
"5": 5,
|
|
14
|
+
"6": 6,
|
|
15
|
+
"7": 7,
|
|
16
|
+
"8": 8,
|
|
17
|
+
"9": 9,
|
|
18
|
+
"A": 1,
|
|
19
|
+
"B": 2,
|
|
20
|
+
"C": 3,
|
|
21
|
+
"D": 4,
|
|
22
|
+
"E": 5,
|
|
23
|
+
"F": 6,
|
|
24
|
+
"G": 7,
|
|
25
|
+
"H": 8,
|
|
26
|
+
"J": 1,
|
|
27
|
+
"K": 2,
|
|
28
|
+
"L": 3,
|
|
29
|
+
"M": 4,
|
|
30
|
+
"N": 5,
|
|
31
|
+
"P": 7,
|
|
32
|
+
"R": 9,
|
|
33
|
+
"S": 2,
|
|
34
|
+
"T": 3,
|
|
35
|
+
"U": 4,
|
|
36
|
+
"V": 5,
|
|
37
|
+
"W": 6,
|
|
38
|
+
"X": 7,
|
|
39
|
+
"Y": 8,
|
|
40
|
+
"Z": 9
|
|
41
|
+
};
|
|
42
|
+
var EXCLUDED_VIN_CHARS = ["I", "O", "Q"];
|
|
43
|
+
var VIN_VERSION = "1.0.0";
|
|
44
|
+
|
|
45
|
+
// src/vin/validate.ts
|
|
46
|
+
function validateVIN(vin) {
|
|
47
|
+
if (!vin || vin.length !== VIN_LENGTH) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
const normalizedVIN = vin.toUpperCase();
|
|
51
|
+
for (const char of EXCLUDED_VIN_CHARS) {
|
|
52
|
+
if (normalizedVIN.includes(char)) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
let sum = 0;
|
|
57
|
+
for (let i = 0; i < VIN_LENGTH; i++) {
|
|
58
|
+
const char = normalizedVIN[i];
|
|
59
|
+
const weight = VIN_WEIGHTS[i];
|
|
60
|
+
const val = VIN_CHAR_VALUES[char];
|
|
61
|
+
if (val === void 0) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
sum += val * weight;
|
|
65
|
+
}
|
|
66
|
+
const checkDigitValue = sum % VIN_MODULUS;
|
|
67
|
+
const expectedCheckDigit = checkDigitValue === 10 ? VIN_CHECK_DIGIT_X : checkDigitValue.toString();
|
|
68
|
+
const actualCheckDigit = normalizedVIN[VIN_CHECK_DIGIT_INDEX];
|
|
69
|
+
return actualCheckDigit === expectedCheckDigit;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { EXCLUDED_VIN_CHARS, VIN_CHAR_VALUES, VIN_CHECK_DIGIT_INDEX, VIN_CHECK_DIGIT_X, VIN_LENGTH, VIN_MODULUS, VIN_VERSION, VIN_WEIGHTS, validateVIN };
|
|
73
|
+
//# sourceMappingURL=index.js.map
|
|
74
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/vin/constants.ts","../../src/vin/validate.ts"],"names":[],"mappings":";AAGO,IAAM,UAAA,GAAa;A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A;AAAA,EAAG,GAAA,EAAK,CAAA;AAAA,EAAG,GAAA,EAAK;AAC/D;AAKO,IAAM,kBAAA,GAAqB,CAAC,GAAA,EAAK,GAAA,EAAK,GAAG;AAKzC,IAAM,WAAA,GAAc;;;ACjBpB,SAAS,YAAY,GAAA,EAAsB;AAChD,EAAA,IAAI,CAAC,GAAA,IAAO,GAAA,CAAI,MAAA,KAAW,UAAA,EAAY;AACrC,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,MAAM,aAAA,GAAgB,IAAI,WAAA,EAAY;AAGtC,EAAA,KAAA,MAAW,QAAQ,kBAAA,EAAoB;AACrC,IAAA,IAAI,aAAA,CAAc,QAAA,CAAS,IAAI,CAAA,EAAG;AAChC,MAAA,OAAO,KAAA;AAAA,IACT;AAAA,EACF;AAGA,EAAA,IAAI,GAAA,GAAM,CAAA;AACV,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,UAAA,EAAY,CAAA,EAAA,EAAK;AACnC,IAAA,MAAM,IAAA,GAAO,cAAc,CAAC,CAAA;AAC5B,IAAA,MAAM,MAAA,GAAS,YAAY,CAAC,CAAA;AAC5B,IAAA,MAAM,GAAA,GAAM,gBAAgB,IAAI,CAAA;AAEhC,IAAA,IAAI,QAAQ,MAAA,EAAW;AACrB,MAAA,OAAO,KAAA;AAAA,IACT;AAEA,IAAA,GAAA,IAAO,GAAA,GAAM,MAAA;AAAA,EACf;AAEA,EAAA,MAAM,kBAAkB,GAAA,GAAM,WAAA;AAC9B,EAAA,MAAM,kBAAA,GACJ,eAAA,KAAoB,EAAA,GAAK,iBAAA,GAAoB,gBAAgB,QAAA,EAAS;AACxE,EAAA,MAAM,gBAAA,GAAmB,cAAc,qBAAqB,CAAA;AAE5D,EAAA,OAAO,gBAAA,KAAqB,kBAAA;AAC9B","file":"index.js","sourcesContent":["/**\n * The standard length of a VIN (ISO 3779).\n */\nexport const VIN_LENGTH = 17;\n\n/**\n * The 0-based index of the check digit in the VIN (Position 9).\n */\nexport const VIN_CHECK_DIGIT_INDEX = 8;\n\n/**\n * The modulus used in the VIN checksum calculation.\n */\nexport const VIN_MODULUS = 11;\n\n/**\n * The character representing a checksum value of 10.\n */\nexport const VIN_CHECK_DIGIT_X = 'X';\n\n/**\n * Weights used in the VIN checksum calculation.\n * Each position (1-17) is multiplied by its corresponding weight.\n * Position 9 is the check digit itself (weight 0).\n */\nexport const VIN_WEIGHTS = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2];\n\n/**\n * Values assigned to each valid character for VIN calculation.\n * Invalid characters: I, O, Q are not allowed in VIN.\n */\nexport const VIN_CHAR_VALUES: Record<string, number> = {\n '0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9,\n 'A': 1, 'B': 2, 'C': 3, 'D': 4, 'E': 5, 'F': 6, 'G': 7, 'H': 8,\n 'J': 1, 'K': 2, 'L': 3, 'M': 4, 'N': 5, 'P': 7, 'R': 9,\n 'S': 2, 'T': 3, 'U': 4, 'V': 5, 'W': 6, 'X': 7, 'Y': 8, 'Z': 9,\n};\n\n/**\n * Characters excluded from VIN (I, O, Q).\n */\nexport const EXCLUDED_VIN_CHARS = ['I', 'O', 'Q'];\n\n/**\n * Version of the VIN utility module.\n */\nexport const VIN_VERSION = '1.0.0';\n\n","import {\n VIN_WEIGHTS,\n VIN_CHAR_VALUES,\n EXCLUDED_VIN_CHARS,\n VIN_LENGTH,\n VIN_CHECK_DIGIT_INDEX,\n VIN_MODULUS,\n VIN_CHECK_DIGIT_X,\n} from './constants';\n\n/**\n * Validates a Vehicle Identification Number (VIN) based on ISO 3779.\n *\n * Checks for:\n * - Exactly 17 characters length.\n * - Exclusion of characters I, O, and Q.\n * - Checksum validation using the check digit at position 9.\n *\n * @param vin - The VIN string to validate\n * @returns boolean indicating if the VIN is valid\n *\n * @example\n * ```typescript\n * import { validateVIN } from '@indodev/toolkit/vin';\n *\n * validateVIN('1HBHA82L7ZB000001'); // true\n * validateVIN('1HBHA82I7ZB000001'); // false (contains 'I')\n * ```\n */\nexport function validateVIN(vin: string): boolean {\n if (!vin || vin.length !== VIN_LENGTH) {\n return false;\n }\n\n const normalizedVIN = vin.toUpperCase();\n\n // 1. Check for excluded characters (I, O, Q)\n for (const char of EXCLUDED_VIN_CHARS) {\n if (normalizedVIN.includes(char)) {\n return false;\n }\n }\n\n // 2. Checksum validation (Position 9)\n let sum = 0;\n for (let i = 0; i < VIN_LENGTH; i++) {\n const char = normalizedVIN[i];\n const weight = VIN_WEIGHTS[i];\n const val = VIN_CHAR_VALUES[char];\n\n if (val === undefined) {\n return false; // Invalid character found\n }\n\n sum += val * weight;\n }\n\n const checkDigitValue = sum % VIN_MODULUS;\n const expectedCheckDigit =\n checkDigitValue === 10 ? VIN_CHECK_DIGIT_X : checkDigitValue.toString();\n const actualCheckDigit = normalizedVIN[VIN_CHECK_DIGIT_INDEX];\n\n return actualCheckDigit === expectedCheckDigit;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@indodev/toolkit",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Indonesian developer utilities for validation, formatting, and more",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -77,6 +77,16 @@
|
|
|
77
77
|
"types": "./dist/plate/index.d.cts",
|
|
78
78
|
"default": "./dist/plate/index.cjs"
|
|
79
79
|
}
|
|
80
|
+
},
|
|
81
|
+
"./vin": {
|
|
82
|
+
"import": {
|
|
83
|
+
"types": "./dist/vin/index.d.ts",
|
|
84
|
+
"default": "./dist/vin/index.js"
|
|
85
|
+
},
|
|
86
|
+
"require": {
|
|
87
|
+
"types": "./dist/vin/index.d.cts",
|
|
88
|
+
"default": "./dist/vin/index.cjs"
|
|
89
|
+
}
|
|
80
90
|
}
|
|
81
91
|
},
|
|
82
92
|
"files": [
|