us-water-quality-data 1.0.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/LICENSE +37 -0
- package/README.md +96 -0
- package/data.json +132491 -0
- package/index.d.ts +39 -0
- package/index.js +47 -0
- package/index.mjs +42 -0
- package/package.json +40 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface WaterQualityEntry {
|
|
2
|
+
zip: string;
|
|
3
|
+
city: string;
|
|
4
|
+
state: string;
|
|
5
|
+
system_name: string;
|
|
6
|
+
pwsid: string;
|
|
7
|
+
population: number;
|
|
8
|
+
water_source: 'SW' | 'GW';
|
|
9
|
+
total_violations: number;
|
|
10
|
+
health_violations: number;
|
|
11
|
+
unresolved_violations: number;
|
|
12
|
+
lead_level_mg_l: number | null;
|
|
13
|
+
copper_level_mg_l: number | null;
|
|
14
|
+
radon_zone: 1 | 2 | 3 | null;
|
|
15
|
+
home_safety_score: number | null;
|
|
16
|
+
home_safety_grade: 'A' | 'B' | 'C' | 'D' | 'F' | null;
|
|
17
|
+
latitude: number;
|
|
18
|
+
longitude: number;
|
|
19
|
+
contaminant_count: number;
|
|
20
|
+
health_contaminant_names: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Get water quality data for a ZIP code */
|
|
24
|
+
export function getByZip(zip: string | number): WaterQualityEntry | null;
|
|
25
|
+
|
|
26
|
+
/** Get all entries for a state (2-letter code) */
|
|
27
|
+
export function getByState(state: string): WaterQualityEntry[];
|
|
28
|
+
|
|
29
|
+
/** Get all entries */
|
|
30
|
+
export function getAll(): WaterQualityEntry[];
|
|
31
|
+
|
|
32
|
+
/** Get all entries with score at or below threshold (default 50) */
|
|
33
|
+
export function getUnsafe(maxScore?: number): WaterQualityEntry[];
|
|
34
|
+
|
|
35
|
+
/** Get all entries containing a specific contaminant */
|
|
36
|
+
export function getByContaminant(name: string): WaterQualityEntry[];
|
|
37
|
+
|
|
38
|
+
/** Raw data array */
|
|
39
|
+
export const data: WaterQualityEntry[];
|
package/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const data = require('./data.json');
|
|
4
|
+
|
|
5
|
+
const zipIndex = Object.create(null);
|
|
6
|
+
const stateIndex = Object.create(null);
|
|
7
|
+
|
|
8
|
+
for (let i = 0; i < data.length; i++) {
|
|
9
|
+
const entry = data[i];
|
|
10
|
+
zipIndex[entry.zip] = entry;
|
|
11
|
+
if (!stateIndex[entry.state]) stateIndex[entry.state] = [];
|
|
12
|
+
stateIndex[entry.state].push(entry);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Get water quality data for a ZIP code */
|
|
16
|
+
function getByZip(zip) {
|
|
17
|
+
return zipIndex[String(zip).padStart(5, '0')] || null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Get all entries for a state (2-letter code) */
|
|
21
|
+
function getByState(state) {
|
|
22
|
+
return stateIndex[String(state).toUpperCase()] || [];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Get all entries */
|
|
26
|
+
function getAll() {
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Get all entries with score below threshold */
|
|
31
|
+
function getUnsafe(maxScore) {
|
|
32
|
+
if (maxScore === undefined) maxScore = 50;
|
|
33
|
+
return data.filter(function (d) {
|
|
34
|
+
return d.home_safety_score !== null && d.home_safety_score <= maxScore;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Get all entries with a specific contaminant */
|
|
39
|
+
function getByContaminant(name) {
|
|
40
|
+
var lower = String(name).toLowerCase();
|
|
41
|
+
return data.filter(function (d) {
|
|
42
|
+
return d.health_contaminant_names &&
|
|
43
|
+
d.health_contaminant_names.toLowerCase().indexOf(lower) !== -1;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
module.exports = { getByZip, getByState, getAll, getUnsafe, getByContaminant, data };
|
package/index.mjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import data from './data.json' assert { type: 'json' };
|
|
2
|
+
|
|
3
|
+
const zipIndex = Object.create(null);
|
|
4
|
+
const stateIndex = Object.create(null);
|
|
5
|
+
|
|
6
|
+
for (let i = 0; i < data.length; i++) {
|
|
7
|
+
const entry = data[i];
|
|
8
|
+
zipIndex[entry.zip] = entry;
|
|
9
|
+
if (!stateIndex[entry.state]) stateIndex[entry.state] = [];
|
|
10
|
+
stateIndex[entry.state].push(entry);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Get water quality data for a ZIP code */
|
|
14
|
+
export function getByZip(zip) {
|
|
15
|
+
return zipIndex[String(zip).padStart(5, '0')] || null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Get all entries for a state (2-letter code) */
|
|
19
|
+
export function getByState(state) {
|
|
20
|
+
return stateIndex[String(state).toUpperCase()] || [];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Get all entries */
|
|
24
|
+
export function getAll() {
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Get all entries with score below threshold */
|
|
29
|
+
export function getUnsafe(maxScore = 50) {
|
|
30
|
+
return data.filter(d => d.home_safety_score !== null && d.home_safety_score <= maxScore);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Get all entries with a specific contaminant */
|
|
34
|
+
export function getByContaminant(name) {
|
|
35
|
+
const lower = String(name).toLowerCase();
|
|
36
|
+
return data.filter(d =>
|
|
37
|
+
d.health_contaminant_names &&
|
|
38
|
+
d.health_contaminant_names.toLowerCase().includes(lower)
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { data };
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "us-water-quality-data",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "U.S. water quality data by ZIP code — violations, lead/copper levels, radon zones, and Home Safety Scores for 6,300+ ZIP codes. Based on EPA SDWIS data.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"module": "index.mjs",
|
|
7
|
+
"types": "index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"index.js",
|
|
10
|
+
"index.mjs",
|
|
11
|
+
"index.d.ts",
|
|
12
|
+
"data.json",
|
|
13
|
+
"LICENSE",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
16
|
+
"keywords": [
|
|
17
|
+
"water-quality",
|
|
18
|
+
"epa",
|
|
19
|
+
"drinking-water",
|
|
20
|
+
"lead",
|
|
21
|
+
"contaminants",
|
|
22
|
+
"radon",
|
|
23
|
+
"zip-code",
|
|
24
|
+
"usa",
|
|
25
|
+
"public-health",
|
|
26
|
+
"sdwis",
|
|
27
|
+
"environmental-data",
|
|
28
|
+
"open-data"
|
|
29
|
+
],
|
|
30
|
+
"homepage": "https://zipcheckup.com/data/",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/artakulov/us-water-quality-data"
|
|
34
|
+
},
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/artakulov/us-water-quality-data/issues"
|
|
37
|
+
},
|
|
38
|
+
"author": "ZipCheckup <contact@zipcheckup.com> (https://zipcheckup.com)",
|
|
39
|
+
"license": "CC-BY-4.0"
|
|
40
|
+
}
|