@mailwoman/tiger 10.0.0 → 10.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/lib/block-group.ts +7 -7
- package/lib/class-code.ts +387 -266
- package/lib/constants.ts +7 -6
- package/lib/county/subdivision.ts +7 -7
- package/lib/{county/index.ts → county.ts} +7 -7
- package/lib/files.ts +37 -20
- package/lib/functional-status.ts +6 -4
- package/lib/geoid.ts +44 -26
- package/lib/index.ts +1 -1
- package/lib/legal-statistical-area.ts +7 -5
- package/lib/{sdk/schema.ts → schema.ts} +32 -42
- package/lib/state.ts +26 -23
- package/lib/tabulation-block.ts +4 -4
- package/lib/tract.ts +3 -3
- package/out/block-group.d.ts +7 -7
- package/out/class-code.d.ts +387 -266
- package/out/class-code.d.ts.map +1 -1
- package/out/class-code.js +387 -266
- package/out/class-code.js.map +1 -1
- package/out/constants.d.ts +7 -6
- package/out/constants.d.ts.map +1 -1
- package/out/constants.js +3 -3
- package/out/county/subdivision.d.ts +7 -7
- package/out/{county/index.d.ts → county.d.ts} +8 -8
- package/out/county.d.ts.map +1 -0
- package/out/{county/index.js → county.js} +2 -2
- package/out/county.js.map +1 -0
- package/out/files.d.ts +21 -13
- package/out/files.d.ts.map +1 -1
- package/out/files.js +27 -13
- package/out/files.js.map +1 -1
- package/out/functional-status.d.ts +6 -4
- package/out/functional-status.d.ts.map +1 -1
- package/out/functional-status.js +6 -4
- package/out/functional-status.js.map +1 -1
- package/out/geoid.d.ts +34 -16
- package/out/geoid.d.ts.map +1 -1
- package/out/geoid.js +16 -10
- package/out/geoid.js.map +1 -1
- package/out/index.d.ts +1 -1
- package/out/index.d.ts.map +1 -1
- package/out/index.js +1 -1
- package/out/index.js.map +1 -1
- package/out/legal-statistical-area.d.ts +7 -5
- package/out/legal-statistical-area.d.ts.map +1 -1
- package/out/legal-statistical-area.js +7 -5
- package/out/legal-statistical-area.js.map +1 -1
- package/out/{sdk/schema.d.ts → schema.d.ts} +26 -20
- package/out/schema.d.ts.map +1 -0
- package/out/{sdk/schema.js → schema.js} +12 -31
- package/out/schema.js.map +1 -0
- package/out/sdk/download.d.ts +7 -15
- package/out/sdk/download.d.ts.map +1 -1
- package/out/sdk/download.js +6 -15
- package/out/sdk/download.js.map +1 -1
- package/out/sdk/fetch.d.ts +36 -29
- package/out/sdk/fetch.d.ts.map +1 -1
- package/out/sdk/fetch.js +18 -53
- package/out/sdk/fetch.js.map +1 -1
- package/out/sdk/redistricting.d.ts +29 -15
- package/out/sdk/redistricting.d.ts.map +1 -1
- package/out/sdk/redistricting.js +47 -36
- package/out/sdk/redistricting.js.map +1 -1
- package/out/sdk/state/TIGERTabulatedBlockEntity.d.ts +2 -2
- package/out/sdk/state/TIGERTabulatedBlockEntity.d.ts.map +1 -1
- package/out/sdk/state/TIGERTabulatedBlockEntity.js +3 -3
- package/out/sdk/state/TIGERTabulatedBlockEntity.js.map +1 -1
- package/out/sdk/state/TIGERTractEntity.d.ts.map +1 -1
- package/out/sdk/state/TIGERTractEntity.js.map +1 -1
- package/out/sdk/state/block-operations.d.ts +3 -2
- package/out/sdk/state/block-operations.d.ts.map +1 -1
- package/out/sdk/state/block-operations.js +4 -3
- package/out/sdk/state/block-operations.js.map +1 -1
- package/out/sdk/{state/index.d.ts → state.d.ts} +1 -1
- package/out/sdk/state.d.ts.map +1 -0
- package/out/sdk/{state/index.js → state.js} +1 -1
- package/out/sdk/state.js.map +1 -0
- package/out/sdk/tsconfig.tsbuildinfo +1 -0
- package/out/state.d.ts +18 -15
- package/out/state.d.ts.map +1 -1
- package/out/state.js +17 -14
- package/out/state.js.map +1 -1
- package/out/tabulation-block.d.ts +4 -4
- package/out/tools/race/dots/map.d.ts +23 -9
- package/out/tools/race/dots/map.d.ts.map +1 -1
- package/out/tools/race/dots/map.js +9 -5
- package/out/tools/race/dots/map.js.map +1 -1
- package/out/tools/race/dots.d.ts +47 -0
- package/out/tools/race/dots.d.ts.map +1 -0
- package/out/tools/race/{dots/index.js → dots.js} +10 -27
- package/out/tools/race/dots.js.map +1 -0
- package/out/tools/serve-range.d.ts +13 -7
- package/out/tools/serve-range.d.ts.map +1 -1
- package/out/tools/serve-range.js +10 -8
- package/out/tools/serve-range.js.map +1 -1
- package/out/tools/tsconfig.tsbuildinfo +1 -0
- package/out/tract.d.ts +3 -3
- package/out/tsconfig.test.tsbuildinfo +1 -1
- package/package.json +61 -44
- package/sdk/download.ts +41 -0
- package/{lib/sdk → sdk}/fetch.ts +58 -62
- package/{lib/sdk → sdk}/redistricting.ts +57 -40
- package/{lib/sdk → sdk}/state/TIGERTabulatedBlockEntity.ts +3 -3
- package/{lib/sdk → sdk}/state/block-operations.ts +5 -4
- package/{lib/tools → tools}/race/dots/map.ts +30 -12
- package/{lib/tools/race/dots/index.ts → tools/race/dots.ts} +14 -31
- package/{lib/tools → tools}/serve-range.ts +17 -10
- package/lib/sdk/download.ts +0 -49
- package/lib/sdk/index.ts +0 -10
- package/lib/tools/index.ts +0 -11
- package/out/county/index.d.ts.map +0 -1
- package/out/county/index.js.map +0 -1
- package/out/sdk/index.d.ts +0 -10
- package/out/sdk/index.d.ts.map +0 -1
- package/out/sdk/index.js +0 -10
- package/out/sdk/index.js.map +0 -1
- package/out/sdk/schema.d.ts.map +0 -1
- package/out/sdk/schema.js.map +0 -1
- package/out/sdk/state/index.d.ts.map +0 -1
- package/out/sdk/state/index.js.map +0 -1
- package/out/tools/index.d.ts +0 -11
- package/out/tools/index.d.ts.map +0 -1
- package/out/tools/index.js +0 -11
- package/out/tools/index.js.map +0 -1
- package/out/tools/race/dots/index.d.ts +0 -61
- package/out/tools/race/dots/index.d.ts.map +0 -1
- package/out/tools/race/dots/index.js.map +0 -1
- /package/{lib/sdk → sdk}/state/TIGERTractEntity.ts +0 -0
- /package/{lib/sdk/state/index.ts → sdk/state.ts} +0 -0
package/lib/constants.ts
CHANGED
|
@@ -22,7 +22,7 @@ import type { FIPSStateCode } from "#state"
|
|
|
22
22
|
/**
|
|
23
23
|
* A code indicating the classification of the block, i.e. urban or rural.
|
|
24
24
|
*
|
|
25
|
-
* @title
|
|
25
|
+
* @title tiger Geographic Classification
|
|
26
26
|
*
|
|
27
27
|
* @minLength 1
|
|
28
28
|
* @maxLength 1
|
|
@@ -54,7 +54,7 @@ export const LandWaterBlockType = {
|
|
|
54
54
|
export type LandWaterBlockType = (typeof LandWaterBlockType)[keyof typeof LandWaterBlockType]
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
|
-
* @title
|
|
57
|
+
* @title tiger Property
|
|
58
58
|
*/
|
|
59
59
|
export const TIGERProperty = {
|
|
60
60
|
/**
|
|
@@ -106,7 +106,7 @@ export const TIGERProperty = {
|
|
|
106
106
|
*/
|
|
107
107
|
LegalStatisticalAreaDescription: "legal_statistical_area_description",
|
|
108
108
|
/**
|
|
109
|
-
* @title MAF/
|
|
109
|
+
* @title MAF/tiger Feature Class Code
|
|
110
110
|
*/
|
|
111
111
|
ClassCode: "class_code",
|
|
112
112
|
} as const
|
|
@@ -175,7 +175,8 @@ export interface TIGERPropertyRecord<GeoID extends string = string> {
|
|
|
175
175
|
/**
|
|
176
176
|
* A code indicating a specific urban area, such as a specific city, or a specific region of cities.
|
|
177
177
|
*
|
|
178
|
-
* For example, 23824 references Detroit, MI. 63217 references the region of
|
|
178
|
+
* For example, 23824 references Detroit, MI. 63217 references the region of
|
|
179
|
+
* New York City, Jersey City and Newark.
|
|
179
180
|
*
|
|
180
181
|
* @title Urban Area Code
|
|
181
182
|
* @minLength 5
|
|
@@ -204,7 +205,7 @@ export interface TIGERPropertyRecord<GeoID extends string = string> {
|
|
|
204
205
|
/**
|
|
205
206
|
* The tabulated block's housing unit count.
|
|
206
207
|
*
|
|
207
|
-
* Note: This is the number of housing units in the block
|
|
208
|
+
* Note: This is the number of housing units in the block rather than the number of people.
|
|
208
209
|
*
|
|
209
210
|
* @type {integer}
|
|
210
211
|
* @title Housing Units
|
|
@@ -227,7 +228,7 @@ export interface TIGERPropertyRecord<GeoID extends string = string> {
|
|
|
227
228
|
[TIGERProperty.LegalStatisticalAreaDescription]: LegalStatisticalAreaDescription
|
|
228
229
|
|
|
229
230
|
/**
|
|
230
|
-
* @title MAF/
|
|
231
|
+
* @title MAF/tiger Feature Class Code
|
|
231
232
|
*/
|
|
232
233
|
[TIGERProperty.ClassCode]: TIGERClassCode
|
|
233
234
|
|
|
@@ -12,7 +12,7 @@ import type { AdminLevel1Code } from "#state"
|
|
|
12
12
|
/**
|
|
13
13
|
* Census Geographic subdivision of a county.
|
|
14
14
|
*
|
|
15
|
-
* @title
|
|
15
|
+
* @title tiger County Subdivision
|
|
16
16
|
* @public
|
|
17
17
|
*/
|
|
18
18
|
export interface TIGERCountySubdivision {
|
|
@@ -39,16 +39,16 @@ export interface TIGERCountySubdivision {
|
|
|
39
39
|
COUSUBFP: string
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
|
-
* @title County Subdivision
|
|
42
|
+
* @title County Subdivision gnis Code
|
|
43
43
|
*
|
|
44
44
|
* @minLength 8
|
|
45
45
|
* @maxLength 8
|
|
46
46
|
* @pattern ^\d{8}$
|
|
47
|
-
* @see {@link https://www.usgs.gov/us-board-on-geographic-names/domestic-names |
|
|
47
|
+
* @see {@link https://www.usgs.gov/us-board-on-geographic-names/domestic-names | usgs: Domestic Names}
|
|
48
48
|
*/
|
|
49
49
|
COUSUBNS: string
|
|
50
50
|
/**
|
|
51
|
-
* Concatenation of current state FIPS code, county FIPS code
|
|
51
|
+
* Concatenation of current state FIPS code, county FIPS code and county subdivision FIPS code.
|
|
52
52
|
*
|
|
53
53
|
* @title County Sub-division Identifier
|
|
54
54
|
* @minLength 10
|
|
@@ -59,7 +59,7 @@ export interface TIGERCountySubdivision {
|
|
|
59
59
|
GEOID: string
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
|
-
* Fully Qualified
|
|
62
|
+
* Fully Qualified geoid as used in cedsci and other systems.
|
|
63
63
|
*
|
|
64
64
|
* @title Fully Qualified Geographic Identifier
|
|
65
65
|
* @minLength 19
|
|
@@ -92,9 +92,9 @@ export interface TIGERCountySubdivision {
|
|
|
92
92
|
CLASSFP: TIGERClassCode
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
|
-
* MAF/
|
|
95
|
+
* MAF/tiger Feature Class Code.
|
|
96
96
|
*
|
|
97
|
-
* @title MAF/
|
|
97
|
+
* @title MAF/tiger Feature Class Code
|
|
98
98
|
*
|
|
99
99
|
* @minLength 5
|
|
100
100
|
* @maxLength 5
|
|
@@ -10,7 +10,7 @@ import type { LegalStatisticalAreaDescription } from "#legal-statistical-area"
|
|
|
10
10
|
import type { AdminLevel1Code } from "#state"
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* @title
|
|
13
|
+
* @title tiger County
|
|
14
14
|
* @public
|
|
15
15
|
*/
|
|
16
16
|
export interface TIGERCounty {
|
|
@@ -28,17 +28,17 @@ export interface TIGERCounty {
|
|
|
28
28
|
COUNTYFP: string
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
* @title County
|
|
31
|
+
* @title County gnis Code
|
|
32
32
|
*
|
|
33
33
|
* @minLength 8
|
|
34
34
|
* @maxLength 8
|
|
35
35
|
* @pattern ^\d{8}$
|
|
36
|
-
* @see {@link https://www.usgs.gov/us-board-on-geographic-names/domestic-names |
|
|
36
|
+
* @see {@link https://www.usgs.gov/us-board-on-geographic-names/domestic-names | usgs: Domestic Names}
|
|
37
37
|
*/
|
|
38
38
|
GEOID: string
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
-
* Fully Qualified
|
|
41
|
+
* Fully Qualified geoid as used in cedsci and other systems.
|
|
42
42
|
*
|
|
43
43
|
* @title Fully Qualified Geographic Identifier
|
|
44
44
|
* @minLength 19
|
|
@@ -71,9 +71,9 @@ export interface TIGERCounty {
|
|
|
71
71
|
CLASSFP: TIGERClassCode
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
|
-
* MAF/
|
|
74
|
+
* MAF/tiger Feature Class Code.
|
|
75
75
|
*
|
|
76
|
-
* @title MAF/
|
|
76
|
+
* @title MAF/tiger Feature Class Code
|
|
77
77
|
*
|
|
78
78
|
* @minLength 5
|
|
79
79
|
* @maxLength 5
|
|
@@ -132,6 +132,6 @@ export interface TIGERCounty {
|
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
/**
|
|
135
|
-
* Brand symbol marking a value as a
|
|
135
|
+
* Brand symbol marking a value as a tiger county record, so a bare object cannot be passed as one.
|
|
136
136
|
*/
|
|
137
137
|
export const TIGERCountySymbol = Symbol.for("TIGERCounty")
|
package/lib/files.ts
CHANGED
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
6
|
+
* tiger Census data utilities.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type { AdminLevel1Code } from "#state"
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
// #region Constants
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* Census
|
|
14
|
+
* Census tiger levels for geographic data.
|
|
15
15
|
*
|
|
16
16
|
* @category Census
|
|
17
17
|
*/
|
|
@@ -27,7 +27,7 @@ export const TIGERLevel = {
|
|
|
27
27
|
export type TIGERLevel = (typeof TIGERLevel)[keyof typeof TIGERLevel]
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
* File extension for
|
|
30
|
+
* File extension for tiger data files.
|
|
31
31
|
*
|
|
32
32
|
* @category Census
|
|
33
33
|
*/
|
|
@@ -45,11 +45,13 @@ export const TIGERFileExtension = {
|
|
|
45
45
|
*/
|
|
46
46
|
Attributes: ".dbf",
|
|
47
47
|
/**
|
|
48
|
-
* Coordinate system information.
|
|
48
|
+
* Coordinate system information.
|
|
49
|
+
*
|
|
50
|
+
* Describes the projection of the geographic data.
|
|
49
51
|
*/
|
|
50
52
|
Projection: ".prj",
|
|
51
53
|
/**
|
|
52
|
-
* Federal Geographic Data Committee (
|
|
54
|
+
* Federal Geographic Data Committee (fgdc) metadata.
|
|
53
55
|
*/
|
|
54
56
|
FGDCMetadata: ".shp.xml",
|
|
55
57
|
/**
|
|
@@ -72,7 +74,7 @@ export const TIGERFileExtension = {
|
|
|
72
74
|
export type TIGERFileExtension = (typeof TIGERFileExtension)[keyof typeof TIGERFileExtension]
|
|
73
75
|
|
|
74
76
|
/**
|
|
75
|
-
* Order of
|
|
77
|
+
* Order of tiger levels for processing, from largest to smallest.
|
|
76
78
|
*/
|
|
77
79
|
export const TIGERLevelOrder = [
|
|
78
80
|
TIGERLevel.State,
|
|
@@ -83,7 +85,7 @@ export const TIGERLevelOrder = [
|
|
|
83
85
|
] as const satisfies TIGERLevel[]
|
|
84
86
|
|
|
85
87
|
/**
|
|
86
|
-
* The current
|
|
88
|
+
* The current tiger vintage.
|
|
87
89
|
*
|
|
88
90
|
* @category Census
|
|
89
91
|
* @internal
|
|
@@ -92,12 +94,27 @@ export const TIGERCurrentVintage = 2023
|
|
|
92
94
|
|
|
93
95
|
export type TIGERCurrentVintage = typeof TIGERCurrentVintage
|
|
94
96
|
|
|
95
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Parses a TIGER release tag such as `TIGER2023` into its vintage year.
|
|
99
|
+
*
|
|
100
|
+
* @throws Error when the tag is not `TIGER` followed by a four-digit year.
|
|
101
|
+
*/
|
|
102
|
+
export function parseTIGERRelease(release: string): number {
|
|
103
|
+
const match = /^TIGER(\d{4})$/.exec(release)
|
|
104
|
+
|
|
105
|
+
if (!match) {
|
|
106
|
+
throw new Error(`A TIGER release tag looks like TIGER${TIGERCurrentVintage}, but got "${release}".`)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return Number(match[1])
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// #endregion
|
|
96
113
|
|
|
97
|
-
|
|
114
|
+
// #region File Name Generation
|
|
98
115
|
|
|
99
116
|
/**
|
|
100
|
-
* Type-helper for
|
|
117
|
+
* Type-helper for tiger feature geometry file names.
|
|
101
118
|
*
|
|
102
119
|
* @category Census
|
|
103
120
|
*/
|
|
@@ -109,7 +126,7 @@ export type TIGERStateLevelFileName<
|
|
|
109
126
|
> = `tl_${Vintage}_${SFC}_${Level}${FileExtension}`
|
|
110
127
|
|
|
111
128
|
/**
|
|
112
|
-
* Template function to generate a
|
|
129
|
+
* Template function to generate a tiger file name.
|
|
113
130
|
*/
|
|
114
131
|
export function TIGERStateLevelFileName<
|
|
115
132
|
SFC extends AdminLevel1Code,
|
|
@@ -134,7 +151,7 @@ export type TIGERStateLevelZIPPath<
|
|
|
134
151
|
> = `/geo/tiger/TIGER${Vintage}/${Uppercase<Level>}/${TIGERStateLevelFileName<SFC, Level, typeof TIGERFileExtension.Zip, Vintage>}`
|
|
135
152
|
|
|
136
153
|
/**
|
|
137
|
-
* Template function to generate a
|
|
154
|
+
* Template function to generate a tiger ZIP file path.
|
|
138
155
|
*/
|
|
139
156
|
export function TIGERStateLevelZIPPath<
|
|
140
157
|
SFC extends AdminLevel1Code,
|
|
@@ -154,7 +171,7 @@ export function TIGERStateLevelZIPPath<
|
|
|
154
171
|
}
|
|
155
172
|
|
|
156
173
|
/**
|
|
157
|
-
* Template function to generate a
|
|
174
|
+
* Template function to generate a tiger ZIP file path.
|
|
158
175
|
*/
|
|
159
176
|
export function TIGERNationZIPPath<Vintage extends number = TIGERCurrentVintage>(
|
|
160
177
|
vintage: Vintage = TIGERCurrentVintage as Vintage
|
|
@@ -163,17 +180,17 @@ export function TIGERNationZIPPath<Vintage extends number = TIGERCurrentVintage>
|
|
|
163
180
|
|
|
164
181
|
const path = `/geo/tiger/TIGER${vintage}/STATE/${fileName}` as const
|
|
165
182
|
|
|
166
|
-
// https://www2.census.gov/geo/tiger/TIGER2023/
|
|
183
|
+
// https://www2.census.gov/geo/tiger/TIGER2023/state/tl_2023_us_state.zip
|
|
167
184
|
|
|
168
185
|
return path
|
|
169
186
|
}
|
|
170
187
|
|
|
171
|
-
|
|
188
|
+
// #endregion
|
|
172
189
|
|
|
173
|
-
|
|
190
|
+
// #region Manifests
|
|
174
191
|
|
|
175
192
|
/**
|
|
176
|
-
* A
|
|
193
|
+
* A tiger manifest for a specific state at a specific level of detail.
|
|
177
194
|
*
|
|
178
195
|
* @category Census
|
|
179
196
|
*/
|
|
@@ -231,7 +248,7 @@ export function TIGERLevelManifest<
|
|
|
231
248
|
}
|
|
232
249
|
|
|
233
250
|
/**
|
|
234
|
-
* A full
|
|
251
|
+
* A full tiger manifest for a specific state.
|
|
235
252
|
*/
|
|
236
253
|
export interface TIGERStateManifest<SFC extends AdminLevel1Code, Vintage extends number = TIGERCurrentVintage> {
|
|
237
254
|
Tract: TIGERLevelManifest<SFC, typeof TIGERLevel.Tract, Vintage>
|
|
@@ -261,4 +278,4 @@ export function TIGERStateManifest<SFC extends AdminLevel1Code, Vintage extends
|
|
|
261
278
|
return manifest as TIGERStateManifest<SFC, Vintage>
|
|
262
279
|
}
|
|
263
280
|
|
|
264
|
-
|
|
281
|
+
// #endregion
|
package/lib/functional-status.ts
CHANGED
|
@@ -7,16 +7,18 @@
|
|
|
7
7
|
/**
|
|
8
8
|
* A code indicating the functional status of a governmental unit.
|
|
9
9
|
*
|
|
10
|
-
* @title
|
|
10
|
+
* @title tiger Functional Status
|
|
11
11
|
*/
|
|
12
12
|
export const TIGERFunctionalStatus = {
|
|
13
13
|
/**
|
|
14
|
-
* Active government providing primary general-purpose functions.
|
|
14
|
+
* Active government providing primary general-purpose functions.
|
|
15
|
+
*
|
|
16
|
+
* Active entity (federally recognized entities only).
|
|
15
17
|
*/
|
|
16
18
|
ActiveGovernment: "A",
|
|
17
19
|
/**
|
|
18
|
-
* Active government that is partially consolidated with another government
|
|
19
|
-
* primary general-purpose functions.
|
|
20
|
+
* Active government that is partially consolidated with another government
|
|
21
|
+
* but with separate officials providing primary general-purpose functions.
|
|
20
22
|
*/
|
|
21
23
|
PartiallyConsolidatedActiveGovernment: "B",
|
|
22
24
|
/**
|
package/lib/geoid.ts
CHANGED
|
@@ -8,13 +8,13 @@ import type { Tagged } from "type-fest"
|
|
|
8
8
|
|
|
9
9
|
import type { AdminLevel1Code, FIPSStateCode } from "#state"
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
// #region Tagged FIPS types
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* A 4-digit number assigned by the Census to uniquely identify a block.
|
|
15
15
|
*
|
|
16
16
|
* ```txt
|
|
17
|
-
* (State Code)━━┳┓
|
|
17
|
+
* (State Code)━━┳┓ ┏┳┳┳┳┳━━(Tract Code)
|
|
18
18
|
* 482012231001050
|
|
19
19
|
* ┗╋┛ ┗┻┻┻━(Block Code)
|
|
20
20
|
* (County Code)
|
|
@@ -36,7 +36,7 @@ export type FIPSBlockCode = Tagged<string, "FIPSBlockCode">
|
|
|
36
36
|
* A 15-digit number assigned by the Census to uniquely identify a block.
|
|
37
37
|
*
|
|
38
38
|
* ```txt
|
|
39
|
-
* (State Code)━━┳┓
|
|
39
|
+
* (State Code)━━┳┓ ┏┳┳┳┳┳━━(Tract Code)
|
|
40
40
|
* 482012231001050
|
|
41
41
|
* ┗╋┛ ┗┻┻┻━(Block Code)
|
|
42
42
|
* (County Code)
|
|
@@ -57,7 +57,7 @@ export type FIPSBlockGeoID = Tagged<string, "FIPSBlockGeoID">
|
|
|
57
57
|
* A 1-digit number assigned by the Census to uniquely identify a block group.
|
|
58
58
|
*
|
|
59
59
|
* ```txt
|
|
60
|
-
* (State Code)━━┳┓
|
|
60
|
+
* (State Code)━━┳┓ ┏┳┳┳┳┳━━(Tract Code)
|
|
61
61
|
* 060133740002###
|
|
62
62
|
* ┗╋┛ ┗━(Block Group Code)
|
|
63
63
|
* (County Code)
|
|
@@ -79,7 +79,7 @@ export type FIPSBlockGroupCode = Tagged<string, "FIPSBlockGroupCode">
|
|
|
79
79
|
* A 6-digit number assigned by the Census to uniquely identify a tract.
|
|
80
80
|
*
|
|
81
81
|
* ```txt
|
|
82
|
-
* (State Code)━━┳┓
|
|
82
|
+
* (State Code)━━┳┓ ┏┳┳┳┳┳━━(Tract Code)
|
|
83
83
|
* 06013374000####
|
|
84
84
|
* ┗╋┛
|
|
85
85
|
* (County Code)
|
|
@@ -101,7 +101,7 @@ export type FIPSTractCode = Tagged<string, "FIPSTractCode">
|
|
|
101
101
|
* An 11-digit number assigned by the Census to uniquely identify a tract.
|
|
102
102
|
*
|
|
103
103
|
* ```txt
|
|
104
|
-
* (State Code)━━┳┓
|
|
104
|
+
* (State Code)━━┳┓ ┏┳┳┳┳┳━━(Tract Code)
|
|
105
105
|
* 06013374000####
|
|
106
106
|
* ┗╋┛
|
|
107
107
|
* (County Code)
|
|
@@ -122,7 +122,7 @@ export type FIPSTractGeoID = Tagged<string, "FIPSTractGeoID">
|
|
|
122
122
|
* A 5-digit number assigned by the Census to uniquely identify a county sub-division.
|
|
123
123
|
*
|
|
124
124
|
* ```txt
|
|
125
|
-
* (State Code)━━┳┓
|
|
125
|
+
* (State Code)━━┳┓ ┏┳┳┳┳━━(County Sub-Division Code)
|
|
126
126
|
* 0601337400#####
|
|
127
127
|
* ┗╋┛
|
|
128
128
|
* (County Code)
|
|
@@ -201,9 +201,9 @@ export type FIPSPlaceCode = Tagged<string, "FIPSPlaceCode">
|
|
|
201
201
|
*/
|
|
202
202
|
export type FIPSCongressionalDistrictCode = Tagged<string, "FIPSConressionalDistrictCode">
|
|
203
203
|
|
|
204
|
-
|
|
204
|
+
// #endregion
|
|
205
205
|
|
|
206
|
-
|
|
206
|
+
// #region GeoID Parsing Setup
|
|
207
207
|
|
|
208
208
|
/**
|
|
209
209
|
* A part of a GeoID to it's respective name.
|
|
@@ -238,15 +238,21 @@ export const GeoIDPart = {
|
|
|
238
238
|
*/
|
|
239
239
|
Place: "place_code",
|
|
240
240
|
/**
|
|
241
|
-
* The tract code part of a GeoID.
|
|
241
|
+
* The tract code part of a GeoID.
|
|
242
|
+
*
|
|
243
|
+
* The third most granular part.
|
|
242
244
|
*/
|
|
243
245
|
Tract: "tract_code",
|
|
244
246
|
/**
|
|
245
|
-
* The block group code part of a GeoID.
|
|
247
|
+
* The block group code part of a GeoID.
|
|
248
|
+
*
|
|
249
|
+
* The second most granular part.
|
|
246
250
|
*/
|
|
247
251
|
BlockGroup: "block_group_code",
|
|
248
252
|
/**
|
|
249
|
-
* The block code part of a GeoID.
|
|
253
|
+
* The block code part of a GeoID.
|
|
254
|
+
*
|
|
255
|
+
* The most granular part.
|
|
250
256
|
*/
|
|
251
257
|
Block: "block_code",
|
|
252
258
|
} as const
|
|
@@ -254,7 +260,7 @@ export const GeoIDPart = {
|
|
|
254
260
|
export type GeoIDPart = (typeof GeoIDPart)[keyof typeof GeoIDPart]
|
|
255
261
|
|
|
256
262
|
/**
|
|
257
|
-
*
|
|
263
|
+
* This interface maps each `GeoID` part to its corresponding FIPS code type.
|
|
258
264
|
*
|
|
259
265
|
* @internal
|
|
260
266
|
*/
|
|
@@ -288,7 +294,9 @@ export const GeoIDPartLength = {
|
|
|
288
294
|
} as const satisfies Record<GeoIDPart, number>
|
|
289
295
|
|
|
290
296
|
/**
|
|
291
|
-
* A GeoID parsed to the block level.
|
|
297
|
+
* A GeoID parsed to the block level.
|
|
298
|
+
*
|
|
299
|
+
* The most granular level.
|
|
292
300
|
*
|
|
293
301
|
* @title Parsed GeoID Block Level
|
|
294
302
|
* @public
|
|
@@ -305,7 +313,9 @@ export interface ParsedGeoIDBlockLevel {
|
|
|
305
313
|
}
|
|
306
314
|
|
|
307
315
|
/**
|
|
308
|
-
* A GeoID parsed to the block group level.
|
|
316
|
+
* A GeoID parsed to the block group level.
|
|
317
|
+
*
|
|
318
|
+
* The second most granular level.
|
|
309
319
|
*
|
|
310
320
|
* @internal
|
|
311
321
|
*/
|
|
@@ -319,7 +329,9 @@ export interface ParsedGeoIDBlockGroupLevel {
|
|
|
319
329
|
}
|
|
320
330
|
|
|
321
331
|
/**
|
|
322
|
-
* A GeoID parsed to the tract level.
|
|
332
|
+
* A GeoID parsed to the tract level.
|
|
333
|
+
*
|
|
334
|
+
* The third most granular level.
|
|
323
335
|
*
|
|
324
336
|
* @internal
|
|
325
337
|
*/
|
|
@@ -340,7 +352,9 @@ export interface ParsedGeoIDTractLevel {
|
|
|
340
352
|
export type ParsedGeoIDPartial = Partial<Record<GeoIDPart, string>>
|
|
341
353
|
|
|
342
354
|
/**
|
|
343
|
-
* A GeoID parsed to the county-subdivision level.
|
|
355
|
+
* A GeoID parsed to the county-subdivision level.
|
|
356
|
+
*
|
|
357
|
+
* The fourth most granular level.
|
|
344
358
|
*
|
|
345
359
|
* @internal
|
|
346
360
|
*/
|
|
@@ -354,7 +368,9 @@ export interface ParsedGeoIDCountySubDivisionLevel {
|
|
|
354
368
|
}
|
|
355
369
|
|
|
356
370
|
/**
|
|
357
|
-
* A GeoID parsed to the county level.
|
|
371
|
+
* A GeoID parsed to the county level.
|
|
372
|
+
*
|
|
373
|
+
* The fifth most granular level.
|
|
358
374
|
*
|
|
359
375
|
* @internal
|
|
360
376
|
*/
|
|
@@ -368,7 +384,9 @@ export interface ParsedGeoIDCountyLevel {
|
|
|
368
384
|
}
|
|
369
385
|
|
|
370
386
|
/**
|
|
371
|
-
* A GeoID parsed to the state level.
|
|
387
|
+
* A GeoID parsed to the state level.
|
|
388
|
+
*
|
|
389
|
+
* The least granular level.
|
|
372
390
|
*
|
|
373
391
|
* @internal
|
|
374
392
|
*/
|
|
@@ -401,9 +419,9 @@ export class GeoIDParsingError extends Error {
|
|
|
401
419
|
}
|
|
402
420
|
}
|
|
403
421
|
|
|
404
|
-
|
|
422
|
+
// #endregion
|
|
405
423
|
|
|
406
|
-
|
|
424
|
+
// #region GeoID Input Matchers
|
|
407
425
|
|
|
408
426
|
export class GeoIDInputMatcher<T extends GeoIDPart[] = GeoIDPart[]> {
|
|
409
427
|
public pattern: RegExp
|
|
@@ -526,9 +544,9 @@ export function isGeoIDComponent<T extends GeoIDPart>(component: T, input: unkno
|
|
|
526
544
|
return matcher.test(input)
|
|
527
545
|
}
|
|
528
546
|
|
|
529
|
-
|
|
547
|
+
// #endregion
|
|
530
548
|
|
|
531
|
-
|
|
549
|
+
// #region GeoID Parsing
|
|
532
550
|
|
|
533
551
|
/**
|
|
534
552
|
* GeoID input matchers sorted by length in descending order, such that the most specific matchers are first.
|
|
@@ -625,9 +643,9 @@ export function parseGeoID(input: unknown): ParsedGeoID | null {
|
|
|
625
643
|
return null
|
|
626
644
|
}
|
|
627
645
|
|
|
628
|
-
|
|
646
|
+
// #endregion
|
|
629
647
|
|
|
630
|
-
|
|
648
|
+
// #region GeoID Formatting
|
|
631
649
|
|
|
632
650
|
/**
|
|
633
651
|
* Format a parsed block GeoID back into a string.
|
|
@@ -682,4 +700,4 @@ export function formatGeoID(input: unknown): string | null {
|
|
|
682
700
|
return null
|
|
683
701
|
}
|
|
684
702
|
|
|
685
|
-
|
|
703
|
+
// #endregion
|
package/lib/index.ts
CHANGED
|
@@ -8,7 +8,7 @@ export * from "#block-group"
|
|
|
8
8
|
export * from "#class-code"
|
|
9
9
|
export * from "#constants"
|
|
10
10
|
export * from "#county/subdivision"
|
|
11
|
-
export * from "#county
|
|
11
|
+
export * from "#county"
|
|
12
12
|
export * from "#files"
|
|
13
13
|
export * from "#functional-status"
|
|
14
14
|
export * from "#geoid"
|
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
/**
|
|
8
8
|
* Describes the particular typology for each geographic entity.
|
|
9
9
|
*
|
|
10
|
-
* For legal entities, the
|
|
11
|
-
* a treaty, charter, legislation, resolution, or ordinance.
|
|
10
|
+
* For legal entities, the lsad reflects the term that appears in legal documentation
|
|
11
|
+
* pertaining to the entity, such as a treaty, charter, legislation, resolution, or ordinance.
|
|
12
12
|
*
|
|
13
|
-
* For statistical entities, the
|
|
13
|
+
* For statistical entities, the lsad is the term assigned by the Census Bureau
|
|
14
|
+
* or other agency defining the entity.
|
|
14
15
|
*
|
|
15
16
|
* @title Legal/Statistical Area Description
|
|
16
17
|
*/
|
|
@@ -35,7 +36,7 @@ export const LegalStatisticalAreaDescription = {
|
|
|
35
36
|
* - State or Equivalent Feature
|
|
36
37
|
* - Tribal Subdivision
|
|
37
38
|
* - Unified School District
|
|
38
|
-
* - Voting District
|
|
39
|
+
* - A Voting District
|
|
39
40
|
*/
|
|
40
41
|
Other: "00",
|
|
41
42
|
/**
|
|
@@ -95,7 +96,8 @@ export const LegalStatisticalAreaDescription = {
|
|
|
95
96
|
*/
|
|
96
97
|
CensusSubDistrict: "24",
|
|
97
98
|
/**
|
|
98
|
-
* Consolidated City, County or Equivalent Feature, County Subdivision,
|
|
99
|
+
* Consolidated City, County or Equivalent Feature, County Subdivision,
|
|
100
|
+
* Economic Census Place, Incorporated Place.
|
|
99
101
|
*/
|
|
100
102
|
City: "25",
|
|
101
103
|
CountySuffixCountySubdivision: "26",
|