From 32d0692daa5e35935b418fb5ad3f28a1823deac8 Mon Sep 17 00:00:00 2001 From: Justin Hammond <39606064+Justintime50@users.noreply.github.com> Date: Wed, 25 Nov 2020 22:05:28 -0700 Subject: [PATCH] v2.6.0 (#4) * v2.6.0 * Additional changes to utils and added US_AZ * Fixing Travis reference * Fixing travis * Updating README --- .gitignore | 1 + .travis.yml | 4 +- CHANGELOG.md | 6 + DATA.md | 74 ----------- README.md | 83 +++++++++---- ...resses-slim.min.json => vt-addresses.json} | 0 ...resses-slim.min.json => bc-addresses.json} | 0 ...resses-slim.min.json => bj-addresses.json} | 0 ...resses-slim.min.json => hk-addresses.json} | 0 ...resses-slim.min.json => de-addresses.json} | 0 ...resses-slim.min.json => es-addresses.json} | 0 ...resses-slim.min.json => uk-addresses.json} | 0 data/united-states/az-addresses.json | 1 + .../ca-addresses.json} | 0 data/united-states/id-addresses.json | 1 + .../ks-addresses.json} | 0 .../nv-addresses.json} | 0 .../ny-addresses.json} | 0 .../or-addresses.json} | 0 .../tx-addresses.json} | 0 .../ut-addresses.json} | 0 .../wa-addresses.json} | 0 lib/data-router.js | 44 ++++--- package-lock.json | 104 +++++++++++++++- package.json | 7 +- test/create-slim-json.test.js | 30 +++++ test/files/test-data-set.json | 109 ++++++++++++++++ ...ata.test.js => united-states-data.test.js} | 116 +++++++++++++----- util/create-slim-json.js | 14 --- utils/create-slim-json.js | 47 +++++++ 30 files changed, 469 insertions(+), 172 deletions(-) delete mode 100644 DATA.md rename data/australia/{vt-addresses-slim.min.json => vt-addresses.json} (100%) rename data/canada/{bc-addresses-slim.min.json => bc-addresses.json} (100%) rename data/china/{bj-addresses-slim.min.json => bj-addresses.json} (100%) rename data/china/{hk-addresses-slim.min.json => hk-addresses.json} (100%) rename data/europe/{de-addresses-slim.min.json => de-addresses.json} (100%) rename data/europe/{es-addresses-slim.min.json => es-addresses.json} (100%) rename data/europe/{uk-addresses-slim.min.json => uk-addresses.json} (100%) create mode 100644 data/united-states/az-addresses.json rename data/{us-west/ca-addresses-slim.min.json => united-states/ca-addresses.json} (100%) create mode 100644 data/united-states/id-addresses.json rename data/{us-midwest/ks-addresses-slim.min.json => united-states/ks-addresses.json} (100%) rename data/{us-west/nv-addresses-slim.min.json => united-states/nv-addresses.json} (100%) rename data/{us-northeast/ny-addresses-slim.min.json => united-states/ny-addresses.json} (100%) rename data/{us-west/or-addresses-slim.min.json => united-states/or-addresses.json} (100%) rename data/{us-south/tx-addresses-slim.min.json => united-states/tx-addresses.json} (100%) rename data/{us-west/ut-addresses-slim.min.json => united-states/ut-addresses.json} (100%) rename data/{us-west/wa-addresses-slim.min.json => united-states/wa-addresses.json} (100%) create mode 100644 test/create-slim-json.test.js create mode 100644 test/files/test-data-set.json rename test/{us-data.test.js => united-states-data.test.js} (80%) delete mode 100644 util/create-slim-json.js create mode 100644 utils/create-slim-json.js diff --git a/.gitignore b/.gitignore index db8ba0e..e5a552e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules coverage .nyc_output +test-data-set.json-slim.json diff --git a/.travis.yml b/.travis.yml index 0466800..cadc3e4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,9 +10,9 @@ node_js: script: - npm i - npx eslint index.js - - npx eslint util/* + - npx eslint utils/*.js - npx eslint lib/data-router.js - - npx eslint test/* + - npx eslint test/*.js - npm run coverage after_success: diff --git a/CHANGELOG.md b/CHANGELOG.md index afb1271..f3491ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # CHANGELOG +## v2.6.0 (2020-11-25) + +* Shifted logic around, renamed files and lists, updated documentation, consolidated all US data into a single folder +* Added Idaho to US_ID and Arizona to US_AZ +* Completely re-wrote the `create-slim-json` utility. It now requires much less manual work, accepts more configuration options, and runs much faster while being more reliable + ## v2.5.0 (2020-10-21) * Overhauled testing framework diff --git a/DATA.md b/DATA.md deleted file mode 100644 index f074749..0000000 --- a/DATA.md +++ /dev/null @@ -1,74 +0,0 @@ -# Data - -Below are the available data options you can use when retrieving addresses. See the [README](README.md) for information on usage. - -## Australia - -All of these files will be found in the `data/australia` directory. - -| Filename | Locations | Address Count | Tag | -| -------------------------- | --------------- | ------------- | ------ | -| vt-addresses-slim.min.json | Victoria Area | 5 | AU_VT | - -## Canada - -All of these files will be found in the `data/canada` directory. - -| Filename | Locations | Address Count | Tag | -| -------------------------- | --------------- | ------------- | ------ | -| bc-addresses-slim.min.json | BC Area | 5 | CA_BC | - -## China - -All of these files will be found in the `data/china` directory. - -| Filename | Locations | Address Count | Tag | -| -------------------------- | ------------------------- | ------------- | ------ | -| bj-addresses-slim.min.json | Beijing Area | 5 | CN_BJ | -| hk-addresses-slim.min.json | Hong Kong - Wan Chai Area | 5 | CN_HK | - -## Europe - -All of these files will be found in the `data/europe` directory. - -| Filename | Locations | Address Count | Tag | -| -------------------------- | ----------------------------- | ------------- | ------ | -| de-addresses-slim.min.json | Germany - Wesel Area | 5 | EU_DE | -| es-addresses-slim.min.json | Spain - Countrywide | 5 | EU_ES | -| uk-addresses-slim.min.json | United Kingdom - England Area | 5 | EU_UK | - -## United States - Midwest - -All of these files will be found in the `data/us-midewest` directory. - -| Filename | Locations | Address Count | Tag | -| -------------------------- | ---------------------- | ------------- | ------ | -| ks-addresses-slim.min.json | Kansas - Barton County | 100 | US_KS | - -## United States - Northeast - -All of these files will be found in the `data/us-northeast` directory. - -| Filename | Locations | Address Count | Tag | -| -------------------------- | ------------------------- | ------------- | ------ | -| ny-addresses-slim.min.json | New York - Rochester Area | 100 | US_NY | - -## United States - South - -All of these files will be found in the `data/us-south` directory. - -| Filename | Locations | Address Count | Tag | -| -------------------------- | ------------------- | ------------- | ------ | -| tx-addresses-slim.min.json | Texas - Austin Area | 100 | US_TX | - -## United States - West - -All of these files will be found in the `data/us-west` directory. - -| Filename | Locations | Address Count | Tag | -| -------------------------- | ------------------------- | ------------- | ------ | -| ca-addresses-slim.min.json | California - Anaheim Area | 100 | US_CA | -| nv-addresses-slim.min.json | Nevada - Lincoln Area | 100 | US_NV | -| or-addresses-slim.min.json | Oregon - Portland Area | 100 | US_OR | -| ut-addresses-slim.min.json | Utah - Provo Area | 100 | US_UT | -| wa-addresses-slim.min.json | Washington - Spokane Area | 100 | US_WA | diff --git a/README.md b/README.md index 4029320..9416229 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Dummy Address Data (DAD) - Retrieve real addresses from all around the world. -DAD is the perfect companion to quickly bootstrap address data in your application. DAD provides real addresses from all over the world with a consistent data structure so you can spend less time looking up addresses and address rules and more time coding. +DAD is the perfect companion to quickly bootstrap address data in your application. DAD provides real addresses from all over the world with a consistent data structure so you can spend less time looking up addresses and address rules and more time coding. Rigorously tested with 2000+ tests, rest easy knowing your address data is uniform, present, and rock solid, all while being incredibly performant when retrieving records. ## Install @@ -21,25 +21,55 @@ DAD is the perfect companion to quickly bootstrap address data in your applicati npm i dad-tool ``` -## Data +## Address Data -Each dataset is built from a much larger dataset and slimmed down to bite size pieces to conserve disk space and resources when retrieving addresses. Each item on an address object will return a string. +Address objects will look like the [sample below](#sample-address-object). The data type of each field on an address object is a string. Attempts have been made to verify addresses and ensure that street1, city, state, and zip are present on all records. Some lists may be shorter than others to avoid complexity or because of a lack of accurate data. -### Sample Data Sources +The following files can be found in the `data` directory. -| Filename | Locations | Address Count | Tag | -| -------------------------- | ------------------------- | ------------- | ------ | -| ca-addresses-slim.min.json | California - Anaheim Area | 100 | US_CA | -| nv-addresses-slim.min.json | Nevada - Lincoln Area | 100 | US_NV | -| or-addresses-slim.min.json | Oregon - Portland Area | 100 | US_OR | -| ut-addresses-slim.min.json | Utah - Provo Area | 100 | US_UT | -| wa-addresses-slim.min.json | Washington - Spokane Area | 100 | US_WA | +## Australia -### All Data Sources +| Filename | Locations | Address Count | Tag | +| --------------------------- | --------------- | ------------- | ------ | +| australia/vt-addresses.json | Victoria Area | 5 | AU_VT | -The amount of data is too extensive to list here. View all the [available data sources](DATA.md) you can retrieve addresses from. +## Canada + +| Filename | Locations | Address Count | Tag | +| ------------------------ | --------------- | ------------- | ------ | +| canada/bc-addresses.json | BC Area | 5 | CA_BC | + +## China + +| Filename | Locations | Address Count | Tag | +| ----------------------- | ------------------------- | ------------- | ------ | +| china/bj-addresses.json | Beijing Area | 5 | CN_BJ | +| china/hk-addresses.json | Hong Kong - Wan Chai Area | 5 | CN_HK | + +## Europe + +| Filename | Locations | Address Count | Tag | +| ------------------------ | ----------------------------- | ------------- | ------ | +| europe/de-addresses.json | Germany - Wesel Area | 5 | EU_DE | +| europe/es-addresses.json | Spain - Countrywide | 5 | EU_ES | +| europe/uk-addresses.json | United Kingdom - England Area | 5 | EU_UK | + +## United States + +| Filename | Locations | Address Count | Tag | +| ------------------------------- | ------------------------- | ------------- | ------ | +| united-states/az-addresses.json | Arizona - Gilbert Area | 100 | US_AZ | +| united-states/ca-addresses.json | California - Anaheim Area | 100 | US_CA | +| united-states/id-addresses.json | Idaho - Boise Area | 100 | US_ID | +| united-states/ks-addresses.json | Kansas - Barton County | 100 | US_KS | +| united-states/nv-addresses.json | Nevada - Lincoln Area | 100 | US_NV | +| united-states/ny-addresses.json | New York - Rochester Area | 100 | US_NY | +| united-states/or-addresses.json | Oregon - Portland Area | 100 | US_OR | +| united-states/tx-addresses.json | Texas - Austin Area | 100 | US_TX | +| united-states/ut-addresses.json | Utah - Provo Area | 100 | US_UT | +| united-states/wa-addresses.json | Washington - Spokane Area | 100 | US_WA | ## Usage @@ -60,9 +90,9 @@ console.log(address) // console.log(address.city) ``` -### Output +### Sample Address Object -Outputs an entry like the following: +A sample address object will look like the following: ```javascript { @@ -72,29 +102,30 @@ Outputs an entry like the following: state: 'UT', zip: '84057', country: 'US' -}, +} ``` ## Development -### Utilities - -To create the slim lists from a larger dataset, use the `create-slim-json.js` tool in the `util` folder. +When adding or editing a list, ensure the file is minimized and does not exceed 100 records. ```bash -node util/create-slim-json.js -``` +# Lint a file +npx eslint index.js -### Linting +# Run tests +npm run test -```bash -npx eslint index.js +# Run test coverage +npm run coverage ``` -### Tests +### Utilities + +To create the slim lists from a larger dataset, use the `create-slim-json.js` tool in the `utils` folder. See the script for additional information. This tool will grab 100 random addresses (by default) from a larger JSON dataset and create a new slim file that can be added to DAD. ```bash -npm run test +DATA_SET=path/to/dataset.json STATE=UT COUNTRY=US node utils/create-slim-json.js ``` ## Contributing diff --git a/data/australia/vt-addresses-slim.min.json b/data/australia/vt-addresses.json similarity index 100% rename from data/australia/vt-addresses-slim.min.json rename to data/australia/vt-addresses.json diff --git a/data/canada/bc-addresses-slim.min.json b/data/canada/bc-addresses.json similarity index 100% rename from data/canada/bc-addresses-slim.min.json rename to data/canada/bc-addresses.json diff --git a/data/china/bj-addresses-slim.min.json b/data/china/bj-addresses.json similarity index 100% rename from data/china/bj-addresses-slim.min.json rename to data/china/bj-addresses.json diff --git a/data/china/hk-addresses-slim.min.json b/data/china/hk-addresses.json similarity index 100% rename from data/china/hk-addresses-slim.min.json rename to data/china/hk-addresses.json diff --git a/data/europe/de-addresses-slim.min.json b/data/europe/de-addresses.json similarity index 100% rename from data/europe/de-addresses-slim.min.json rename to data/europe/de-addresses.json diff --git a/data/europe/es-addresses-slim.min.json b/data/europe/es-addresses.json similarity index 100% rename from data/europe/es-addresses-slim.min.json rename to data/europe/es-addresses.json diff --git a/data/europe/uk-addresses-slim.min.json b/data/europe/uk-addresses.json similarity index 100% rename from data/europe/uk-addresses-slim.min.json rename to data/europe/uk-addresses.json diff --git a/data/united-states/az-addresses.json b/data/united-states/az-addresses.json new file mode 100644 index 0000000..f236186 --- /dev/null +++ b/data/united-states/az-addresses.json @@ -0,0 +1 @@ +{"addresses":[{"street1":"281 W WARNER RD","street2":"","city":"Gilbert","state":"AZ","zip":"85233","country":"US"},{"street1":"1534 E STIRRUP CT","street2":"","city":"Gilbert","state":"AZ","zip":"85296","country":"US"},{"street1":"2603 E HICKORY ST","street2":"","city":"Gilbert","state":"AZ","zip":"85298","country":"US"},{"street1":"7696 S BARLOW DR","street2":"","city":"Gilbert","state":"AZ","zip":"85298","country":"US"},{"street1":"935 N WHALERS COVE DR","street2":"","city":"Gilbert","state":"AZ","zip":"85234","country":"US"},{"street1":"6930 S SEVILLE BLVD W","street2":"","city":"Gilbert","state":"AZ","zip":"85298","country":"US"},{"street1":"1672 S MARTINGALE RD","street2":"","city":"Gilbert","state":"AZ","zip":"85295","country":"US"},{"street1":"1916 S BUCHANAN ST","street2":"","city":"Gilbert","state":"AZ","zip":"85233","country":"US"},{"street1":"845 S CANCUN DR","street2":"","city":"Gilbert","state":"AZ","zip":"85233","country":"US"},{"street1":"3319 E REDFIELD RD","street2":"","city":"Gilbert","state":"AZ","zip":"85234","country":"US"},{"street1":"736 W DESERT AVE","street2":"","city":"Gilbert","state":"AZ","zip":"85233","country":"US"},{"street1":"1736 S FALCON DR","street2":"","city":"Gilbert","state":"AZ","zip":"85295","country":"US"},{"street1":"2273 E VICTOR RD","street2":"","city":"Gilbert","state":"AZ","zip":"85296","country":"US"},{"street1":"45 E BETSY LN","street2":"","city":"Gilbert","state":"AZ","zip":"85296","country":"US"},{"street1":"21606 S GREENFIELD RD","street2":"","city":"Gilbert","state":"AZ","zip":"85298","country":"US"},{"street1":"488 N ACACIA DR","street2":"","city":"Gilbert","state":"AZ","zip":"85233","country":"US"},{"street1":"685 W GOLDEN ST","street2":"","city":"Gilbert","state":"AZ","zip":"85233","country":"US"},{"street1":"1392 S QUAIL LN","street2":"","city":"Gilbert","state":"AZ","zip":"85233","country":"US"},{"street1":"15312 E MELROSE ST","street2":"","city":"Gilbert","state":"AZ","zip":"85297","country":"US"},{"street1":" ","street2":"","city":"Gilbert","state":"AZ","zip":"","country":"US"},{"street1":"499 N SWALLOW LN","street2":"","city":"Gilbert","state":"AZ","zip":"85234","country":"US"},{"street1":"1335 E PARKSIDE DR","street2":"","city":"Gilbert","state":"AZ","zip":"85234","country":"US"},{"street1":"307 S GOLDEN KEY DR","street2":"","city":"Gilbert","state":"AZ","zip":"85233","country":"US"},{"street1":"17318 E BROOKS FARM RD","street2":"","city":"Gilbert","state":"AZ","zip":"85298","country":"US"},{"street1":"2227 E CORTEZ DR","street2":"","city":"Gilbert","state":"AZ","zip":"85234","country":"US"},{"street1":"4138 E WALNUT RD","street2":"","city":"Gilbert","state":"AZ","zip":"85298","country":"US"},{"street1":"1475 E SIERRA MADRE AVE","street2":"","city":"Gilbert","state":"AZ","zip":"85296","country":"US"},{"street1":"4334 E OAKLAND ST","street2":"","city":"Gilbert","state":"AZ","zip":"85295","country":"US"},{"street1":"2680 S VAL VISTA DR","street2":"136","city":"Gilbert","state":"AZ","zip":"85295","country":"US"},{"street1":"925 S STORMENT LN","street2":"","city":"Gilbert","state":"AZ","zip":"85296","country":"US"},{"street1":"4030 E CONSTITUTION CT","street2":"","city":"Gilbert","state":"AZ","zip":"85296","country":"US"},{"street1":"1234 E SEA BREEZE DR","street2":"","city":"Gilbert","state":"AZ","zip":"85234","country":"US"},{"street1":"1725 E DOGWOOD LN","street2":"","city":"Gilbert","state":"AZ","zip":"85295","country":"US"},{"street1":" ","street2":"","city":"Gilbert","state":"AZ","zip":"","country":"US"},{"street1":"5879 S TUCANA LN","street2":"","city":"Gilbert","state":"AZ","zip":"85298","country":"US"},{"street1":"302 N COBBLESTONE ST","street2":"","city":"Gilbert","state":"AZ","zip":"85234","country":"US"},{"street1":" ","street2":"","city":"Gilbert","state":"AZ","zip":"","country":"US"},{"street1":"4184 E MEADOWVIEW DR","street2":"","city":"Gilbert","state":"AZ","zip":"85298","country":"US"},{"street1":"3440 S JACANA LN","street2":"","city":"Gilbert","state":"AZ","zip":"85297","country":"US"},{"street1":"2715 E CALLE DEL NORTE DR","street2":"","city":"Gilbert","state":"AZ","zip":"85296","country":"US"},{"street1":"4565 E LAUREL AVE","street2":"","city":"Gilbert","state":"AZ","zip":"85234","country":"US"},{"street1":"3698 S SETON AVE","street2":"","city":"Gilbert","state":"AZ","zip":"85297","country":"US"},{"street1":"669 S OAK ST","street2":"","city":"Gilbert","state":"AZ","zip":"85233","country":"US"},{"street1":"3338 E BONANZA RD","street2":"","city":"Gilbert","state":"AZ","zip":"85297","country":"US"},{"street1":"4050 S RANCH HOUSE PKWY","street2":"178","city":"Gilbert","state":"AZ","zip":"85297","country":"US"},{"street1":"3269 E ANIKA DR","street2":"","city":"Gilbert","state":"AZ","zip":"85298","country":"US"},{"street1":"269 E SAGEBRUSH ST","street2":"","city":"Gilbert","state":"AZ","zip":"85296","country":"US"},{"street1":"3149 E COLDWATER BLVD","street2":"","city":"Gilbert","state":"AZ","zip":"85142","country":"US"},{"street1":"1336 E WASHINGTON AVE","street2":"","city":"Gilbert","state":"AZ","zip":"85234","country":"US"},{"street1":"688 N ABALONE DR","street2":"","city":"Gilbert","state":"AZ","zip":"85233","country":"US"},{"street1":"889 E FRANCES LN","street2":"","city":"Gilbert","state":"AZ","zip":"85295","country":"US"},{"street1":"841 W CALYPSO DR","street2":"","city":"Gilbert","state":"AZ","zip":"85233","country":"US"},{"street1":"3934 E TURLEY ST","street2":"","city":"Gilbert","state":"AZ","zip":"85295","country":"US"},{"street1":"792 S MARTINIQUE DR","street2":"","city":"Gilbert","state":"AZ","zip":"85233","country":"US"},{"street1":"1689 W LEAH LN","street2":"","city":"Gilbert","state":"AZ","zip":"85233","country":"US"},{"street1":"1026 S GILBERT RD","street2":"","city":"Gilbert","state":"AZ","zip":"85296","country":"US"},{"street1":" ","street2":"","city":"Gilbert","state":"AZ","zip":"","country":"US"},{"street1":"428 S PORT DR","street2":"","city":"Gilbert","state":"AZ","zip":"85233","country":"US"},{"street1":"459 S GRANITE ST","street2":"","city":"Gilbert","state":"AZ","zip":"85296","country":"US"},{"street1":"413 E LINDA LN","street2":"D","city":"Gilbert","state":"AZ","zip":"85234","country":"US"},{"street1":"302 N COBBLESTONE ST","street2":"","city":"Gilbert","state":"AZ","zip":"85234","country":"US"},{"street1":"4537 E TOWNE LN","street2":"","city":"Gilbert","state":"AZ","zip":"85234","country":"US"},{"street1":"239 N TIAGO DR","street2":"","city":"Gilbert","state":"AZ","zip":"85233","country":"US"},{"street1":"1142 E BAJOR ST","street2":"","city":"Gilbert","state":"AZ","zip":"85298","country":"US"},{"street1":"4046 E PAGE AVE","street2":"","city":"Gilbert","state":"AZ","zip":"85234","country":"US"},{"street1":"3637 E PINON CT","street2":"","city":"Gilbert","state":"AZ","zip":"85234","country":"US"},{"street1":"1172 N SAN BENITO DR","street2":"","city":"Gilbert","state":"AZ","zip":"85234","country":"US"},{"street1":"3420 E INDIGO ST","street2":"","city":"Gilbert","state":"AZ","zip":"85298","country":"US"},{"street1":"1850 E LAKECREST DR","street2":"","city":"Gilbert","state":"AZ","zip":"85234","country":"US"},{"street1":"3311 E LOMA VISTA ST","street2":"","city":"Gilbert","state":"AZ","zip":"85295","country":"US"},{"street1":"1242 E AZURE SEA LN","street2":"","city":"Gilbert","state":"AZ","zip":"85234","country":"US"},{"street1":"4550 E APRICOT LN","street2":"","city":"Gilbert","state":"AZ","zip":"85298","country":"US"},{"street1":"4075 E JASPER DR","street2":"","city":"Gilbert","state":"AZ","zip":"85296","country":"US"},{"street1":"1102 S ANNIE LN","street2":"","city":"Gilbert","state":"AZ","zip":"85296","country":"US"},{"street1":"1026 N BLACKBIRD DR","street2":"","city":"Gilbert","state":"AZ","zip":"85234","country":"US"},{"street1":"1143 W REDONDO DR","street2":"","city":"Gilbert","state":"AZ","zip":"85233","country":"US"},{"street1":"6089 S 174TH PL","street2":"","city":"Gilbert","state":"AZ","zip":"85298","country":"US"},{"street1":"2920 E TEMPLE CT","street2":"","city":"Gilbert","state":"AZ","zip":"85296","country":"US"},{"street1":"2728 S SULLEY DR","street2":"103","city":"Gilbert","state":"AZ","zip":"85295","country":"US"},{"street1":" ","street2":"","city":"Gilbert","state":"AZ","zip":"","country":"US"},{"street1":"331 N REDROCK ST","street2":"","city":"Gilbert","state":"AZ","zip":"85234","country":"US"},{"street1":"712 E SHEFFIELD AVE","street2":"","city":"Gilbert","state":"AZ","zip":"85296","country":"US"},{"street1":"2527 E VIA DEL ARBOLES","street2":"","city":"Gilbert","state":"AZ","zip":"85298","country":"US"},{"street1":"3528 E SANTA FE LN","street2":"","city":"Gilbert","state":"AZ","zip":"85297","country":"US"},{"street1":"2316 E CORTEZ DR","street2":"","city":"Gilbert","state":"AZ","zip":"85234","country":"US"},{"street1":"2679 E SADDLEBROOK RD","street2":"","city":"Gilbert","state":"AZ","zip":"85298","country":"US"},{"street1":"3886 E MORELOS ST","street2":"","city":"Gilbert","state":"AZ","zip":"85295","country":"US"},{"street1":"1208 N CAYMAN DR","street2":"","city":"Gilbert","state":"AZ","zip":"85234","country":"US"},{"street1":"2632 S HARMONY AVE","street2":"","city":"Gilbert","state":"AZ","zip":"85295","country":"US"},{"street1":"2062 E APPALOOSA RD","street2":"","city":"Gilbert","state":"AZ","zip":"85296","country":"US"},{"street1":"3141 E HAMPTON LN","street2":"","city":"Gilbert","state":"AZ","zip":"85295","country":"US"},{"street1":"2012 E GONDOLA LN","street2":"","city":"Gilbert","state":"AZ","zip":"85234","country":"US"},{"street1":"124 E VAUGHN AVE","street2":"","city":"Gilbert","state":"AZ","zip":"85234","country":"US"},{"street1":"725 W ORCHARD WY","street2":"","city":"Gilbert","state":"AZ","zip":"85233","country":"US"},{"street1":"853 E FURNESS DR","street2":"","city":"Gilbert","state":"AZ","zip":"85297","country":"US"},{"street1":"1663 E BASELINE RD","street2":"","city":"Gilbert","state":"AZ","zip":"85233","country":"US"},{"street1":"3484 S JACANA LN","street2":"","city":"Gilbert","state":"AZ","zip":"85297","country":"US"},{"street1":"4216 E BONANZA RD","street2":"","city":"Gilbert","state":"AZ","zip":"85297","country":"US"},{"street1":"1633 E LAKESIDE DR","street2":"144","city":"Gilbert","state":"AZ","zip":"85234","country":"US"},{"street1":"460 W SAN REMO ST","street2":"","city":"Gilbert","state":"AZ","zip":"85233","country":"US"}]} diff --git a/data/us-west/ca-addresses-slim.min.json b/data/united-states/ca-addresses.json similarity index 100% rename from data/us-west/ca-addresses-slim.min.json rename to data/united-states/ca-addresses.json diff --git a/data/united-states/id-addresses.json b/data/united-states/id-addresses.json new file mode 100644 index 0000000..f8e80ef --- /dev/null +++ b/data/united-states/id-addresses.json @@ -0,0 +1 @@ +{"addresses":[{"street1":"W WHITTAKER ST","street2":"","city":"BOISE","state":"ID","zip":"83714","country":"US"},{"street1":"N LIBERTY ST","street2":"","city":"BOISE","state":"ID","zip":"83704","country":"US"},{"street1":"E YUCCA CANYON ST","street2":"","city":"MERIDIAN","state":"ID","zip":"83646","country":"US"},{"street1":"W ROCKFORD ST","street2":"","city":"MERIDIAN","state":"ID","zip":"83642","country":"US"},{"street1":"W WOLF RAPIDS ST","street2":"","city":"MERIDIAN","state":"ID","zip":"83646","country":"US"},{"street1":"W PETRIE ST","street2":"","city":"BOISE","state":"ID","zip":"83704","country":"US"},{"street1":"W JACKSNIPE DR","street2":"","city":"MERIDIAN","state":"ID","zip":"83642","country":"US"},{"street1":"W HOLBROOK AVE","street2":"","city":"BOISE","state":"ID","zip":"83704","country":"US"},{"street1":"E 47TH ST","street2":"","city":"GARDEN CITY","state":"ID","zip":"83714","country":"US"},{"street1":"S RUSHMORE WAY","street2":"","city":"BOISE","state":"ID","zip":"83709","country":"US"},{"street1":"E BLUE HERON ST","street2":"","city":"MERIDIAN","state":"ID","zip":"83646","country":"US"},{"street1":"S FIDDLE AVE","street2":"","city":"MERIDIAN","state":"ID","zip":"83642","country":"US"},{"street1":"W BIENAPFL DR","street2":"","city":"BOISE","state":"ID","zip":"83709","country":"US"},{"street1":"S NASTURTIUM PL","street2":"","city":"BOISE","state":"ID","zip":"83716","country":"US"},{"street1":"S STRAUGHAN AVE","street2":"","city":"BOISE","state":"ID","zip":"83712","country":"US"},{"street1":"S DANSKIN LN","street2":"","city":"MERIDIAN","state":"ID","zip":"83642","country":"US"},{"street1":"W CORY LN","street2":"","city":"BOISE","state":"ID","zip":"83704","country":"US"},{"street1":"N COOL SPRINGS AVE","street2":"","city":"KUNA","state":"ID","zip":"83634","country":"US"},{"street1":"N WHITE SPRUCE PL","street2":"","city":"BOISE","state":"ID","zip":"83713","country":"US"},{"street1":"W KOOTENAI ST","street2":"","city":"BOISE","state":"ID","zip":"83705","country":"US"},{"street1":"W DEVOTION DR","street2":"","city":"MERIDIAN","state":"ID","zip":"83642","country":"US"},{"street1":"W WATER GROVE DR","street2":"","city":"EAGLE","state":"ID","zip":"83616","country":"US"},{"street1":"S BURGDORF WAY","street2":"","city":"MERIDIAN","state":"ID","zip":"83642","country":"US"},{"street1":"N BEVERLY DR","street2":"","city":"EAGLE","state":"ID","zip":"83616","country":"US"},{"street1":"S TRAPPER COVE AVE","street2":"","city":"BOISE","state":"ID","zip":"83709","country":"US"},{"street1":"NW 11TH AVE","street2":"","city":"MERIDIAN","state":"ID","zip":"83646","country":"US"},{"street1":"E CADILLAC DR","street2":"","city":"MERIDIAN","state":"ID","zip":"83642","country":"US"},{"street1":"S ELM ST","street2":"","city":"BOISE","state":"ID","zip":"83712","country":"US"},{"street1":"N SHADOWRIDGE AVE","street2":"","city":"EAGLE","state":"ID","zip":"83616","country":"US"},{"street1":"E HOLLY ST","street2":"","city":"BOISE","state":"ID","zip":"83712","country":"US"},{"street1":"S CAPITOL BLVD","street2":"","city":"BOISE","state":"ID","zip":"83706","country":"US"},{"street1":"S MICHIGAN AVE","street2":"","city":"BOISE","state":"ID","zip":"83706","country":"US"},{"street1":"N TULLSHIRE WAY","street2":"","city":"EAGLE","state":"ID","zip":"83616","country":"US"},{"street1":"N ANFIELD AVE","street2":"","city":"MERIDIAN","state":"ID","zip":"83646","country":"US"},{"street1":"N GRANDEE ST","street2":"","city":"BOISE","state":"ID","zip":"83704","country":"US"},{"street1":"N HIGHFIELD WAY","street2":"","city":"BOISE","state":"ID","zip":"83714","country":"US"},{"street1":"N DEVON WAY","street2":"","city":"STAR","state":"ID","zip":"83669","country":"US"},{"street1":"W LEILANI DR","street2":"","city":"BOISE","state":"ID","zip":"83709","country":"US"},{"street1":"N ELSINORE AVE","street2":"","city":"MERIDIAN","state":"ID","zip":"83646","country":"US"},{"street1":"N MAPLE GROVE RD","street2":"","city":"BOISE","state":"ID","zip":"83704","country":"US"},{"street1":"W BARON LN","street2":"","city":"BOISE","state":"ID","zip":"83703","country":"US"},{"street1":"N PREDO WAY","street2":"","city":"MERIDIAN","state":"ID","zip":"83646","country":"US"},{"street1":"N ADDAX AVE","street2":"","city":"KUNA","state":"ID","zip":"83634","country":"US"},{"street1":"W LOS FLORES ST","street2":"","city":"MERIDIAN","state":"ID","zip":"83646","country":"US"},{"street1":"W CHRISTOPHER DR","street2":"","city":"MERIDIAN","state":"ID","zip":"83642","country":"US"},{"street1":"E MEADOW WOOD ST","street2":"","city":"MERIDIAN","state":"ID","zip":"83646","country":"US"},{"street1":"W CARTRIDGE ST","street2":"","city":"BOISE","state":"ID","zip":"83713","country":"US"},{"street1":"N 10TH ST","street2":"","city":"BOISE","state":"ID","zip":"83702","country":"US"},{"street1":"E VICTORY RD","street2":"BLDG M","city":"MERIDIAN","state":"ID","zip":"83642","country":"US"},{"street1":"S GATEWOOD LN","street2":"","city":"BOISE","state":"ID","zip":"83709","country":"US"},{"street1":"N GAVIOLA AVE","street2":"","city":"MERIDIAN","state":"ID","zip":"83646","country":"US"},{"street1":"N COLE RD","street2":"","city":"BOISE","state":"ID","zip":"83704","country":"US"},{"street1":"N SIMERLY AVE","street2":"","city":"MERIDIAN","state":"ID","zip":"83646","country":"US"},{"street1":"W ASHBY DR","street2":"BLDG B","city":"MERIDIAN","state":"ID","zip":"83646","country":"US"},{"street1":"E BLUE HERON LN","street2":"","city":"MERIDIAN","state":"ID","zip":"83646","country":"US"},{"street1":"S UPDALE AVE","street2":"","city":"KUNA","state":"ID","zip":"83634","country":"US"},{"street1":"W TANGO CREEK DR","street2":"","city":"MERIDIAN","state":"ID","zip":"83646","country":"US"},{"street1":"W SUSAN ST","street2":"","city":"BOISE","state":"ID","zip":"83704","country":"US"},{"street1":"N BURLEY WAY","street2":"","city":"MERIDIAN","state":"ID","zip":"83646","country":"US"},{"street1":"N MOUNTAIN LION AVE","street2":"","city":"STAR","state":"ID","zip":"83669","country":"US"},{"street1":"S DENVER AVE","street2":"","city":"BOISE","state":"ID","zip":"83706","country":"US"},{"street1":"S CONSTELLATION WAY","street2":"","city":"BOISE","state":"ID","zip":"83709","country":"US"},{"street1":"S MISSOULA WAY","street2":"","city":"BOISE","state":"ID","zip":"83709","country":"US"},{"street1":"W PERUGIA ST","street2":"BLDG S","city":"MERIDIAN","state":"ID","zip":"83642","country":"US"},{"street1":"W SAGEBRUSH ST","street2":"","city":"BOISE","state":"ID","zip":"83709","country":"US"},{"street1":"N ASPEN LAKES WAY","street2":"","city":"STAR","state":"ID","zip":"83669","country":"US"},{"street1":"W CHAMPAGNE CT","street2":"","city":"EAGLE","state":"ID","zip":"83616","country":"US"},{"street1":"S EUCLID LN","street2":"","city":"BOISE","state":"ID","zip":"83706","country":"US"},{"street1":"N SILVER SPRUCE AVE","street2":"","city":"MERIDIAN","state":"ID","zip":"83646","country":"US"},{"street1":"W GINGER CREEK DR","street2":"","city":"BOISE","state":"ID","zip":"83713","country":"US"},{"street1":"E PENNSYLVANIA ST","street2":"","city":"BOISE","state":"ID","zip":"83706","country":"US"},{"street1":"N LENA AVE","street2":"","city":"BOISE","state":"ID","zip":"83713","country":"US"},{"street1":"S LONGMOOR AVE","street2":"","city":"BOISE","state":"ID","zip":"83709","country":"US"},{"street1":"W GOLDENROD AVE","street2":"","city":"BOISE","state":"ID","zip":"83713","country":"US"},{"street1":"S CARBONDALE PL","street2":"","city":"MERIDIAN","state":"ID","zip":"83642","country":"US"},{"street1":"S ALLANTE PL","street2":"","city":"BOISE","state":"ID","zip":"83709","country":"US"},{"street1":"W BUTTE ST","street2":"","city":"BOISE","state":"ID","zip":"83704","country":"US"},{"street1":"E FLORENCE DR","street2":"","city":"MERIDIAN","state":"ID","zip":"83642","country":"US"},{"street1":"N MAIN ST","street2":"","city":"MERIDIAN","state":"ID","zip":"83642","country":"US"},{"street1":"W MORNIN MIST ST","street2":"","city":"BOISE","state":"ID","zip":"83709","country":"US"},{"street1":"E MENDOTA DR","street2":"","city":"BOISE","state":"ID","zip":"83716","country":"US"},{"street1":"W GREENBRIER DR","street2":"","city":"BOISE","state":"ID","zip":"83705","country":"US"},{"street1":"N LILYTURF AVE","street2":"","city":"MERIDIAN","state":"ID","zip":"83646","country":"US"},{"street1":"S COLERIDGE PL","street2":"","city":"BOISE","state":"ID","zip":"83706","country":"US"},{"street1":"E JEFFERSON ST","street2":"","city":"BOISE","state":"ID","zip":"83712","country":"US"},{"street1":"N SCHICKS RIDGE RD","street2":"","city":"BOISE","state":"ID","zip":"83714","country":"US"},{"street1":"W DENTON LN","street2":"","city":"BOISE","state":"ID","zip":"83704","country":"US"},{"street1":"N MORPHEUS AVE","street2":"","city":"MERIDIAN","state":"ID","zip":"83646","country":"US"},{"street1":"S MOONFLOWER PL","street2":"","city":"BOISE","state":"ID","zip":"83716","country":"US"},{"street1":"E BLACK HAWK CT","street2":"","city":"KUNA","state":"ID","zip":"83634","country":"US"},{"street1":"W TRAFALGER CT","street2":"","city":"BOISE","state":"ID","zip":"83709","country":"US"},{"street1":"E FLORENCE DR","street2":"","city":"MERIDIAN","state":"ID","zip":"83642","country":"US"},{"street1":"W CASSIA ST","street2":"","city":"BOISE","state":"ID","zip":"83705","country":"US"},{"street1":"N SNOW GOOSE WAY","street2":"","city":"MERIDIAN","state":"ID","zip":"83646","country":"US"},{"street1":"S FRANKLIN PARK DR","street2":"","city":"BOISE","state":"ID","zip":"83709","country":"US"},{"street1":"W TARGEE ST","street2":"","city":"BOISE","state":"ID","zip":"83705","country":"US"},{"street1":"W HOWE ST","street2":"","city":"BOISE","state":"ID","zip":"83706","country":"US"},{"street1":"W FAIRVIEW AVE","street2":"","city":"BOISE","state":"ID","zip":"83704","country":"US"},{"street1":"N CLOVERDALE RD","street2":"","city":"BOISE","state":"ID","zip":"83713","country":"US"},{"street1":"N 10TH AVE","street2":"","city":"BOISE","state":"ID","zip":"83714","country":"US"}]} diff --git a/data/us-midwest/ks-addresses-slim.min.json b/data/united-states/ks-addresses.json similarity index 100% rename from data/us-midwest/ks-addresses-slim.min.json rename to data/united-states/ks-addresses.json diff --git a/data/us-west/nv-addresses-slim.min.json b/data/united-states/nv-addresses.json similarity index 100% rename from data/us-west/nv-addresses-slim.min.json rename to data/united-states/nv-addresses.json diff --git a/data/us-northeast/ny-addresses-slim.min.json b/data/united-states/ny-addresses.json similarity index 100% rename from data/us-northeast/ny-addresses-slim.min.json rename to data/united-states/ny-addresses.json diff --git a/data/us-west/or-addresses-slim.min.json b/data/united-states/or-addresses.json similarity index 100% rename from data/us-west/or-addresses-slim.min.json rename to data/united-states/or-addresses.json diff --git a/data/us-south/tx-addresses-slim.min.json b/data/united-states/tx-addresses.json similarity index 100% rename from data/us-south/tx-addresses-slim.min.json rename to data/united-states/tx-addresses.json diff --git a/data/us-west/ut-addresses-slim.min.json b/data/united-states/ut-addresses.json similarity index 100% rename from data/us-west/ut-addresses-slim.min.json rename to data/united-states/ut-addresses.json diff --git a/data/us-west/wa-addresses-slim.min.json b/data/united-states/wa-addresses.json similarity index 100% rename from data/us-west/wa-addresses-slim.min.json rename to data/united-states/wa-addresses.json diff --git a/lib/data-router.js b/lib/data-router.js index 8e4a685..ac39580 100644 --- a/lib/data-router.js +++ b/lib/data-router.js @@ -1,37 +1,38 @@ function variables(data) { // DAD data const location = 'data/' - const nameScheme = '-addresses-slim.min.json' + const nameScheme = '-addresses.json' var addresses = '' // Country data const australia = 'australia/' const canada = 'canada/' const china = 'china/' const europe = 'europe/' - const usWest = 'us-west/' - const usMidWest = 'us-midwest/' - const usNorthEast = 'us-northeast/' - const usSouth = 'us-south/' + const unitedStates = 'united-states/' - // Check if there is no data + // Check if there is no data present if (!data) { throw new Error('Data source tag was not valid. An address could not be retrieved.') } // Setup the data router based on the tag passed in switch (data) { + // AUSTRALIA DATA case 'AU_VT': addresses = `${location}${australia}vt${nameScheme}` break; + // CANADA DATA case 'CA_BC': addresses = `${location}${canada}bc${nameScheme}` break; + // CHINA DATA case 'CN_BJ': addresses = `${location}${china}bj${nameScheme}` break; case 'CN_HK': addresses = `${location}${china}hk${nameScheme}` break; + // EUROPE DATA case 'EU_DE': addresses = `${location}${europe}de${nameScheme}` break; @@ -41,29 +42,36 @@ function variables(data) { case 'EU_UK': addresses = `${location}${europe}uk${nameScheme}` break; - case 'US_KS': - addresses = `${location}${usMidWest}ks${nameScheme}` + // UNITED STATES DATA + case 'US_AZ': + addresses = `${location}${unitedStates}az${nameScheme}` break; - case 'US_NY': - addresses = `${location}${usNorthEast}ny${nameScheme}` + case 'US_CA': + addresses = `${location}${unitedStates}ca${nameScheme}` break; - case 'US_TX': - addresses = `${location}${usSouth}tx${nameScheme}` + case 'US_ID': + addresses = `${location}${unitedStates}id${nameScheme}` break; - case 'US_CA': - addresses = `${location}${usWest}ca${nameScheme}` + case 'US_KS': + addresses = `${location}${unitedStates}ks${nameScheme}` break; case 'US_NV': - addresses = `${location}${usWest}nv${nameScheme}` + addresses = `${location}${unitedStates}nv${nameScheme}` + break; + case 'US_NY': + addresses = `${location}${unitedStates}ny${nameScheme}` break; case 'US_OR': - addresses = `${location}${usWest}or${nameScheme}` + addresses = `${location}${unitedStates}or${nameScheme}` + break; + case 'US_TX': + addresses = `${location}${unitedStates}tx${nameScheme}` break; case 'US_UT': - addresses = `${location}${usWest}ut${nameScheme}` + addresses = `${location}${unitedStates}ut${nameScheme}` break; case 'US_WA': - addresses = `${location}${usWest}wa${nameScheme}` + addresses = `${location}${unitedStates}wa${nameScheme}` break; default: throw new Error('Data source tag was not valid. An address could not be retrieved.') diff --git a/package-lock.json b/package-lock.json index 9c0271b..aba3999 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "dad-tool", - "version": "2.5.0", + "version": "2.6.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -298,6 +298,51 @@ "integrity": "sha512-tsAQNx32a8CoFhjhijUIhI4kccIAgmGhy8LZMZgGfmXcpMbPRUqn5LWmgRttILi6yeGmBJd2xsPkFMs0PzgPCw==", "dev": true }, + "@sinonjs/commons": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.1.tgz", + "integrity": "sha512-892K+kWUUi3cl+LlqEWIDrhvLgdL79tECi8JZUyq6IviKy/DNhuzCRlbHUjxK89f4ypPMMaFnFuR9Ie6DoIMsw==", + "dev": true, + "requires": { + "type-detect": "4.0.8" + } + }, + "@sinonjs/fake-timers": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-6.0.1.tgz", + "integrity": "sha512-MZPUxrmFubI36XS1DI3qmI0YdN1gks62JtFZvxR67ljjSNCeK6U08Zx4msEWOXuofgqUt6zPHSi1H9fbjR/NRA==", + "dev": true, + "requires": { + "@sinonjs/commons": "^1.7.0" + } + }, + "@sinonjs/formatio": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@sinonjs/formatio/-/formatio-5.0.1.tgz", + "integrity": "sha512-KaiQ5pBf1MpS09MuA0kp6KBQt2JUOQycqVG1NZXvzeaXe5LGFqAKueIS0bw4w0P9r7KuBSVdUk5QjXsUdu2CxQ==", + "dev": true, + "requires": { + "@sinonjs/commons": "^1", + "@sinonjs/samsam": "^5.0.2" + } + }, + "@sinonjs/samsam": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-5.3.0.tgz", + "integrity": "sha512-hXpcfx3aq+ETVBwPlRFICld5EnrkexXuXDwqUNhDdr5L8VjvMeSRwyOa0qL7XFmR+jVWR4rUZtnxlG7RX72sBg==", + "dev": true, + "requires": { + "@sinonjs/commons": "^1.6.0", + "lodash.get": "^4.4.2", + "type-detect": "^4.0.8" + } + }, + "@sinonjs/text-encoding": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.1.tgz", + "integrity": "sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ==", + "dev": true + }, "@types/color-name": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz", @@ -1951,6 +1996,12 @@ "verror": "1.10.0" } }, + "just-extend": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.1.1.tgz", + "integrity": "sha512-aWgeGFW67BP3e5181Ep1Fv2v8z//iBJfrvyTnq8wG86vEESwmonn1zPBJ0VfmT9CJq2FIT0VsETtrNFm2a+SHA==", + "dev": true + }, "lcov-parse": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/lcov-parse/-/lcov-parse-1.0.0.tgz", @@ -1988,6 +2039,12 @@ "integrity": "sha1-+wMJF/hqMTTlvJvsDWngAT3f7bI=", "dev": true }, + "lodash.get": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", + "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=", + "dev": true + }, "log-driver": { "version": "1.2.7", "resolved": "https://registry.npmjs.org/log-driver/-/log-driver-1.2.7.tgz", @@ -2114,6 +2171,19 @@ "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", "dev": true }, + "nise": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/nise/-/nise-4.0.4.tgz", + "integrity": "sha512-bTTRUNlemx6deJa+ZyoCUTRvH3liK5+N6VQZ4NIw90AgDXY6iPnsqplNFf6STcj+ePk0H/xqxnP75Lr0J0Fq3A==", + "dev": true, + "requires": { + "@sinonjs/commons": "^1.7.0", + "@sinonjs/fake-timers": "^6.0.0", + "@sinonjs/text-encoding": "^0.7.1", + "just-extend": "^4.0.2", + "path-to-regexp": "^1.7.0" + } + }, "node-preload": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/node-preload/-/node-preload-0.2.1.tgz", @@ -2441,6 +2511,23 @@ "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", "dev": true }, + "path-to-regexp": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz", + "integrity": "sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==", + "dev": true, + "requires": { + "isarray": "0.0.1" + }, + "dependencies": { + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", + "dev": true + } + } + }, "pathval": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz", @@ -2687,6 +2774,21 @@ "integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==", "dev": true }, + "sinon": { + "version": "9.2.1", + "resolved": "https://registry.npmjs.org/sinon/-/sinon-9.2.1.tgz", + "integrity": "sha512-naPfsamB5KEE1aiioaoqJ6MEhdUs/2vtI5w1hPAXX/UwvoPjXcwh1m5HiKx0HGgKR8lQSoFIgY5jM6KK8VrS9w==", + "dev": true, + "requires": { + "@sinonjs/commons": "^1.8.1", + "@sinonjs/fake-timers": "^6.0.1", + "@sinonjs/formatio": "^5.0.1", + "@sinonjs/samsam": "^5.2.0", + "diff": "^4.0.2", + "nise": "^4.0.4", + "supports-color": "^7.1.0" + } + }, "slice-ansi": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-2.1.0.tgz", diff --git a/package.json b/package.json index ff101f5..a946394 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "dad-tool", - "version": "2.5.0", - "description": "Dummy Address Data (DAD) allows you to query a massive dataset for real addresses that are perfect for dummy data.", + "version": "2.6.0", + "description": "Dummy Address Data (DAD) - Retrieve real addresses from all around the world.", "main": "index.js", "scripts": { "test": "_mocha", @@ -28,7 +28,8 @@ "coveralls": "^3.1.0", "eslint": "^6.8.0", "mocha": "^8.1.1", - "nyc": "^15.1.0" + "nyc": "^15.1.0", + "sinon": "^9.2.1" }, "dependencies": {} } diff --git a/test/create-slim-json.test.js b/test/create-slim-json.test.js new file mode 100644 index 0000000..8c6b20c --- /dev/null +++ b/test/create-slim-json.test.js @@ -0,0 +1,30 @@ +/* eslint-env node, mocha */ +const assert = require('chai').assert + +const sinon = require('sinon') +const fs = require('fs') +const slimJsonUtil = require('../utils/create-slim-json') + +describe('Create Slim JSON Util', function () { + it('creates a slim JSON file from a larger dataset', async function () { + const testFileName = __dirname + '/files/test-data-set-slim' + if (fs.existsSync(testFileName)) { + fs.unlinkSync(testFileName) + } + process.env.DATA_SET = '' + process.env.NUM_ADDRESSES = 5 + sinon.stub(process.env, 'DATA_SET').value(__dirname + '/files/test-data-set.json'); + const createSlimJson = await slimJsonUtil.createSlimJson() + assert.equal(createSlimJson, true); + }); + + it('returns an error when DATA_SET is undefined', async function () { + // Hacky but works, could instead use https://github.com/domenic/chai-as-promised + try { + process.env.DATA_SET = undefined + await slimJsonUtil.createSlimJson() + } catch (error) { + assert.include(error.message, 'Cannot find module \'undefined\''); + } + }); +}) diff --git a/test/files/test-data-set.json b/test/files/test-data-set.json new file mode 100644 index 0000000..33f6620 --- /dev/null +++ b/test/files/test-data-set.json @@ -0,0 +1,109 @@ +{ + "addresses": [ + { + "type": "Feature", + "properties": { + "id": "", + "unit": "", + "number": "6242", + "street": "N SWEET VALLEY PL", + "city": "MERIDIAN", + "district": "", + "region": "", + "postcode": "83646", + "hash": "f6fb34d0cf8a8d3d" + }, + "geometry": { + "type": "Point", + "coordinates": [ + -116.3698397, + 43.6615879 + ] + } + }, + { + "type": "Feature", + "properties": { + "id": "", + "unit": "", + "number": "6268", + "street": "N SWEET VALLEY PL", + "city": "MERIDIAN", + "district": "", + "region": "", + "postcode": "83646", + "hash": "66419a5fd05468bd" + }, + "geometry": { + "type": "Point", + "coordinates": [ + -116.3698534, + 43.6617774 + ] + } + }, + { + "type": "Feature", + "properties": { + "id": "", + "unit": "", + "number": "6294", + "street": "N SWEET VALLEY PL", + "city": "MERIDIAN", + "district": "", + "region": "", + "postcode": "83646", + "hash": "9ec51cc46fe8638c" + }, + "geometry": { + "type": "Point", + "coordinates": [ + -116.3698515, + 43.6619784 + ] + } + }, + { + "type": "Feature", + "properties": { + "id": "", + "unit": "", + "number": "6326", + "street": "N SWEET VALLEY PL", + "city": "MERIDIAN", + "district": "", + "region": "", + "postcode": "83646", + "hash": "e657d41aa701353a" + }, + "geometry": { + "type": "Point", + "coordinates": [ + -116.3696962, + 43.6623059 + ] + } + }, + { + "type": "Feature", + "properties": { + "id": "", + "unit": "", + "number": "6352", + "street": "N SWEET VALLEY PL", + "city": "MERIDIAN", + "district": "", + "region": "", + "postcode": "83646", + "hash": "d3c6128dcc2e9e28" + }, + "geometry": { + "type": "Point", + "coordinates": [ + -116.3699588, + 43.6624559 + ] + } + } + ] +} diff --git a/test/us-data.test.js b/test/united-states-data.test.js similarity index 80% rename from test/us-data.test.js rename to test/united-states-data.test.js index 017fcac..4c6e9ab 100644 --- a/test/us-data.test.js +++ b/test/united-states-data.test.js @@ -3,21 +3,21 @@ const assert = require('chai').assert const expect = require('chai').expect const dad = require('../index') -describe('US KS Address Data', function () { - const address = dad.random('US_KS') - const addresses = dad.list('US_KS') +describe('US AZ Address Data', function () { + const address = dad.random('US_AZ') + const addresses = dad.list('US_AZ') - it('returns a random KS address', function () { - assert.equal(address.state, 'KS'); + it('returns a random AZ address', function () { + assert.equal(address.state, 'AZ'); }); - it('returns a list of KS addresses with a length of 100', function () { + it('returns a list of AZ addresses with a length of 100', function () { assert.equal(addresses.addresses.length, 100); }) addresses.addresses.forEach(function (singleAddress) { - it(`returns "${singleAddress.street1}" from a list of KS addresses`, function () { - assert.equal(singleAddress.state, 'KS') + it(`returns "${singleAddress.street1}" from a list of AZ addresses`, function () { + assert.equal(singleAddress.state, 'AZ') }); }) @@ -28,21 +28,21 @@ describe('US KS Address Data', function () { }); }) -describe('US NY Address Data', function () { - const address = dad.random('US_NY') - const addresses = dad.list('US_NY') +describe('US CA Address Data', function () { + const address = dad.random('US_CA') + const addresses = dad.list('US_CA') - it('returns a random NY address', function () { - assert.equal(address.state, 'NY'); + it('returns a random CA address', function () { + assert.equal(address.state, 'CA'); }); - it('returns a list of NY addresses with a length of 100', function () { + it('returns a list of CA addresses with a length of 100', function () { assert.equal(addresses.addresses.length, 100); }) addresses.addresses.forEach(function (singleAddress) { - it(`returns "${singleAddress.street1}" from a list of NY addresses`, function () { - assert.equal(singleAddress.state, 'NY') + it(`returns "${singleAddress.street1}" from a list of CA addresses`, function () { + assert.equal(singleAddress.state, 'CA') }); }) @@ -53,22 +53,21 @@ describe('US NY Address Data', function () { }); }) +describe('US ID Address Data', function () { + const address = dad.random('US_ID') + const addresses = dad.list('US_ID') -describe('US TX Address Data', function () { - const address = dad.random('US_TX') - const addresses = dad.list('US_TX') - - it('returns a random TX address', function () { - assert.equal(address.state, 'TX'); + it('returns a random ID address', function () { + assert.equal(address.state, 'ID'); }); - it('returns a list of TX addresses with a length of 100', function () { + it('returns a list of ID addresses with a length of 100', function () { assert.equal(addresses.addresses.length, 100); }) addresses.addresses.forEach(function (singleAddress) { - it(`returns "${singleAddress.street1}" from a list of TX addresses`, function () { - assert.equal(singleAddress.state, 'TX') + it(`returns "${singleAddress.street1}" from a list of ID addresses`, function () { + assert.equal(singleAddress.state, 'ID') }); }) @@ -79,22 +78,21 @@ describe('US TX Address Data', function () { }); }) +describe('US KS Address Data', function () { + const address = dad.random('US_KS') + const addresses = dad.list('US_KS') -describe('US CA Address Data', function () { - const address = dad.random('US_CA') - const addresses = dad.list('US_CA') - - it('returns a random CA address', function () { - assert.equal(address.state, 'CA'); + it('returns a random KS address', function () { + assert.equal(address.state, 'KS'); }); - it('returns a list of CA addresses with a length of 100', function () { + it('returns a list of KS addresses with a length of 100', function () { assert.equal(addresses.addresses.length, 100); }) addresses.addresses.forEach(function (singleAddress) { - it(`returns "${singleAddress.street1}" from a list of CA addresses`, function () { - assert.equal(singleAddress.state, 'CA') + it(`returns "${singleAddress.street1}" from a list of KS addresses`, function () { + assert.equal(singleAddress.state, 'KS') }); }) @@ -130,6 +128,31 @@ describe('US NV Address Data', function () { }); }) +describe('US NY Address Data', function () { + const address = dad.random('US_NY') + const addresses = dad.list('US_NY') + + it('returns a random NY address', function () { + assert.equal(address.state, 'NY'); + }); + + it('returns a list of NY addresses with a length of 100', function () { + assert.equal(addresses.addresses.length, 100); + }) + + addresses.addresses.forEach(function (singleAddress) { + it(`returns "${singleAddress.street1}" from a list of NY addresses`, function () { + assert.equal(singleAddress.state, 'NY') + }); + }) + + addresses.addresses.forEach(function (singleAddress) { + it(`ensures the data structure of "${singleAddress.street1}" is uniform`, function () { + expect(singleAddress).to.contain.all.keys('street1', 'street2', 'city', 'state', 'zip', 'country'); + }); + }); +}) + describe('US OR Address Data', function () { const address = dad.random('US_OR') const addresses = dad.list('US_OR') @@ -155,6 +178,31 @@ describe('US OR Address Data', function () { }); }) +describe('US TX Address Data', function () { + const address = dad.random('US_TX') + const addresses = dad.list('US_TX') + + it('returns a random TX address', function () { + assert.equal(address.state, 'TX'); + }); + + it('returns a list of TX addresses with a length of 100', function () { + assert.equal(addresses.addresses.length, 100); + }) + + addresses.addresses.forEach(function (singleAddress) { + it(`returns "${singleAddress.street1}" from a list of TX addresses`, function () { + assert.equal(singleAddress.state, 'TX') + }); + }) + + addresses.addresses.forEach(function (singleAddress) { + it(`ensures the data structure of "${singleAddress.street1}" is uniform`, function () { + expect(singleAddress).to.contain.all.keys('street1', 'street2', 'city', 'state', 'zip', 'country'); + }); + }); +}) + describe('US UT Address Data', function () { const address = dad.random('US_UT') const addresses = dad.list('US_UT') diff --git a/util/create-slim-json.js b/util/create-slim-json.js deleted file mode 100644 index 2c34823..0000000 --- a/util/create-slim-json.js +++ /dev/null @@ -1,14 +0,0 @@ -// A helper utility to build slim lists from a larger data set. Data source: http://results.openaddresses.io -const fs = require('fs') - -// Setup variables -const slimNumber = 100 // How many items should be pulled from the larger data set for this slim list -const dataSet = '' // Which data set are you pulling from? - -// Create a slim list based on the larger data set -const addresses = require(dataSet).addresses -for (var i = 0; i < slimNumber; i++) { - var randomAddress = addresses[Math.floor(Math.random() * addresses.length)] - fs.appendFileSync(`${dataSet}-slim.min`, JSON.stringify(randomAddress)) -} -console.log("Addresses slimmed, make sure to add commas where needed.") diff --git a/utils/create-slim-json.js b/utils/create-slim-json.js new file mode 100644 index 0000000..ace8533 --- /dev/null +++ b/utils/create-slim-json.js @@ -0,0 +1,47 @@ +const fs = require('fs') + +// A helper utility to build slim lists from a larger data set. Data source: https://batch.openaddresses.io/data +// You may be required to wrap the JSON in an addresses wrapper on the dataSet you want to use. eg: {"addresses":[{ ... } +// Additionally, you may be required to add commas after each JSON address object +// Usage: DATA_SET="path/to/dataset.json" STATE="UT" COUNTRY="US" node util/create-slim-json.js + +async function createSlimJson() { + const numberOfAddresses = process.env.NUM_ADDRESSES || 100 // How many items should be pulled from the larger data set for this slim list + const dataSetFilePath = process.env.DATA_SET // The path to a JSON data set you want to build a slim list from + const outputPath = `${dataSetFilePath}-slim.json` + const state = process.env.STATE || '' + const country = process.env.COUNTRY || '' + let finalList = [] + + if (dataSetFilePath) { + try { + for (let i = 0; i < numberOfAddresses; i++) { + // TODO: Strip or replace common formatting issues from the origin file here before building the object + const dataSetFile = require(dataSetFilePath).addresses + let randomAddress = dataSetFile[Math.floor(Math.random() * dataSetFile.length)]['properties'] + let addressObject = { + 'street1': `${randomAddress['number']} ${randomAddress['street']}`, + 'street2': randomAddress['unit'], + 'city': randomAddress['city'], + 'state': state, + 'zip': randomAddress['postcode'], + 'country': country + } + finalList.push(addressObject) + } + await fs.promises.writeFile(outputPath, JSON.stringify({ "addresses": finalList }) + '\n') + console.log(`Addresses slimmed and saved to ${outputPath}. Place the new list in its corresponding country folder and rename as needed.`) + return true + } catch (error) { + throw Error(error) + } + } else { + throw new Error('DATA_SET env variable must be set. Please correct and try again.') + } +} + +createSlimJson().catch(console.log) + +module.exports = { + createSlimJson +}