@chofter/geo 0.0.0-stage → 0.1.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 +21 -0
- package/README.md +255 -2
- package/dist/geo.d.ts +36 -0
- package/dist/geo.global.js +222 -0
- package/dist/geo.global.min.js +2 -0
- package/dist/geo.js +217 -0
- package/dist/geo.min.js +2 -0
- package/package.json +56 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Shane O'Sullivan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,256 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @chofter/geo
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Town and city search for any country, as a tiny dependency-free client. There is
|
|
4
|
+
no API and no key. The data is served as static JSON files from
|
|
5
|
+
[geo.chofter.com](https://geo.chofter.com), built monthly from
|
|
6
|
+
[GeoNames](https://www.geonames.org/). The client works out which file holds the
|
|
7
|
+
answer, fetches it from the CDN and ranks the results locally.
|
|
8
|
+
|
|
9
|
+
- About 226,000 towns and cities in 246 countries, with coordinates.
|
|
10
|
+
- One small request per keystroke at most, often none (files are cached).
|
|
11
|
+
- About 1.4 KB minified and gzipped. Works in browsers, Node 18+, Deno, Bun, Workers and React Native.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @chofter/geo
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import { createGeo } from "@chofter/geo";
|
|
21
|
+
|
|
22
|
+
const geo = createGeo();
|
|
23
|
+
const places = await geo.search("IE", "dub", { limit: 5 });
|
|
24
|
+
// [{ id: 2964574, name: "Dublin", region: "Leinster", country: "Ireland",
|
|
25
|
+
// countryCode: "IE", lat: 53.3331, lng: -6.2489, population: 1024027,
|
|
26
|
+
// label: "Dublin, Leinster, Ireland" }, ...]
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Without a bundler, import it straight from the CDN:
|
|
30
|
+
|
|
31
|
+
```html
|
|
32
|
+
<script type="module">
|
|
33
|
+
import { createGeo } from "https://geo.chofter.com/geo.js";
|
|
34
|
+
</script>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Or load the classic script, which adds one global, `choftergeo`:
|
|
38
|
+
|
|
39
|
+
```html
|
|
40
|
+
<script src="https://geo.chofter.com/geo.global.min.js"></script>
|
|
41
|
+
<script>
|
|
42
|
+
const geo = choftergeo.createGeo();
|
|
43
|
+
</script>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Files
|
|
47
|
+
|
|
48
|
+
Every build is in the npm package and on the CDN (`https://geo.chofter.com/<file>`),
|
|
49
|
+
and npm CDNs such as jsDelivr and unpkg serve the package too.
|
|
50
|
+
|
|
51
|
+
| File | Format | Import from npm | Size (gzip) |
|
|
52
|
+
| ------------------------ | ----------------------------- | ------------------------- | ----------- |
|
|
53
|
+
| `dist/geo.js` | ES module, readable | `@chofter/geo` | 2.8 KB |
|
|
54
|
+
| `dist/geo.min.js` | ES module, minified | `@chofter/geo/min` | 1.4 KB |
|
|
55
|
+
| `dist/geo.global.js` | classic script, readable | `@chofter/geo/global` | 2.8 KB |
|
|
56
|
+
| `dist/geo.global.min.js` | classic script, minified | `@chofter/geo/global.min` | 1.4 KB |
|
|
57
|
+
| `dist/geo.d.ts` | TypeScript types (all builds) | | |
|
|
58
|
+
|
|
59
|
+
Bundlers should use the default `@chofter/geo` entry and minify it themselves.
|
|
60
|
+
The minified files are for loading directly in a page.
|
|
61
|
+
|
|
62
|
+
## API
|
|
63
|
+
|
|
64
|
+
### `createGeo(options?)`
|
|
65
|
+
|
|
66
|
+
- `baseUrl`: where the data lives. Defaults to `https://geo.chofter.com/v1`;
|
|
67
|
+
set it if you host the files yourself.
|
|
68
|
+
- `fetch`: a custom `fetch` implementation.
|
|
69
|
+
|
|
70
|
+
Returns an object with:
|
|
71
|
+
|
|
72
|
+
- `search(countryCode, query, { limit = 10 })`: places in that country whose
|
|
73
|
+
name or an alternate name (including local spellings, such as "München" for
|
|
74
|
+
Munich) starts with the query, or has a later word that does. Case, accents
|
|
75
|
+
and punctuation are ignored. Exact matches come first, then larger places.
|
|
76
|
+
An empty query returns the largest places.
|
|
77
|
+
- `countries()`: `[{ code, name, count }]` for a country picker.
|
|
78
|
+
- `preload(countryCode)`: fetches the country's index early, for example when
|
|
79
|
+
the user picks a country.
|
|
80
|
+
|
|
81
|
+
`countryCode` is an ISO 3166-1 alpha-2 code such as `"US"` or `"ie"`.
|
|
82
|
+
Results include `matched` when the query matched an alternate name.
|
|
83
|
+
|
|
84
|
+
## Examples
|
|
85
|
+
|
|
86
|
+
These are real results from the live data. Long ones are cut down to the
|
|
87
|
+
fields that matter, with `// …` marking what was left out.
|
|
88
|
+
|
|
89
|
+
### A full result
|
|
90
|
+
|
|
91
|
+
```js
|
|
92
|
+
await geo.search("IE", "dub", { limit: 3 });
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
[
|
|
97
|
+
{
|
|
98
|
+
"id": 2964574,
|
|
99
|
+
"name": "Dublin",
|
|
100
|
+
"region": "Leinster",
|
|
101
|
+
"country": "Ireland",
|
|
102
|
+
"countryCode": "IE",
|
|
103
|
+
"lat": 53.3331,
|
|
104
|
+
"lng": -6.2489,
|
|
105
|
+
"population": 1024027,
|
|
106
|
+
"label": "Dublin, Leinster, Ireland"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"id": 2964690,
|
|
110
|
+
"name": "Douglas",
|
|
111
|
+
"region": "Munster",
|
|
112
|
+
"country": "Ireland",
|
|
113
|
+
"countryCode": "IE",
|
|
114
|
+
"lat": 51.8744,
|
|
115
|
+
"lng": -8.435,
|
|
116
|
+
"population": 26883,
|
|
117
|
+
"label": "Douglas, Munster, Ireland",
|
|
118
|
+
"matched": "Dúbhglas"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"id": 2966131,
|
|
122
|
+
"name": "Blackrock",
|
|
123
|
+
"region": "Leinster",
|
|
124
|
+
"country": "Ireland",
|
|
125
|
+
"countryCode": "IE",
|
|
126
|
+
"lat": 53.3015,
|
|
127
|
+
"lng": -6.1778,
|
|
128
|
+
"population": 8821,
|
|
129
|
+
"label": "Blackrock, Leinster, Ireland",
|
|
130
|
+
"matched": "Carraig Dubh"
|
|
131
|
+
}
|
|
132
|
+
]
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
`id` is the GeoNames id. `label` is ready to display. Douglas and Blackrock are
|
|
136
|
+
found by their Irish names, so `matched` says which name was hit. You might show
|
|
137
|
+
it as "Douglas (Dúbhglas)".
|
|
138
|
+
|
|
139
|
+
### Local spellings and other scripts
|
|
140
|
+
|
|
141
|
+
```js
|
|
142
|
+
await geo.search("DE", "München", { limit: 2 });
|
|
143
|
+
await geo.search("RU", "Москва", { limit: 1 });
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
```jsonc
|
|
147
|
+
[
|
|
148
|
+
{ "name": "Munich", "label": "Munich, Bavaria, Germany", "lat": 48.1374, "lng": 11.5755, "matched": "München" /* … */ },
|
|
149
|
+
{ "name": "Münchenbernsdorf", "label": "Münchenbernsdorf, Thuringia, Germany" /* … */ }
|
|
150
|
+
]
|
|
151
|
+
[
|
|
152
|
+
{ "name": "Moscow", "label": "Moscow, Moscow, Russia", "lat": 55.752, "lng": 37.6178, "matched": "Москва" /* … */ }
|
|
153
|
+
]
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Accents are optional: `"munchen"` and `"sao pau"` work just as well.
|
|
157
|
+
|
|
158
|
+
### Same name, different places
|
|
159
|
+
|
|
160
|
+
```js
|
|
161
|
+
(await geo.search("US", "springfield", { limit: 4 })).map((p) => p.label);
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
```json
|
|
165
|
+
[
|
|
166
|
+
"Springfield, Missouri, United States",
|
|
167
|
+
"Springfield, Massachusetts, United States",
|
|
168
|
+
"Springfield, Illinois, United States",
|
|
169
|
+
"Springfield, Oregon, United States"
|
|
170
|
+
]
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Use `region`, `lat` and `lng` (or `id`) to tell them apart. Exact matches come
|
|
174
|
+
first, largest first.
|
|
175
|
+
|
|
176
|
+
### Ranking: exact names, then prefixes and later words
|
|
177
|
+
|
|
178
|
+
```js
|
|
179
|
+
(await geo.search("US", "york")).map((p) => p.name);
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
```json
|
|
183
|
+
[
|
|
184
|
+
"York",
|
|
185
|
+
"York",
|
|
186
|
+
"York",
|
|
187
|
+
"York",
|
|
188
|
+
"York",
|
|
189
|
+
"New York City",
|
|
190
|
+
"West New York",
|
|
191
|
+
"Yorkville",
|
|
192
|
+
"York Beach",
|
|
193
|
+
"Yorktown"
|
|
194
|
+
]
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
The five towns called exactly "York" rank first. After them come names that
|
|
198
|
+
start with "york", or that have a later word starting with it, ordered by
|
|
199
|
+
population. That's how New York City appears.
|
|
200
|
+
|
|
201
|
+
### An empty query
|
|
202
|
+
|
|
203
|
+
```js
|
|
204
|
+
(await geo.search("FR", "", { limit: 5 })).map((p) => p.name);
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
```json
|
|
208
|
+
["Paris", "Marseille", "Lyon", "Toulouse", "Nice"]
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
The country's largest places, which are handy to show before the user types.
|
|
212
|
+
|
|
213
|
+
### Countries
|
|
214
|
+
|
|
215
|
+
```js
|
|
216
|
+
await geo.countries();
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
```jsonc
|
|
220
|
+
[
|
|
221
|
+
{ "code": "AF", "name": "Afghanistan", "count": 319 },
|
|
222
|
+
{ "code": "AX", "name": "Aland Islands", "count": 21 },
|
|
223
|
+
{ "code": "AL", "name": "Albania", "count": 418 },
|
|
224
|
+
// … 246 countries in all, sorted by name
|
|
225
|
+
]
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
`count` is the number of places in that country.
|
|
229
|
+
|
|
230
|
+
### No match and errors
|
|
231
|
+
|
|
232
|
+
```js
|
|
233
|
+
await geo.search("IE", "zzz"); // []
|
|
234
|
+
await geo.search("XX", "a"); // rejects: Error("geo: xx/_.json returned 404")
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
No match is an empty array, not an error. An unknown country code or a network
|
|
238
|
+
failure rejects, and the failed file is fetched again on the next call.
|
|
239
|
+
|
|
240
|
+
## How it works
|
|
241
|
+
|
|
242
|
+
Each country has an index file, `/v1/{cc}/_.json`, that lists its prefix files.
|
|
243
|
+
A small country fits in its index. For a larger one, the client reads the file
|
|
244
|
+
for the longest listed prefix of the query, such as `/v1/us/sa.json` for "San Fr".
|
|
245
|
+
Busy prefixes are split further, and the shorter file keeps the most populous
|
|
246
|
+
places, so every keystroke stays one small request.
|
|
247
|
+
|
|
248
|
+
## Licence
|
|
249
|
+
|
|
250
|
+
The code is MIT. The data comes from GeoNames under
|
|
251
|
+
[CC BY 4.0](https://creativecommons.org/licenses/by/4.0/): if you show results,
|
|
252
|
+
credit GeoNames, for example "Place data © GeoNames".
|
|
253
|
+
|
|
254
|
+
Clients for other languages live alongside this one in
|
|
255
|
+
[shaneosullivan/geo](https://github.com/shaneosullivan/geo) and share its
|
|
256
|
+
conformance tests.
|
package/dist/geo.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface Place {
|
|
2
|
+
/** GeoNames id. */
|
|
3
|
+
id: number;
|
|
4
|
+
name: string;
|
|
5
|
+
/** First-level admin division (state, province, county), may be empty. */
|
|
6
|
+
region: string;
|
|
7
|
+
country: string;
|
|
8
|
+
countryCode: string;
|
|
9
|
+
lat: number;
|
|
10
|
+
lng: number;
|
|
11
|
+
population: number;
|
|
12
|
+
/** "Name, Region, Country". */
|
|
13
|
+
label: string;
|
|
14
|
+
/** Set when the query matched an alternate name rather than `name`. */
|
|
15
|
+
matched?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface Country {
|
|
19
|
+
code: string;
|
|
20
|
+
name: string;
|
|
21
|
+
count: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface GeoOptions {
|
|
25
|
+
/** URL of the versioned data folder. Defaults to "https://geo.chofter.com/v1". */
|
|
26
|
+
baseUrl?: string;
|
|
27
|
+
fetch?: typeof fetch;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface Geo {
|
|
31
|
+
search(countryCode: string, query: string, options?: { limit?: number }): Promise<Place[]>;
|
|
32
|
+
countries(): Promise<Country[]>;
|
|
33
|
+
preload(countryCode: string): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function createGeo(options?: GeoOptions): Geo;
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// @chofter/geo 0.1.0 · MIT · https://geo.chofter.com · data © GeoNames (CC BY 4.0)
|
|
2
|
+
(function () {
|
|
3
|
+
"use strict";
|
|
4
|
+
// Client for the static place-search files. No dependencies; works in browsers,
|
|
5
|
+
// Node 18+, Workers and React Native.
|
|
6
|
+
//
|
|
7
|
+
// Naming scheme (everything is relative to baseUrl, e.g. https://geo.example.com/v1):
|
|
8
|
+
// {countryCode}/_.json country index: name, list of prefix files, top places.
|
|
9
|
+
// Small countries have no prefix files; `top` is every place.
|
|
10
|
+
// {countryCode}/{prefix}.json places whose search key starts with `prefix`
|
|
11
|
+
// For a query, the file to read is the longest listed prefix of the normalised
|
|
12
|
+
// query. Busy prefixes are split further: "s" may hold only the most populous
|
|
13
|
+
// places starting with s, while "sa" or "san" hold everything for that prefix.
|
|
14
|
+
|
|
15
|
+
const LETTER_FOLDS = {
|
|
16
|
+
ß: "ss",
|
|
17
|
+
æ: "ae",
|
|
18
|
+
œ: "oe",
|
|
19
|
+
ø: "o",
|
|
20
|
+
đ: "d",
|
|
21
|
+
ð: "d",
|
|
22
|
+
þ: "th",
|
|
23
|
+
ł: "l",
|
|
24
|
+
ı: "i",
|
|
25
|
+
ħ: "h",
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// normalize, prefixOf and fileKey are exported only so the data build can share
|
|
29
|
+
// them; the package's public entry point exposes nothing but createGeo.
|
|
30
|
+
|
|
31
|
+
/** Lowercase, strip accents and punctuation. Build script and client must agree on this. */
|
|
32
|
+
function normalize(text) {
|
|
33
|
+
return String(text)
|
|
34
|
+
.toLowerCase()
|
|
35
|
+
.normalize("NFD")
|
|
36
|
+
.replace(/\p{M}+/gu, "")
|
|
37
|
+
.replace(/[ßæœøđðþłıħ]/g, (letter) => LETTER_FOLDS[letter])
|
|
38
|
+
.replace(/['’‘ʼ`]/g, "")
|
|
39
|
+
.replace(/[^\p{L}\p{N}]+/gu, " ")
|
|
40
|
+
.trim();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** First `length` characters (code points) of a normalised key. */
|
|
44
|
+
function prefixOf(key, length) {
|
|
45
|
+
return Array.from(key).slice(0, length).join("");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** URL-safe file name for a prefix: a-z0-9 as is, space as "-", anything else as ~hex. */
|
|
49
|
+
function fileKey(prefix) {
|
|
50
|
+
let fileName = "";
|
|
51
|
+
for (const character of prefix) {
|
|
52
|
+
if (/[a-z0-9]/.test(character)) {
|
|
53
|
+
fileName += character;
|
|
54
|
+
} else if (character === " ") {
|
|
55
|
+
fileName += "-";
|
|
56
|
+
} else {
|
|
57
|
+
fileName += "~" + character.codePointAt(0).toString(16);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return fileName;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// A place in the JSON files is an array:
|
|
64
|
+
// [name, region, lat, lng, population, id, altNames?]
|
|
65
|
+
const NAME = 0;
|
|
66
|
+
const POPULATION = 4;
|
|
67
|
+
const ALT_NAMES = 6;
|
|
68
|
+
|
|
69
|
+
const EXACT_MATCH = 0;
|
|
70
|
+
const PREFIX_MATCH = 1;
|
|
71
|
+
const NO_MATCH = -1;
|
|
72
|
+
|
|
73
|
+
/** Pair each place with its names and their normalised search keys. */
|
|
74
|
+
function prepare(records) {
|
|
75
|
+
return records.map((record) => {
|
|
76
|
+
const names = [record[NAME], ...(record[ALT_NAMES] || [])];
|
|
77
|
+
return { record, names, searchKeys: names.map(normalize) };
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function matchTier(searchKey, query) {
|
|
82
|
+
if (searchKey === query) {
|
|
83
|
+
return EXACT_MATCH;
|
|
84
|
+
}
|
|
85
|
+
// A match at the start of the name or of a later word ranks the same, so
|
|
86
|
+
// "york" lists New York City above small towns that merely start with York.
|
|
87
|
+
if (searchKey.startsWith(query) || searchKey.includes(" " + query)) {
|
|
88
|
+
return PREFIX_MATCH;
|
|
89
|
+
}
|
|
90
|
+
return NO_MATCH;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** The best tier over all of a place's names, and which name gave it. */
|
|
94
|
+
function bestMatch(place, query) {
|
|
95
|
+
let tier = NO_MATCH;
|
|
96
|
+
let nameIndex = 0;
|
|
97
|
+
place.searchKeys.forEach((searchKey, index) => {
|
|
98
|
+
const candidate = matchTier(searchKey, query);
|
|
99
|
+
if (candidate !== NO_MATCH && (tier === NO_MATCH || candidate < tier)) {
|
|
100
|
+
tier = candidate;
|
|
101
|
+
nameIndex = index;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
return { tier, nameIndex };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const DEFAULT_BASE_URL = "https://geo.chofter.com/v1";
|
|
108
|
+
const DEFAULT_LIMIT = 10;
|
|
109
|
+
|
|
110
|
+
function createGeo(options = {}) {
|
|
111
|
+
const baseUrl = String(options.baseUrl || DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
112
|
+
const fetchFile = options.fetch || globalThis.fetch.bind(globalThis);
|
|
113
|
+
const cache = new Map(); // path -> Promise of the transformed file contents
|
|
114
|
+
|
|
115
|
+
/** Fetch and transform a file once; failed fetches are dropped so they are retried. */
|
|
116
|
+
function load(path, transform) {
|
|
117
|
+
let pending = cache.get(path);
|
|
118
|
+
if (!pending) {
|
|
119
|
+
pending = fetchFile(`${baseUrl}/${path}`)
|
|
120
|
+
.then((response) => {
|
|
121
|
+
if (!response.ok) {
|
|
122
|
+
throw new Error(`geo: ${path} returned ${response.status}`);
|
|
123
|
+
}
|
|
124
|
+
return response.json();
|
|
125
|
+
})
|
|
126
|
+
.then(transform);
|
|
127
|
+
pending.catch(() => cache.delete(path));
|
|
128
|
+
cache.set(path, pending);
|
|
129
|
+
}
|
|
130
|
+
return pending;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function loadCountry(countryCode) {
|
|
134
|
+
return load(`${countryCode}/_.json`, (index) => ({
|
|
135
|
+
code: countryCode.toUpperCase(),
|
|
136
|
+
name: index.name,
|
|
137
|
+
depth: index.depth,
|
|
138
|
+
count: index.count,
|
|
139
|
+
prefixFiles: new Set(index.shards),
|
|
140
|
+
topPlaces: prepare(index.top),
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function toResult(country, place, nameIndex) {
|
|
145
|
+
const [name, region, lat, lng, population, id] = place.record;
|
|
146
|
+
const result = {
|
|
147
|
+
id,
|
|
148
|
+
name,
|
|
149
|
+
region,
|
|
150
|
+
country: country.name,
|
|
151
|
+
countryCode: country.code,
|
|
152
|
+
lat,
|
|
153
|
+
lng,
|
|
154
|
+
population,
|
|
155
|
+
label: [name, region, country.name].filter(Boolean).join(", "),
|
|
156
|
+
};
|
|
157
|
+
if (nameIndex > 0) {
|
|
158
|
+
result.matched = place.names[nameIndex];
|
|
159
|
+
}
|
|
160
|
+
return result;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** The prefix file holding every place that could match `query`, or null if none is listed. */
|
|
164
|
+
function prefixFileFor(country, query) {
|
|
165
|
+
const longest = Math.min(country.depth, Array.from(query).length);
|
|
166
|
+
for (let length = longest; length > 0; length--) {
|
|
167
|
+
const candidate = fileKey(prefixOf(query, length));
|
|
168
|
+
if (country.prefixFiles.has(candidate)) {
|
|
169
|
+
return candidate;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Search one country. `countryCode` is an ISO 3166-1 alpha-2 code. */
|
|
176
|
+
async function search(countryCode, query, searchOptions = {}) {
|
|
177
|
+
const limit = searchOptions.limit || DEFAULT_LIMIT;
|
|
178
|
+
const country = await loadCountry(String(countryCode).toLowerCase());
|
|
179
|
+
const normalizedQuery = normalize(query || "");
|
|
180
|
+
if (!normalizedQuery) {
|
|
181
|
+
return country.topPlaces.slice(0, limit).map((place) => toResult(country, place, 0));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
let candidates = country.topPlaces;
|
|
185
|
+
if (country.depth > 0) {
|
|
186
|
+
const prefixFile = prefixFileFor(country, normalizedQuery);
|
|
187
|
+
if (prefixFile === null) {
|
|
188
|
+
return [];
|
|
189
|
+
}
|
|
190
|
+
candidates = await load(`${country.code.toLowerCase()}/${prefixFile}.json`, prepare);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const matches = [];
|
|
194
|
+
for (const place of candidates) {
|
|
195
|
+
const { tier, nameIndex } = bestMatch(place, normalizedQuery);
|
|
196
|
+
if (tier !== NO_MATCH) {
|
|
197
|
+
matches.push({ place, tier, nameIndex });
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
matches.sort(
|
|
201
|
+
(a, b) => a.tier - b.tier || b.place.record[POPULATION] - a.place.record[POPULATION],
|
|
202
|
+
);
|
|
203
|
+
return matches.slice(0, limit).map((match) => toResult(country, match.place, match.nameIndex));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** Countries that have data: [{ code, name, count }]. */
|
|
207
|
+
function countries() {
|
|
208
|
+
return load("countries.json", (rows) =>
|
|
209
|
+
rows.map(([code, name, count]) => ({ code, name, count })),
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** Warm the cache for a country, e.g. when the user picks it. */
|
|
214
|
+
function preload(countryCode) {
|
|
215
|
+
return loadCountry(String(countryCode).toLowerCase()).then(() => undefined);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return { search, countries, preload };
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
globalThis.choftergeo = { createGeo };
|
|
222
|
+
})();
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @chofter/geo 0.1.0 · MIT · https://geo.chofter.com · data © GeoNames (CC BY 4.0)
|
|
2
|
+
(()=>{var b={ß:"ss",æ:"ae",œ:"oe",ø:"o",đ:"d",ð:"d",þ:"th",ł:"l",ı:"i",ħ:"h"};function E(r){return String(r).toLowerCase().normalize("NFD").replace(/\p{M}+/gu,"").replace(/[ßæœøđðþłıħ]/g,(t)=>b[t]).replace(/['’‘ʼ`]/g,"").replace(/[^\p{L}\p{N}]+/gu," ").trim()}function x(r,t){return Array.from(r).slice(0,t).join("")}function N(r){let t="";for(let i of r)if(/[a-z0-9]/.test(i))t+=i;else if(i===" ")t+="-";else t+="~"+i.codePointAt(0).toString(16);return t}var P=0,A=4,U=6,j=0,I=1,m=-1;function L(r){return r.map((t)=>{let i=[t[P],...t[U]||[]];return{record:t,names:i,searchKeys:i.map(E)}})}function O(r,t){if(r===t)return j;if(r.startsWith(t)||r.includes(" "+t))return I;return m}function z(r,t){let i=m,f=0;return r.searchKeys.forEach((p,g)=>{let u=O(p,t);if(u!==m&&(i===m||u<i))i=u,f=g}),{tier:i,nameIndex:f}}var D="https://geo.chofter.com/v1",R=10;function F(r={}){let t=String(r.baseUrl||D).replace(/\/+$/,""),i=r.fetch||globalThis.fetch.bind(globalThis),f=new Map;function p(e,n){let a=f.get(e);if(!a)a=i(`${t}/${e}`).then((o)=>{if(!o.ok)throw Error(`geo: ${e} returned ${o.status}`);return o.json()}).then(n),a.catch(()=>f.delete(e)),f.set(e,a);return a}function g(e){return p(`${e}/_.json`,(n)=>({code:e.toUpperCase(),name:n.name,depth:n.depth,count:n.count,prefixFiles:new Set(n.shards),topPlaces:L(n.top)}))}function u(e,n,a){let[o,s,h,T,d,c]=n.record,l={id:c,name:o,region:s,country:e.name,countryCode:e.code,lat:h,lng:T,population:d,label:[o,s,e.name].filter(Boolean).join(", ")};if(a>0)l.matched=n.names[a];return l}function w(e,n){let a=Math.min(e.depth,Array.from(n).length);for(let o=a;o>0;o--){let s=N(x(n,o));if(e.prefixFiles.has(s))return s}return null}async function C(e,n,a={}){let o=a.limit||R,s=await g(String(e).toLowerCase()),h=E(n||"");if(!h)return s.topPlaces.slice(0,o).map((c)=>u(s,c,0));let T=s.topPlaces;if(s.depth>0){let c=w(s,h);if(c===null)return[];T=await p(`${s.code.toLowerCase()}/${c}.json`,L)}let d=[];for(let c of T){let{tier:l,nameIndex:_}=z(c,h);if(l!==m)d.push({place:c,tier:l,nameIndex:_})}return d.sort((c,l)=>c.tier-l.tier||l.place.record[A]-c.place.record[A]),d.slice(0,o).map((c)=>u(s,c.place,c.nameIndex))}function M(){return p("countries.json",(e)=>e.map(([n,a,o])=>({code:n,name:a,count:o})))}function S(e){return g(String(e).toLowerCase()).then(()=>{return})}return{search:C,countries:M,preload:S}}globalThis.choftergeo={createGeo:F};})();
|
package/dist/geo.js
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
// @chofter/geo 0.1.0 · MIT · https://geo.chofter.com · data © GeoNames (CC BY 4.0)
|
|
2
|
+
// Client for the static place-search files. No dependencies; works in browsers,
|
|
3
|
+
// Node 18+, Workers and React Native.
|
|
4
|
+
//
|
|
5
|
+
// Naming scheme (everything is relative to baseUrl, e.g. https://geo.example.com/v1):
|
|
6
|
+
// {countryCode}/_.json country index: name, list of prefix files, top places.
|
|
7
|
+
// Small countries have no prefix files; `top` is every place.
|
|
8
|
+
// {countryCode}/{prefix}.json places whose search key starts with `prefix`
|
|
9
|
+
// For a query, the file to read is the longest listed prefix of the normalised
|
|
10
|
+
// query. Busy prefixes are split further: "s" may hold only the most populous
|
|
11
|
+
// places starting with s, while "sa" or "san" hold everything for that prefix.
|
|
12
|
+
|
|
13
|
+
const LETTER_FOLDS = {
|
|
14
|
+
ß: "ss",
|
|
15
|
+
æ: "ae",
|
|
16
|
+
œ: "oe",
|
|
17
|
+
ø: "o",
|
|
18
|
+
đ: "d",
|
|
19
|
+
ð: "d",
|
|
20
|
+
þ: "th",
|
|
21
|
+
ł: "l",
|
|
22
|
+
ı: "i",
|
|
23
|
+
ħ: "h",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// normalize, prefixOf and fileKey are exported only so the data build can share
|
|
27
|
+
// them; the package's public entry point exposes nothing but createGeo.
|
|
28
|
+
|
|
29
|
+
/** Lowercase, strip accents and punctuation. Build script and client must agree on this. */
|
|
30
|
+
function normalize(text) {
|
|
31
|
+
return String(text)
|
|
32
|
+
.toLowerCase()
|
|
33
|
+
.normalize("NFD")
|
|
34
|
+
.replace(/\p{M}+/gu, "")
|
|
35
|
+
.replace(/[ßæœøđðþłıħ]/g, (letter) => LETTER_FOLDS[letter])
|
|
36
|
+
.replace(/['’‘ʼ`]/g, "")
|
|
37
|
+
.replace(/[^\p{L}\p{N}]+/gu, " ")
|
|
38
|
+
.trim();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** First `length` characters (code points) of a normalised key. */
|
|
42
|
+
function prefixOf(key, length) {
|
|
43
|
+
return Array.from(key).slice(0, length).join("");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** URL-safe file name for a prefix: a-z0-9 as is, space as "-", anything else as ~hex. */
|
|
47
|
+
function fileKey(prefix) {
|
|
48
|
+
let fileName = "";
|
|
49
|
+
for (const character of prefix) {
|
|
50
|
+
if (/[a-z0-9]/.test(character)) {
|
|
51
|
+
fileName += character;
|
|
52
|
+
} else if (character === " ") {
|
|
53
|
+
fileName += "-";
|
|
54
|
+
} else {
|
|
55
|
+
fileName += "~" + character.codePointAt(0).toString(16);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return fileName;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// A place in the JSON files is an array:
|
|
62
|
+
// [name, region, lat, lng, population, id, altNames?]
|
|
63
|
+
const NAME = 0;
|
|
64
|
+
const POPULATION = 4;
|
|
65
|
+
const ALT_NAMES = 6;
|
|
66
|
+
|
|
67
|
+
const EXACT_MATCH = 0;
|
|
68
|
+
const PREFIX_MATCH = 1;
|
|
69
|
+
const NO_MATCH = -1;
|
|
70
|
+
|
|
71
|
+
/** Pair each place with its names and their normalised search keys. */
|
|
72
|
+
function prepare(records) {
|
|
73
|
+
return records.map((record) => {
|
|
74
|
+
const names = [record[NAME], ...(record[ALT_NAMES] || [])];
|
|
75
|
+
return { record, names, searchKeys: names.map(normalize) };
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function matchTier(searchKey, query) {
|
|
80
|
+
if (searchKey === query) {
|
|
81
|
+
return EXACT_MATCH;
|
|
82
|
+
}
|
|
83
|
+
// A match at the start of the name or of a later word ranks the same, so
|
|
84
|
+
// "york" lists New York City above small towns that merely start with York.
|
|
85
|
+
if (searchKey.startsWith(query) || searchKey.includes(" " + query)) {
|
|
86
|
+
return PREFIX_MATCH;
|
|
87
|
+
}
|
|
88
|
+
return NO_MATCH;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The best tier over all of a place's names, and which name gave it. */
|
|
92
|
+
function bestMatch(place, query) {
|
|
93
|
+
let tier = NO_MATCH;
|
|
94
|
+
let nameIndex = 0;
|
|
95
|
+
place.searchKeys.forEach((searchKey, index) => {
|
|
96
|
+
const candidate = matchTier(searchKey, query);
|
|
97
|
+
if (candidate !== NO_MATCH && (tier === NO_MATCH || candidate < tier)) {
|
|
98
|
+
tier = candidate;
|
|
99
|
+
nameIndex = index;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
return { tier, nameIndex };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const DEFAULT_BASE_URL = "https://geo.chofter.com/v1";
|
|
106
|
+
const DEFAULT_LIMIT = 10;
|
|
107
|
+
|
|
108
|
+
export function createGeo(options = {}) {
|
|
109
|
+
const baseUrl = String(options.baseUrl || DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
110
|
+
const fetchFile = options.fetch || globalThis.fetch.bind(globalThis);
|
|
111
|
+
const cache = new Map(); // path -> Promise of the transformed file contents
|
|
112
|
+
|
|
113
|
+
/** Fetch and transform a file once; failed fetches are dropped so they are retried. */
|
|
114
|
+
function load(path, transform) {
|
|
115
|
+
let pending = cache.get(path);
|
|
116
|
+
if (!pending) {
|
|
117
|
+
pending = fetchFile(`${baseUrl}/${path}`)
|
|
118
|
+
.then((response) => {
|
|
119
|
+
if (!response.ok) {
|
|
120
|
+
throw new Error(`geo: ${path} returned ${response.status}`);
|
|
121
|
+
}
|
|
122
|
+
return response.json();
|
|
123
|
+
})
|
|
124
|
+
.then(transform);
|
|
125
|
+
pending.catch(() => cache.delete(path));
|
|
126
|
+
cache.set(path, pending);
|
|
127
|
+
}
|
|
128
|
+
return pending;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function loadCountry(countryCode) {
|
|
132
|
+
return load(`${countryCode}/_.json`, (index) => ({
|
|
133
|
+
code: countryCode.toUpperCase(),
|
|
134
|
+
name: index.name,
|
|
135
|
+
depth: index.depth,
|
|
136
|
+
count: index.count,
|
|
137
|
+
prefixFiles: new Set(index.shards),
|
|
138
|
+
topPlaces: prepare(index.top),
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function toResult(country, place, nameIndex) {
|
|
143
|
+
const [name, region, lat, lng, population, id] = place.record;
|
|
144
|
+
const result = {
|
|
145
|
+
id,
|
|
146
|
+
name,
|
|
147
|
+
region,
|
|
148
|
+
country: country.name,
|
|
149
|
+
countryCode: country.code,
|
|
150
|
+
lat,
|
|
151
|
+
lng,
|
|
152
|
+
population,
|
|
153
|
+
label: [name, region, country.name].filter(Boolean).join(", "),
|
|
154
|
+
};
|
|
155
|
+
if (nameIndex > 0) {
|
|
156
|
+
result.matched = place.names[nameIndex];
|
|
157
|
+
}
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** The prefix file holding every place that could match `query`, or null if none is listed. */
|
|
162
|
+
function prefixFileFor(country, query) {
|
|
163
|
+
const longest = Math.min(country.depth, Array.from(query).length);
|
|
164
|
+
for (let length = longest; length > 0; length--) {
|
|
165
|
+
const candidate = fileKey(prefixOf(query, length));
|
|
166
|
+
if (country.prefixFiles.has(candidate)) {
|
|
167
|
+
return candidate;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Search one country. `countryCode` is an ISO 3166-1 alpha-2 code. */
|
|
174
|
+
async function search(countryCode, query, searchOptions = {}) {
|
|
175
|
+
const limit = searchOptions.limit || DEFAULT_LIMIT;
|
|
176
|
+
const country = await loadCountry(String(countryCode).toLowerCase());
|
|
177
|
+
const normalizedQuery = normalize(query || "");
|
|
178
|
+
if (!normalizedQuery) {
|
|
179
|
+
return country.topPlaces.slice(0, limit).map((place) => toResult(country, place, 0));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
let candidates = country.topPlaces;
|
|
183
|
+
if (country.depth > 0) {
|
|
184
|
+
const prefixFile = prefixFileFor(country, normalizedQuery);
|
|
185
|
+
if (prefixFile === null) {
|
|
186
|
+
return [];
|
|
187
|
+
}
|
|
188
|
+
candidates = await load(`${country.code.toLowerCase()}/${prefixFile}.json`, prepare);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const matches = [];
|
|
192
|
+
for (const place of candidates) {
|
|
193
|
+
const { tier, nameIndex } = bestMatch(place, normalizedQuery);
|
|
194
|
+
if (tier !== NO_MATCH) {
|
|
195
|
+
matches.push({ place, tier, nameIndex });
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
matches.sort(
|
|
199
|
+
(a, b) => a.tier - b.tier || b.place.record[POPULATION] - a.place.record[POPULATION],
|
|
200
|
+
);
|
|
201
|
+
return matches.slice(0, limit).map((match) => toResult(country, match.place, match.nameIndex));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** Countries that have data: [{ code, name, count }]. */
|
|
205
|
+
function countries() {
|
|
206
|
+
return load("countries.json", (rows) =>
|
|
207
|
+
rows.map(([code, name, count]) => ({ code, name, count })),
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** Warm the cache for a country, e.g. when the user picks it. */
|
|
212
|
+
function preload(countryCode) {
|
|
213
|
+
return loadCountry(String(countryCode).toLowerCase()).then(() => undefined);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return { search, countries, preload };
|
|
217
|
+
}
|
package/dist/geo.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @chofter/geo 0.1.0 · MIT · https://geo.chofter.com · data © GeoNames (CC BY 4.0)
|
|
2
|
+
var _={ß:"ss",æ:"ae",œ:"oe",ø:"o",đ:"d",ð:"d",þ:"th",ł:"l",ı:"i",ħ:"h"};function E(r){return String(r).toLowerCase().normalize("NFD").replace(/\p{M}+/gu,"").replace(/[ßæœøđðþłıħ]/g,(t)=>_[t]).replace(/['’‘ʼ`]/g,"").replace(/[^\p{L}\p{N}]+/gu," ").trim()}function x(r,t){return Array.from(r).slice(0,t).join("")}function N(r){let t="";for(let i of r)if(/[a-z0-9]/.test(i))t+=i;else if(i===" ")t+="-";else t+="~"+i.codePointAt(0).toString(16);return t}var P=0,T=4,U=6,b=0,j=1,h=-1;function L(r){return r.map((t)=>{let i=[t[P],...t[U]||[]];return{record:t,names:i,searchKeys:i.map(E)}})}function I(r,t){if(r===t)return b;if(r.startsWith(t)||r.includes(" "+t))return j;return h}function O(r,t){let i=h,f=0;return r.searchKeys.forEach((p,g)=>{let u=I(p,t);if(u!==h&&(i===h||u<i))i=u,f=g}),{tier:i,nameIndex:f}}var z="https://geo.chofter.com/v1",D=10;function R(r={}){let t=String(r.baseUrl||z).replace(/\/+$/,""),i=r.fetch||globalThis.fetch.bind(globalThis),f=new Map;function p(e,n){let a=f.get(e);if(!a)a=i(`${t}/${e}`).then((o)=>{if(!o.ok)throw Error(`geo: ${e} returned ${o.status}`);return o.json()}).then(n),a.catch(()=>f.delete(e)),f.set(e,a);return a}function g(e){return p(`${e}/_.json`,(n)=>({code:e.toUpperCase(),name:n.name,depth:n.depth,count:n.count,prefixFiles:new Set(n.shards),topPlaces:L(n.top)}))}function u(e,n,a){let[o,s,d,A,m,c]=n.record,l={id:c,name:o,region:s,country:e.name,countryCode:e.code,lat:d,lng:A,population:m,label:[o,s,e.name].filter(Boolean).join(", ")};if(a>0)l.matched=n.names[a];return l}function F(e,n){let a=Math.min(e.depth,Array.from(n).length);for(let o=a;o>0;o--){let s=N(x(n,o));if(e.prefixFiles.has(s))return s}return null}async function w(e,n,a={}){let o=a.limit||D,s=await g(String(e).toLowerCase()),d=E(n||"");if(!d)return s.topPlaces.slice(0,o).map((c)=>u(s,c,0));let A=s.topPlaces;if(s.depth>0){let c=F(s,d);if(c===null)return[];A=await p(`${s.code.toLowerCase()}/${c}.json`,L)}let m=[];for(let c of A){let{tier:l,nameIndex:S}=O(c,d);if(l!==h)m.push({place:c,tier:l,nameIndex:S})}return m.sort((c,l)=>c.tier-l.tier||l.place.record[T]-c.place.record[T]),m.slice(0,o).map((c)=>u(s,c.place,c.nameIndex))}function C(){return p("countries.json",(e)=>e.map(([n,a,o])=>({code:n,name:a,count:o})))}function M(e){return g(String(e).toLowerCase()).then(()=>{return})}return{search:w,countries:C,preload:M}}export{R as createGeo};
|
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chofter/geo",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Tiny, dependency-free town and city search over static GeoNames files. No API, no key.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"geonames",
|
|
7
|
+
"geocoding",
|
|
8
|
+
"places",
|
|
9
|
+
"cities",
|
|
10
|
+
"towns",
|
|
11
|
+
"autocomplete",
|
|
12
|
+
"search"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/shaneosullivan/geo/tree/main/js#readme",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/shaneosullivan/geo.git",
|
|
18
|
+
"directory": "js"
|
|
19
|
+
},
|
|
20
|
+
"bugs": "https://github.com/shaneosullivan/geo/issues",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/geo.d.ts",
|
|
27
|
+
"default": "./dist/geo.js"
|
|
28
|
+
},
|
|
29
|
+
"./min": {
|
|
30
|
+
"types": "./dist/geo.d.ts",
|
|
31
|
+
"default": "./dist/geo.min.js"
|
|
32
|
+
},
|
|
33
|
+
"./global": "./dist/geo.global.js",
|
|
34
|
+
"./global.min": "./dist/geo.global.min.js",
|
|
35
|
+
"./package.json": "./package.json"
|
|
36
|
+
},
|
|
37
|
+
"types": "./dist/geo.d.ts",
|
|
38
|
+
"unpkg": "./dist/geo.global.min.js",
|
|
39
|
+
"jsdelivr": "./dist/geo.global.min.js",
|
|
40
|
+
"files": [
|
|
41
|
+
"dist"
|
|
42
|
+
],
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "bun build.mjs",
|
|
45
|
+
"test": "bun build.mjs && node --test",
|
|
46
|
+
"lint": "oxlint -c ../.oxlintrc.json .",
|
|
47
|
+
"format": "oxfmt -c ../.oxfmtrc.json .",
|
|
48
|
+
"format:check": "oxfmt --check -c ../.oxfmtrc.json .",
|
|
49
|
+
"prepublishOnly": "npm test"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=18"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"oxlint": "^1.94.0",
|
|
56
|
+
"oxfmt": "^0.79.0"
|
|
57
|
+
}
|
|
58
|
+
}
|