-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,870 additions
and
1,147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# https://editorconfig.org/ | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
extends: [require.resolve('amper-scripts/config/eslint')], | ||
root: true | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Publish update | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: '16' | ||
cache: 'yarn' | ||
registry-url: 'https://registry.npmjs.org' | ||
|
||
- run: yarn install | ||
|
||
- run: yarn publish | ||
name: Publish to npm | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Run tests | ||
|
||
on: push | ||
|
||
jobs: | ||
run-tests: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
fail-fast: true | ||
matrix: | ||
node_version: | ||
- '12' | ||
- '14' | ||
- '16' | ||
- '17' | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- uses: actions/setup-node@v2 | ||
name: Use Node.js v${{matrix.node_version}} | ||
with: | ||
node-version: ${{matrix.node_version}} | ||
cache: 'yarn' | ||
|
||
- run: yarn install | ||
|
||
- run: yarn test |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1 @@ | ||
module.exports = { | ||
arrowParens: 'avoid', | ||
bracketSpacing: true, | ||
endOfLine: 'lf', | ||
jsxBracketSameLine: false, | ||
jsxSingleQuote: false, | ||
printWidth: 80, | ||
semi: true, | ||
singleQuote: true, | ||
tabWidth: 2, | ||
trailingComma: 'none', | ||
useTabs: false | ||
}; | ||
module.exports = require('amper-scripts/config/prettier.config.js'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import sphereKnn from 'sphere-knn'; | ||
import { | ||
GeolocationInput, | ||
standardizeGeolocation | ||
} from 'standardize-geolocation'; | ||
import { ZIPCode } from 'us-zips'; | ||
import usZips, { ZIPCodeList } from 'us-zips/array'; | ||
|
||
export interface Options { | ||
limit: number; | ||
} | ||
|
||
export const defaultOptions: Options = { limit: 1 }; | ||
|
||
// Start building lookup when module imported | ||
const lookup = sphereKnn(usZips); | ||
|
||
// Don't recreate this function on every run | ||
const pluckZipCode = (obj: { zipCode: string }) => obj.zipCode; | ||
|
||
export function geo2zip( | ||
location: GeolocationInput, | ||
extraOptions: Partial<Options> = {} | ||
): Promise<ZIPCode[]> { | ||
const options = { ...defaultOptions, ...extraOptions }; | ||
const { latitude, longitude } = standardizeGeolocation(location); | ||
|
||
return new Promise(resolve => { | ||
const results = lookup(latitude, longitude, options.limit) as ZIPCodeList; | ||
|
||
resolve(results.map(pluckZipCode)); | ||
}); | ||
} | ||
|
||
export default geo2zip; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
declare module 'sphere-knn' { | ||
type WithLatitude = { lat: number } | { latitude: number }; | ||
|
||
type WithLongitude = | ||
| { lon: number } | ||
| { lng: number } | ||
| { long: number } | ||
| { longitude: number }; | ||
|
||
type Geolocation = | ||
| [number, number] | ||
| { location: [number, number] } | ||
| { position: [number, number] } | ||
| { geometry: { coordinates: [number, number]; type: 'Point' } } | ||
| (WithLatitude & WithLongitude); | ||
|
||
type Lookup = ( | ||
latitude: number, | ||
longitude: number, | ||
limit?: number, | ||
maxDistance?: number | ||
) => Geolocation[]; | ||
|
||
type SphereKnn<T = Geolocation> = (points: T[]) => Lookup; | ||
|
||
const defaultExport: SphereKnn; | ||
export = defaultExport; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"compilerOptions": { | ||
"allowJs": true, | ||
"allowSyntheticDefaultImports": true, | ||
"baseUrl": ".", | ||
"declaration": true, | ||
"esModuleInterop": true, | ||
"incremental": true, | ||
"module": "CommonJS", | ||
"moduleResolution": "node", | ||
"noImplicitAny": true, | ||
"outDir": "dist", | ||
"sourceMap": true, | ||
"target": "ES2019", | ||
"paths": { | ||
"*": ["node_modules/*", "src/types/*"] | ||
} | ||
}, | ||
"include": ["src/**/*"] | ||
} |
Oops, something went wrong.