Skip to content

Commit

Permalink
v4.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Justintime50 committed Aug 2, 2021
1 parent bc12b0b commit f27bfb1
Show file tree
Hide file tree
Showing 15 changed files with 276 additions and 250 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

## v4.1.0 (2021-08-02)

* Swaps the manually downloaded DAD data to a git submodule for easier management moving forward
* Reworks the entire `data-router` from a switch/case statement to an object literal for easier management. Refactored the order of logic and changed all variable names for easier readability
* Tags will not automatically be capatilized when passed as parameters to assist in capitilization input errors
* Bumps dependencies

## v4.0.0 (2021-07-12)

* Separates DAD address data into a separate repo (https://github.com/justintime50/dad), removes tooling and references to data and focuses instead on implementing a way to retrieve that data via Node
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ npm i -g dad-tool

# Install locally for package implementation
npm i dad-tool
git submodule init && git submodule update
```

## Address Data
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node
const path = require('path')
const dataRouter = require('./lib/data-router')
const dataRouter = require('./lib/dataRouter')

// Pull an entire list of addresses
function list(data) {
Expand Down
87 changes: 0 additions & 87 deletions lib/data-router.js

This file was deleted.

54 changes: 54 additions & 0 deletions lib/dataRouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
function variables(data) {
// DAD variables
const addressDirectory = 'dad/src/addresses'
const fileExtension = '-addresses.min.json'
const australiaDirectory = 'australia'
const canadaDirectory = 'canada'
const chinaDirectory = 'china'
const europeDirectory = 'europe'
const mexicoDirectory = 'mexico'
const unitedStatesDirectory = 'united-states/'
const invalidTagErrorMessage = 'Data source tag was not valid. An address could not be retrieved.'
let dataFilePath = null


// Country variables
const dataFilePaths = {
// Australia
'AU_VT': `${addressDirectory}/${australiaDirectory}/vt${fileExtension}`,
// Canada
'CA_BC': `${addressDirectory}/${canadaDirectory}/bc${fileExtension}`,
// China
'CN_BJ': `${addressDirectory}/${chinaDirectory}/bj${fileExtension}`,
'CN_HK': `${addressDirectory}/${chinaDirectory}/hk${fileExtension}`,
// Europe
'EU_DE': `${addressDirectory}/${europeDirectory}/de${fileExtension}`,
'EU_ES': `${addressDirectory}/${europeDirectory}/es${fileExtension}`,
'EU_UK': `${addressDirectory}/${europeDirectory}/uk${fileExtension}`,
// Mexico
'MX_MX': `${addressDirectory}/${mexicoDirectory}/mx${fileExtension}`,
// United States
'US_AZ': `${addressDirectory}/${unitedStatesDirectory}/az${fileExtension}`,
'US_CA': `${addressDirectory}/${unitedStatesDirectory}/ca${fileExtension}`,
'US_ID': `${addressDirectory}/${unitedStatesDirectory}/id${fileExtension}`,
'US_KS': `${addressDirectory}/${unitedStatesDirectory}/ks${fileExtension}`,
'US_NV': `${addressDirectory}/${unitedStatesDirectory}/nv${fileExtension}`,
'US_NY': `${addressDirectory}/${unitedStatesDirectory}/ny${fileExtension}`,
'US_OR': `${addressDirectory}/${unitedStatesDirectory}/or${fileExtension}`,
'US_TX': `${addressDirectory}/${unitedStatesDirectory}/tx${fileExtension}`,
'US_UT': `${addressDirectory}/${unitedStatesDirectory}/ut${fileExtension}`,
'US_WA': `${addressDirectory}/${unitedStatesDirectory}/wa${fileExtension}`,
// Invalid data source tag
'invalid': null,
}

dataFilePath = dataFilePaths[data.toUpperCase()] || dataFilePaths['invalid']

if (dataFilePath === null) {
throw new Error(invalidTagErrorMessage)
}

return dataFilePath
}

exports.variables = variables
Loading

0 comments on commit f27bfb1

Please sign in to comment.