elections-types 1.0.77 → 1.0.79
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
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { AmendmentTypeID, FormTypeID, LongFormTypeID } from "./FormTypeID.js";
|
|
2
|
+
export declare const form_version_ids: readonly ["8.1", "8.2", "8.3", "8.4", "8.5"];
|
|
3
|
+
export type FormVersionID = typeof form_version_ids[number];
|
|
4
|
+
export declare function is_form_version_id(form_version_id: any): form_version_id is FormVersionID;
|
|
2
5
|
export declare class FECFile {
|
|
3
6
|
readonly fec_file_id: number;
|
|
7
|
+
readonly form_version_id: FormVersionID;
|
|
4
8
|
readonly form_type_id: FormTypeID;
|
|
5
9
|
readonly amendment_type_id: AmendmentTypeID;
|
|
6
10
|
readonly long_form_type_id: LongFormTypeID;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { is_amendment_type_id, is_form_type_id, is_long_form_type_id } from "./FormTypeID.js";
|
|
2
|
+
export const form_version_ids = ["8.1", "8.2", "8.3", "8.4", "8.5"];
|
|
3
|
+
export function is_form_version_id(form_version_id) {
|
|
4
|
+
return form_version_ids.includes(form_version_id);
|
|
5
|
+
}
|
|
2
6
|
export class FECFile {
|
|
3
7
|
fec_file_id;
|
|
8
|
+
form_version_id;
|
|
4
9
|
form_type_id;
|
|
5
10
|
amendment_type_id;
|
|
6
11
|
long_form_type_id;
|
|
@@ -10,6 +15,7 @@ export class FECFile {
|
|
|
10
15
|
throw Error("Invalid input.");
|
|
11
16
|
}
|
|
12
17
|
this.fec_file_id = fec_file.fec_file_id;
|
|
18
|
+
this.form_version_id = fec_file.form_version_id;
|
|
13
19
|
this.form_type_id = fec_file.form_type_id;
|
|
14
20
|
this.amendment_type_id = fec_file.amendment_type_id;
|
|
15
21
|
this.long_form_type_id = fec_file.long_form_type_id;
|
|
@@ -18,6 +24,7 @@ export class FECFile {
|
|
|
18
24
|
static is(fec_file) {
|
|
19
25
|
return (fec_file !== undefined &&
|
|
20
26
|
typeof fec_file.fec_file_id === "number" &&
|
|
27
|
+
is_form_version_id(fec_file.form_version_id) &&
|
|
21
28
|
is_form_type_id(fec_file.form_type_id) &&
|
|
22
29
|
is_amendment_type_id(fec_file.amendment_type_id) &&
|
|
23
30
|
is_long_form_type_id(fec_file.long_form_type_id) &&
|
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/FECFile.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import { AmendmentTypeID, FormTypeID, is_amendment_type_id, is_form_type_id, is_long_form_type_id, LongFormTypeID } from "./FormTypeID"
|
|
2
2
|
|
|
3
|
+
export const form_version_ids = ["8.1", "8.2", "8.3", "8.4", "8.5"] as const
|
|
4
|
+
|
|
5
|
+
export type FormVersionID = typeof form_version_ids[number]
|
|
6
|
+
|
|
7
|
+
export function is_form_version_id(form_version_id : any) : form_version_id is FormVersionID {
|
|
8
|
+
return form_version_ids.includes(form_version_id)
|
|
9
|
+
}
|
|
10
|
+
|
|
3
11
|
export class FECFile {
|
|
4
12
|
readonly fec_file_id : number
|
|
13
|
+
readonly form_version_id : FormVersionID
|
|
5
14
|
readonly form_type_id : FormTypeID
|
|
6
15
|
readonly amendment_type_id : AmendmentTypeID
|
|
7
16
|
readonly long_form_type_id : LongFormTypeID
|
|
@@ -13,6 +22,7 @@ export class FECFile {
|
|
|
13
22
|
throw Error("Invalid input.")
|
|
14
23
|
}
|
|
15
24
|
this.fec_file_id = fec_file.fec_file_id
|
|
25
|
+
this.form_version_id = fec_file.form_version_id
|
|
16
26
|
this.form_type_id = fec_file.form_type_id
|
|
17
27
|
this.amendment_type_id = fec_file.amendment_type_id
|
|
18
28
|
this.long_form_type_id = fec_file.long_form_type_id
|
|
@@ -23,6 +33,7 @@ export class FECFile {
|
|
|
23
33
|
return (
|
|
24
34
|
fec_file !== undefined &&
|
|
25
35
|
typeof fec_file.fec_file_id === "number" &&
|
|
36
|
+
is_form_version_id(fec_file.form_version_id) &&
|
|
26
37
|
is_form_type_id(fec_file.form_type_id) &&
|
|
27
38
|
is_amendment_type_id(fec_file.amendment_type_id) &&
|
|
28
39
|
is_long_form_type_id(fec_file.long_form_type_id) &&
|