elections-types 1.0.78 → 1.0.80
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.
|
@@ -2,7 +2,7 @@ import { CandidateAux } from "./Candidate.js";
|
|
|
2
2
|
import { CommitteeAux } from "./Committee.js";
|
|
3
3
|
import { ExpenditureAux } from "./Expenditure.js";
|
|
4
4
|
import { StateID } from "./State.js";
|
|
5
|
-
declare const office_ids: readonly ["H", "S"];
|
|
5
|
+
declare const office_ids: readonly ["H", "S", "P"];
|
|
6
6
|
export type OfficeID = typeof office_ids[number];
|
|
7
7
|
export declare function is_office_id(office_id: any): office_id is OfficeID;
|
|
8
8
|
export type ElectionID = string;
|
|
@@ -11,7 +11,7 @@ export declare class Election {
|
|
|
11
11
|
readonly election_id: ElectionID;
|
|
12
12
|
readonly name: string;
|
|
13
13
|
readonly office_id: OfficeID;
|
|
14
|
-
readonly state_id
|
|
14
|
+
readonly state_id?: StateID;
|
|
15
15
|
readonly district?: number;
|
|
16
16
|
readonly [x: string]: any;
|
|
17
17
|
constructor(election: Election);
|
|
@@ -2,7 +2,7 @@ import { CandidateAux } from "./Candidate.js";
|
|
|
2
2
|
import { CommitteeAux } from "./Committee.js";
|
|
3
3
|
import { ExpenditureAux } from "./Expenditure.js";
|
|
4
4
|
import { is_state_id } from "./State.js";
|
|
5
|
-
const office_ids = ["H", "S"];
|
|
5
|
+
const office_ids = ["H", "S", "P"];
|
|
6
6
|
export function is_office_id(office_id) {
|
|
7
7
|
return office_ids.includes(office_id);
|
|
8
8
|
}
|
|
@@ -13,12 +13,28 @@ export function is_election_id(election_id) {
|
|
|
13
13
|
const office_id = parts[1];
|
|
14
14
|
const state_id = parts[2];
|
|
15
15
|
const district = Number(parts[3]);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
if (!(Number.isInteger(year) && year > 1700 && year < 3000 && is_office_id(office_id))) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
if (office_id === "P" && parts.length === 2) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
if (!is_state_id(state_id)) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
if (office_id === "S" && parts.length === 3) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
if (office_id !== "H") {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
if (!(state_ids_without_district.includes(state_id) && parts.length === 3 || parts.length === 4)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
if (!Number.isInteger(district) && district < 100) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
return true;
|
|
22
38
|
}
|
|
23
39
|
export class Election {
|
|
24
40
|
election_id;
|
|
@@ -41,7 +57,7 @@ export class Election {
|
|
|
41
57
|
is_election_id(election.election_id) &&
|
|
42
58
|
typeof election.name === "string" &&
|
|
43
59
|
is_office_id(election.office_id) &&
|
|
44
|
-
is_state_id(election.state_id) &&
|
|
60
|
+
(election.state_id === undefined || is_state_id(election.state_id)) &&
|
|
45
61
|
(election.district === undefined || typeof election.district === "number"));
|
|
46
62
|
}
|
|
47
63
|
}
|
|
@@ -39,7 +39,7 @@ export class FECF1File extends FECFile {
|
|
|
39
39
|
typeof fec_file.report_date === "string" &&
|
|
40
40
|
is_committee_designation(fec_file.designation) &&
|
|
41
41
|
(fec_file.election_id === undefined || is_election_id(fec_file.election_id)) &&
|
|
42
|
-
(fec_file.candidate_id === undefined || typeof fec_file.
|
|
42
|
+
(fec_file.candidate_id === undefined || typeof fec_file.candidate_id === "string") &&
|
|
43
43
|
(fec_file.jfp_committee_ids === undefined || Array.isArray(fec_file.jfp_committee_ids) && fec_file.jfp_committee_ids.every((committee_id) => typeof committee_id === "string")) &&
|
|
44
44
|
(Array.isArray(fec_file.jfr_committee_ids) && fec_file.jfr_committee_ids.every((committee_id) => typeof committee_id === "string")) &&
|
|
45
45
|
(Array.isArray(fec_file.aff_committee_ids) && fec_file.aff_committee_ids.every((committee_id) => typeof committee_id === "string")) &&
|
package/package.json
CHANGED
package/src/types/Election.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Committee, CommitteeAux } from "./Committee"
|
|
|
3
3
|
import { ExpenditureAux } from "./Expenditure"
|
|
4
4
|
import { is_state_id, state_ids, StateID } from "./State"
|
|
5
5
|
|
|
6
|
-
const office_ids = ["H", "S"] as const
|
|
6
|
+
const office_ids = ["H", "S", "P"] as const
|
|
7
7
|
|
|
8
8
|
export type OfficeID = typeof office_ids[number]
|
|
9
9
|
|
|
@@ -21,21 +21,35 @@ export function is_election_id(election_id : any) : election_id is ElectionID {
|
|
|
21
21
|
const office_id = parts[1]
|
|
22
22
|
const state_id = parts[2]
|
|
23
23
|
const district = Number(parts[3])
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
if (!(Number.isInteger(year) && year > 1700 && year < 3000 && is_office_id(office_id))) {
|
|
25
|
+
return false
|
|
26
|
+
}
|
|
27
|
+
if (office_id === "P" && parts.length === 2) {
|
|
28
|
+
return true
|
|
29
|
+
}
|
|
30
|
+
if (!is_state_id(state_id)) {
|
|
31
|
+
return false
|
|
32
|
+
}
|
|
33
|
+
if (office_id === "S" && parts.length === 3) {
|
|
34
|
+
return true
|
|
35
|
+
}
|
|
36
|
+
if (office_id !== "H") {
|
|
37
|
+
return false
|
|
38
|
+
}
|
|
39
|
+
if (!(state_ids_without_district.includes(state_id) && parts.length === 3 || parts.length === 4)) {
|
|
40
|
+
return false
|
|
41
|
+
}
|
|
42
|
+
if (!Number.isInteger(district) && district < 100) {
|
|
43
|
+
return false
|
|
44
|
+
}
|
|
45
|
+
return true
|
|
32
46
|
}
|
|
33
47
|
|
|
34
48
|
export class Election {
|
|
35
49
|
readonly election_id : ElectionID
|
|
36
50
|
readonly name : string
|
|
37
51
|
readonly office_id : OfficeID
|
|
38
|
-
readonly state_id : StateID
|
|
52
|
+
readonly state_id? : StateID
|
|
39
53
|
readonly district? : number
|
|
40
54
|
readonly [x : string] : any
|
|
41
55
|
|
|
@@ -56,7 +70,7 @@ export class Election {
|
|
|
56
70
|
is_election_id(election.election_id) &&
|
|
57
71
|
typeof election.name === "string" &&
|
|
58
72
|
is_office_id(election.office_id) &&
|
|
59
|
-
is_state_id(election.state_id) &&
|
|
73
|
+
(election.state_id === undefined || is_state_id(election.state_id)) &&
|
|
60
74
|
(election.district === undefined || typeof election.district === "number")
|
|
61
75
|
)
|
|
62
76
|
}
|
package/src/types/FECF1File.ts
CHANGED
|
@@ -43,7 +43,7 @@ export class FECF1File extends FECFile {
|
|
|
43
43
|
typeof fec_file.report_date === "string" &&
|
|
44
44
|
is_committee_designation(fec_file.designation) &&
|
|
45
45
|
(fec_file.election_id === undefined || is_election_id(fec_file.election_id)) &&
|
|
46
|
-
(fec_file.candidate_id === undefined || typeof fec_file.
|
|
46
|
+
(fec_file.candidate_id === undefined || typeof fec_file.candidate_id === "string") &&
|
|
47
47
|
(fec_file.jfp_committee_ids === undefined || Array.isArray(fec_file.jfp_committee_ids) && fec_file.jfp_committee_ids.every((committee_id : any) => typeof committee_id === "string")) &&
|
|
48
48
|
(Array.isArray(fec_file.jfr_committee_ids) && fec_file.jfr_committee_ids.every((committee_id : any) => typeof committee_id === "string")) &&
|
|
49
49
|
(Array.isArray(fec_file.aff_committee_ids) && fec_file.aff_committee_ids.every((committee_id : any) => typeof committee_id === "string")) &&
|