Skip to content

Commit

Permalink
Merge pull request #130 from evansiroky/named-exports
Browse files Browse the repository at this point in the history
Remove default export in favor of named exports
  • Loading branch information
evansiroky authored Nov 27, 2021
2 parents 4f0bf4f + adb1f21 commit afa29d3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,27 @@ The most up-to-date and accurate node.js geographical timezone lookup package.
## Usage

```js
const geoTz = require('geo-tz')
const { find } = require('geo-tz')

geoTz(47.650499, -122.350070) // ['America/Los_Angeles']
geoTz(43.839319, 87.526148) // ['Asia/Shanghai', 'Asia/Urumqi']
find(47.650499, -122.350070) // ['America/Los_Angeles']
find(43.839319, 87.526148) // ['Asia/Shanghai', 'Asia/Urumqi']
```

## API Docs:

As of Version 7, there is no longer a default import. The `find` function should be used instead.

As of Version 5, the API now returns a list of possible timezones. There are certain coordinates where the timekeeping method will depend on the person you ask. Also, another case where 2 or more timezones could be returned is when a request is made with a coordinate that happens to be exactly on the border between two or more timezones.

### geoTz(lat, lon)
### find(lat, lon)

Returns the timezone names found at `lat`, `lon`. The timezone names will be the timezone identifiers as defined in the [timezone database](https://www.iana.org/time-zones). The underlying geographic data is obtained from the [timezone-boudary-builder](https://github.com/evansiroky/timezone-boundary-builder) project.

This library does an exact geographic lookup which has tradeoffs. It is perhaps a little bit slower that other libraries, has a larger installation size on disk and cannot be used in the browser. However, the results are more accurate than other libraries that compromise by approximating the lookup of the data.

The data is indexed for fast analysis by caching subregions of geographic data when a precise lookup is needed.

### geoTz.setCache(options)
### setCache(options)

By default, geoTz lazy-loads exact lookup data into an unexpiring cache. The `setCache` method can be used to change the caching behavior using the following options:

Expand All @@ -38,10 +40,10 @@ By default, geoTz lazy-loads exact lookup data into an unexpiring cache. The `se
Examples:

```js
geoTz.setCache({ preload: true }) // preloads all files
setCache({ preload: true }) // preloads all files

let map = new Map();
geoTz.setCache({ store: map }) // pass a Map-like storage object
setCache({ store: map }) // pass a Map-like storage object
```

## Limitations
Expand Down
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
"node": ">=12"
},
"source": "src/find.ts",
"exports": {
"require": "./dist/geo-tz.js",
"default": "./dist/geo-tz.modern.js"
},
"main": "./dist/geo-tz.js",
"module": "./dist/geo-tz.module.js",
"unpkg": "./dist/geo-tz.umd.js",
Expand Down
2 changes: 1 addition & 1 deletion src/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function loadFeatures(
* @param lon longitue (must be >= -180 and <=180)
* @returns An array of string of TZIDs at the given coordinate.
*/
export default function getTimezone(lat: number, lon: number): string[] {
export function find(lat: number, lon: number): string[] {
const originalLon = lon

let err
Expand Down
6 changes: 3 additions & 3 deletions tests/find.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { assert } from 'chai'

import geoTz, { preCache } from '../src/find'
import { find, preCache } from '../src/find'
import { oceanZones } from '../src/oceanUtils'

const issueCoords = require('./fixtures/issues.json')
Expand All @@ -20,7 +20,7 @@ function assertTzResultContainsTzs(lat, lon, tzs) {
if (typeof tzs === 'string') {
tzs = [tzs]
}
const result = geoTz(lat, lon)
const result = find(lat, lon)
assert.isArray(result)
assert.sameMembers(result, tzs)
}
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('find tests', function () {
const timingStr = 'find tz of ' + count + ' random european positions'
console.time(timingStr)
for (let i = 0; i < count; i++) {
geoTz(
find(
europeTopLeft[0] +
Math.random() * (europeBottomRight[0] - europeTopLeft[0]),
europeTopLeft[1] +
Expand Down

0 comments on commit afa29d3

Please sign in to comment.