elections-types 1.0.12 → 1.0.13

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.
@@ -3,17 +3,19 @@ const office_ids = ["H", "S"];
3
3
  export function is_office_id(office_id) {
4
4
  return office_ids.includes(office_id);
5
5
  }
6
+ const state_ids_without_district = ["AK", "DE", "ND", "SD", "VT", "WY"];
6
7
  export function is_election_id(election_id) {
7
8
  const parts = election_id.split("-");
8
9
  const year = Number(parts[0]);
9
10
  const office_id = parts[1];
10
11
  const state_id = parts[2];
11
12
  const district = Number(parts[3]);
12
- return ((parts.length === 4 && office_id === "H" || parts.length === 3) &&
13
+ return (parts.length <= 4 &&
13
14
  Number.isInteger(year) && year > 1700 && year < 3000 &&
14
15
  is_office_id(office_id) &&
15
16
  is_state_id(state_id) &&
16
- (office_id === "S" || parts[3].length === 2 && Number.isInteger(district) && district < 100));
17
+ ((office_id === "S" || state_ids_without_district.includes(state_id)) && district === undefined ||
18
+ !(office_id === "S" || state_ids_without_district.includes(state_id)) && Number.isInteger(district) && district < 100));
17
19
  }
18
20
  export class Election {
19
21
  election_id;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elections-types",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
@@ -8,6 +8,8 @@ export function is_office_id(office_id : any) : office_id is OfficeID {
8
8
  return office_ids.includes(office_id)
9
9
  }
10
10
 
11
+ const state_ids_without_district : StateID[] = ["AK", "DE", "ND", "SD", "VT", "WY"]
12
+
11
13
  export type ElectionID = string
12
14
 
13
15
  export function is_election_id(election_id : any) : election_id is ElectionID {
@@ -17,11 +19,12 @@ export function is_election_id(election_id : any) : election_id is ElectionID {
17
19
  const state_id = parts[2]
18
20
  const district = Number(parts[3])
19
21
  return (
20
- (parts.length === 4 && office_id === "H" || parts.length === 3) &&
22
+ parts.length <= 4 &&
21
23
  Number.isInteger(year) && year > 1700 && year < 3000 &&
22
24
  is_office_id(office_id) &&
23
25
  is_state_id(state_id) &&
24
- (office_id === "S" || parts[3].length === 2 && Number.isInteger(district) && district < 100)
26
+ ((office_id === "S" || state_ids_without_district.includes(state_id)) && district === undefined ||
27
+ !(office_id === "S" || state_ids_without_district.includes(state_id)) && Number.isInteger(district) && district < 100)
25
28
  )
26
29
  }
27
30