indycheck 0.1.2 → 0.2.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/index.d.ts CHANGED
@@ -144,10 +144,13 @@ export interface VoterParsed {
144
144
  }
145
145
  export interface VehicleParsed {
146
146
  registration: string;
147
- state_code: string;
148
- district: string;
147
+ series_type: "state" | "bharat";
148
+ state_code?: string;
149
+ district?: string;
149
150
  series: string;
150
151
  number: string;
152
+ year?: string;
153
+ suffix?: string;
151
154
  }
152
155
  export interface DetectParsed {
153
156
  type: string | null;
package/dist/index.js CHANGED
@@ -905,6 +905,11 @@ function validateVehicle(input) {
905
905
  if (chars.length < 8 || chars.length > 10) {
906
906
  return fail("INVALID_LENGTH", "Vehicle registration number must be 8-10 characters (e.g. DL01AB1234)", "Vehicle registration number 8 se 10 character ka hona chahiye (jaise DL01AB1234)");
907
907
  }
908
+ // Bharat (BH) series: YYBH####XX — starts with 2 digits (the year),
909
+ // so it must be checked before the state format (2 leading letters).
910
+ if (chars.slice(0, 2).every(isAsciiDigit)) {
911
+ return validateBharat(cleaned, chars);
912
+ }
908
913
  if (!chars.slice(0, 2).every(isAsciiAlpha)) {
909
914
  return fail("INVALID_FORMAT", "Vehicle registration number must start with 2 state-code letters (e.g. DL01AB1234)", "Vehicle registration number 2 state-code akshar se shuru hona chahiye (jaise DL01AB1234)");
910
915
  }
@@ -927,12 +932,37 @@ function validateVehicle(input) {
927
932
  return fail("INVALID_FORMAT", "Vehicle registration format must be state letters + district digits + series letters + number digits (e.g. DL01AB1234). Registration numbers have no checksum, so only the format is checked", "Vehicle registration ka format state akshar + district digit + series akshar + number digit hona chahiye (jaise DL01AB1234). Registration number ka koi checksum nahi hai, isliye sirf format check hota hai");
928
933
  }
929
934
  const stateCode = chars.slice(0, 2).join("");
930
- return ok("Vehicle registration format is valid. Registration numbers have no checksum, so this only checks the format", "Vehicle registration ka format sahi hai. Registration number ka koi checksum nahi hai, isliye sirf format check hua hai", { registration: cleaned, state_code: stateCode, district, series, number });
935
+ return ok("Vehicle registration format is valid. Registration numbers have no checksum, so this only checks the format", "Vehicle registration ka format sahi hai. Registration number ka koi checksum nahi hai, isliye sirf format check hua hai", { registration: cleaned, series_type: "state", state_code: stateCode, district, series, number });
931
936
  }
932
937
  catch {
933
938
  return invalidType();
934
939
  }
935
940
  }
941
+ /** Bharat (BH) series: `YYBH####XX` — called only when the cleaned input starts with digits. */
942
+ function validateBharat(cleaned, chars) {
943
+ const notBharat = (en, hi) => fail("INVALID_FORMAT", en, hi);
944
+ const shapeOk = chars.length === 10 &&
945
+ chars[2] === "B" &&
946
+ chars[3] === "H" &&
947
+ chars.slice(4, 8).every(isAsciiDigit) &&
948
+ chars.slice(8, 10).every(isAsciiAlpha);
949
+ if (!shapeOk) {
950
+ return notBharat("Vehicle registration number must start with 2 state-code letters (e.g. DL01AB1234), or be a Bharat series number (e.g. 22BH1234AA)", "Vehicle registration number 2 state-code akshar se shuru hona chahiye (jaise DL01AB1234), ya Bharat series number hona chahiye (jaise 22BH1234AA)");
951
+ }
952
+ const year = chars.slice(0, 2).join("");
953
+ if (Number(year) < 21) {
954
+ return notBharat("Bharat (BH) series numbers start from 2021 — the year must be 21 or later (e.g. 22BH1234AA)", "Bharat (BH) series number 2021 se shuru hue hain — saal 21 ya usse baad ka hona chahiye (jaise 22BH1234AA)");
955
+ }
956
+ const number = chars.slice(4, 8).join("");
957
+ if (number === "0000") {
958
+ return notBharat("Bharat (BH) series number must be 0001-9999 (e.g. 22BH1234AA)", "Bharat (BH) series number 0001 se 9999 ke beech hona chahiye (jaise 22BH1234AA)");
959
+ }
960
+ const suffix = chars.slice(8, 10).join("");
961
+ if (suffix.includes("I") || suffix.includes("O")) {
962
+ return notBharat("Bharat (BH) series suffix letters cannot be I or O (e.g. 22BH1234AA)", "Bharat (BH) series ke aakhiri akshar I ya O nahi ho sakte (jaise 22BH1234AA)");
963
+ }
964
+ return ok("Bharat (BH) series vehicle registration format is valid. Registration numbers have no checksum, so this only checks the format", "Bharat (BH) series vehicle registration ka format sahi hai. Registration number ka koi checksum nahi hai, isliye sirf format check hua hai", { registration: cleaned, series_type: "bharat", year, series: "BH", number, suffix });
965
+ }
936
966
  /** Alias for `validateVehicle`. */
937
967
  function validateVehicleRegistration(input) {
938
968
  return validateVehicle(input);
package/package.json CHANGED
@@ -37,5 +37,5 @@
37
37
  "typecheck": "tsc --noEmit"
38
38
  },
39
39
  "types": "dist/index.d.ts",
40
- "version": "0.1.2"
40
+ "version": "0.2.0"
41
41
  }