@hebcal/geo-sqlite 4.2.0 → 4.3.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/dist/index.js +27 -14
- package/dist/index.mjs +27 -14
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @hebcal/geo-sqlite v4.
|
|
1
|
+
/*! @hebcal/geo-sqlite v4.3.0 */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -306,33 +306,39 @@ class GeoDb {
|
|
|
306
306
|
/**
|
|
307
307
|
* @private
|
|
308
308
|
* @param {any[]} res
|
|
309
|
+
* @param {boolean} latlong
|
|
309
310
|
* @return {Object[]}
|
|
310
311
|
*/
|
|
311
312
|
|
|
312
313
|
|
|
313
|
-
static zipResultToObj(res) {
|
|
314
|
+
static zipResultToObj(res, latlong = false) {
|
|
314
315
|
const obj = {
|
|
315
316
|
id: String(res.ZipCode),
|
|
316
317
|
value: `${res.CityMixedCase}, ${res.State} ${res.ZipCode}`,
|
|
317
318
|
admin1: res.State,
|
|
318
319
|
asciiname: res.CityMixedCase,
|
|
319
320
|
country: 'United States',
|
|
320
|
-
latitude: res.Latitude,
|
|
321
|
-
longitude: res.Longitude,
|
|
322
|
-
timezone: core.Location.getUsaTzid(res.State, res.TimeZone, res.DayLightSaving),
|
|
323
321
|
population: res.Population,
|
|
324
322
|
geo: 'zip'
|
|
325
323
|
};
|
|
324
|
+
|
|
325
|
+
if (latlong) {
|
|
326
|
+
obj.latitude = res.Latitude;
|
|
327
|
+
obj.longitude = res.Longitude;
|
|
328
|
+
obj.timezone = core.Location.getUsaTzid(res.State, res.TimeZone, res.DayLightSaving);
|
|
329
|
+
}
|
|
330
|
+
|
|
326
331
|
return obj;
|
|
327
332
|
}
|
|
328
333
|
/**
|
|
329
334
|
* Generates autocomplete results based on a query string
|
|
330
335
|
* @param {string} qraw
|
|
336
|
+
* @param {boolean} latlong
|
|
331
337
|
* @return {Object[]}
|
|
332
338
|
*/
|
|
333
339
|
|
|
334
340
|
|
|
335
|
-
autoComplete(qraw) {
|
|
341
|
+
autoComplete(qraw, latlong = false) {
|
|
336
342
|
qraw = qraw.trim();
|
|
337
343
|
|
|
338
344
|
if (qraw.length === 0) {
|
|
@@ -347,7 +353,7 @@ class GeoDb {
|
|
|
347
353
|
}
|
|
348
354
|
|
|
349
355
|
const zip5 = qraw.substring(0, 5);
|
|
350
|
-
return this.zipCompStmt.all(zip5 + '%').map(GeoDb.zipResultToObj);
|
|
356
|
+
return this.zipCompStmt.all(zip5 + '%').map(row => GeoDb.zipResultToObj(row, latlong));
|
|
351
357
|
} else {
|
|
352
358
|
if (!this.geonamesCompStmt) {
|
|
353
359
|
this.geonamesCompStmt = this.geonamesDb.prepare(GEONAME_COMPLETE_SQL);
|
|
@@ -362,11 +368,6 @@ class GeoDb {
|
|
|
362
368
|
id: res.geonameid,
|
|
363
369
|
value: core.Location.geonameCityDescr(res.asciiname, admin1, country),
|
|
364
370
|
asciiname: res.asciiname,
|
|
365
|
-
admin1,
|
|
366
|
-
country,
|
|
367
|
-
latitude: res.latitude,
|
|
368
|
-
longitude: res.longitude,
|
|
369
|
-
timezone: res.timezone,
|
|
370
371
|
population: res.population,
|
|
371
372
|
geo: 'geoname'
|
|
372
373
|
};
|
|
@@ -379,7 +380,12 @@ class GeoDb {
|
|
|
379
380
|
obj.admin1 = admin1;
|
|
380
381
|
}
|
|
381
382
|
|
|
382
|
-
|
|
383
|
+
if (latlong) {
|
|
384
|
+
obj.latitude = res.latitude;
|
|
385
|
+
obj.longitude = res.longitude;
|
|
386
|
+
obj.timezone = res.timezone;
|
|
387
|
+
}
|
|
388
|
+
|
|
383
389
|
return obj;
|
|
384
390
|
});
|
|
385
391
|
|
|
@@ -388,7 +394,7 @@ class GeoDb {
|
|
|
388
394
|
}
|
|
389
395
|
|
|
390
396
|
const zipRows = this.zipFulltextCompStmt.all(`"${qraw}*"`);
|
|
391
|
-
const zipMatches = zipRows.map(GeoDb.zipResultToObj);
|
|
397
|
+
const zipMatches = zipRows.map(row => GeoDb.zipResultToObj(row, latlong));
|
|
392
398
|
const map = new Map();
|
|
393
399
|
|
|
394
400
|
for (const obj of zipMatches) {
|
|
@@ -565,6 +571,13 @@ async function buildGeonamesSqlite(opts) {
|
|
|
565
571
|
} else {
|
|
566
572
|
a[3] = a[3].replace(/‘/g, '\'');
|
|
567
573
|
a[3] = a[3].replace(/’/g, '\'');
|
|
574
|
+
a[3] = a[3].replace(/Ḥ/g, 'Ch');
|
|
575
|
+
a[3] = a[3].replace(/H̱/g, 'Ch');
|
|
576
|
+
a[3] = a[3].replace(/ẖ/g, 'ch');
|
|
577
|
+
a[3] = a[3].replace(/Ẕ/g, 'Tz');
|
|
578
|
+
a[3] = a[3].replace(/ẕ/g, 'tz');
|
|
579
|
+
a[3] = a[3].replace(/ā/g, 'a');
|
|
580
|
+
a[3] = a[3].replace(/é/g, 'e');
|
|
568
581
|
}
|
|
569
582
|
|
|
570
583
|
return true;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @hebcal/geo-sqlite v4.
|
|
1
|
+
/*! @hebcal/geo-sqlite v4.3.0 */
|
|
2
2
|
import Database from 'better-sqlite3';
|
|
3
3
|
import { Location, Locale } from '@hebcal/core';
|
|
4
4
|
import '@hebcal/cities';
|
|
@@ -294,33 +294,39 @@ class GeoDb {
|
|
|
294
294
|
/**
|
|
295
295
|
* @private
|
|
296
296
|
* @param {any[]} res
|
|
297
|
+
* @param {boolean} latlong
|
|
297
298
|
* @return {Object[]}
|
|
298
299
|
*/
|
|
299
300
|
|
|
300
301
|
|
|
301
|
-
static zipResultToObj(res) {
|
|
302
|
+
static zipResultToObj(res, latlong = false) {
|
|
302
303
|
const obj = {
|
|
303
304
|
id: String(res.ZipCode),
|
|
304
305
|
value: `${res.CityMixedCase}, ${res.State} ${res.ZipCode}`,
|
|
305
306
|
admin1: res.State,
|
|
306
307
|
asciiname: res.CityMixedCase,
|
|
307
308
|
country: 'United States',
|
|
308
|
-
latitude: res.Latitude,
|
|
309
|
-
longitude: res.Longitude,
|
|
310
|
-
timezone: Location.getUsaTzid(res.State, res.TimeZone, res.DayLightSaving),
|
|
311
309
|
population: res.Population,
|
|
312
310
|
geo: 'zip'
|
|
313
311
|
};
|
|
312
|
+
|
|
313
|
+
if (latlong) {
|
|
314
|
+
obj.latitude = res.Latitude;
|
|
315
|
+
obj.longitude = res.Longitude;
|
|
316
|
+
obj.timezone = Location.getUsaTzid(res.State, res.TimeZone, res.DayLightSaving);
|
|
317
|
+
}
|
|
318
|
+
|
|
314
319
|
return obj;
|
|
315
320
|
}
|
|
316
321
|
/**
|
|
317
322
|
* Generates autocomplete results based on a query string
|
|
318
323
|
* @param {string} qraw
|
|
324
|
+
* @param {boolean} latlong
|
|
319
325
|
* @return {Object[]}
|
|
320
326
|
*/
|
|
321
327
|
|
|
322
328
|
|
|
323
|
-
autoComplete(qraw) {
|
|
329
|
+
autoComplete(qraw, latlong = false) {
|
|
324
330
|
qraw = qraw.trim();
|
|
325
331
|
|
|
326
332
|
if (qraw.length === 0) {
|
|
@@ -335,7 +341,7 @@ class GeoDb {
|
|
|
335
341
|
}
|
|
336
342
|
|
|
337
343
|
const zip5 = qraw.substring(0, 5);
|
|
338
|
-
return this.zipCompStmt.all(zip5 + '%').map(GeoDb.zipResultToObj);
|
|
344
|
+
return this.zipCompStmt.all(zip5 + '%').map(row => GeoDb.zipResultToObj(row, latlong));
|
|
339
345
|
} else {
|
|
340
346
|
if (!this.geonamesCompStmt) {
|
|
341
347
|
this.geonamesCompStmt = this.geonamesDb.prepare(GEONAME_COMPLETE_SQL);
|
|
@@ -350,11 +356,6 @@ class GeoDb {
|
|
|
350
356
|
id: res.geonameid,
|
|
351
357
|
value: Location.geonameCityDescr(res.asciiname, admin1, country),
|
|
352
358
|
asciiname: res.asciiname,
|
|
353
|
-
admin1,
|
|
354
|
-
country,
|
|
355
|
-
latitude: res.latitude,
|
|
356
|
-
longitude: res.longitude,
|
|
357
|
-
timezone: res.timezone,
|
|
358
359
|
population: res.population,
|
|
359
360
|
geo: 'geoname'
|
|
360
361
|
};
|
|
@@ -367,7 +368,12 @@ class GeoDb {
|
|
|
367
368
|
obj.admin1 = admin1;
|
|
368
369
|
}
|
|
369
370
|
|
|
370
|
-
|
|
371
|
+
if (latlong) {
|
|
372
|
+
obj.latitude = res.latitude;
|
|
373
|
+
obj.longitude = res.longitude;
|
|
374
|
+
obj.timezone = res.timezone;
|
|
375
|
+
}
|
|
376
|
+
|
|
371
377
|
return obj;
|
|
372
378
|
});
|
|
373
379
|
|
|
@@ -376,7 +382,7 @@ class GeoDb {
|
|
|
376
382
|
}
|
|
377
383
|
|
|
378
384
|
const zipRows = this.zipFulltextCompStmt.all(`"${qraw}*"`);
|
|
379
|
-
const zipMatches = zipRows.map(GeoDb.zipResultToObj);
|
|
385
|
+
const zipMatches = zipRows.map(row => GeoDb.zipResultToObj(row, latlong));
|
|
380
386
|
const map = new Map();
|
|
381
387
|
|
|
382
388
|
for (const obj of zipMatches) {
|
|
@@ -553,6 +559,13 @@ async function buildGeonamesSqlite(opts) {
|
|
|
553
559
|
} else {
|
|
554
560
|
a[3] = a[3].replace(/‘/g, '\'');
|
|
555
561
|
a[3] = a[3].replace(/’/g, '\'');
|
|
562
|
+
a[3] = a[3].replace(/Ḥ/g, 'Ch');
|
|
563
|
+
a[3] = a[3].replace(/H̱/g, 'Ch');
|
|
564
|
+
a[3] = a[3].replace(/ẖ/g, 'ch');
|
|
565
|
+
a[3] = a[3].replace(/Ẕ/g, 'Tz');
|
|
566
|
+
a[3] = a[3].replace(/ẕ/g, 'tz');
|
|
567
|
+
a[3] = a[3].replace(/ā/g, 'a');
|
|
568
|
+
a[3] = a[3].replace(/é/g, 'e');
|
|
556
569
|
}
|
|
557
570
|
|
|
558
571
|
return true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hebcal/geo-sqlite",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"author": "Michael J. Radwin (https://github.com/mjradwin)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hebcal"
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@hebcal/cities": "^3.1.2",
|
|
32
32
|
"@hebcal/core": "^3.33.3",
|
|
33
33
|
"better-sqlite3": "^7.5.0",
|
|
34
|
-
"pino": "^7.8.
|
|
34
|
+
"pino": "^7.8.1",
|
|
35
35
|
"pino-pretty": "^7.5.3"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
@@ -60,11 +60,11 @@
|
|
|
60
60
|
"@rollup/plugin-commonjs": "^21.0.2",
|
|
61
61
|
"@rollup/plugin-json": "^4.1.0",
|
|
62
62
|
"@rollup/plugin-node-resolve": "^13.1.3",
|
|
63
|
-
"ava": "^4.0
|
|
64
|
-
"eslint": "^8.
|
|
63
|
+
"ava": "^4.1.0",
|
|
64
|
+
"eslint": "^8.11.0",
|
|
65
65
|
"eslint-config-google": "^0.14.0",
|
|
66
66
|
"jsdoc": "^3.6.10",
|
|
67
67
|
"jsdoc-to-markdown": "^7.1.1",
|
|
68
|
-
"rollup": "^2.
|
|
68
|
+
"rollup": "^2.70.0"
|
|
69
69
|
}
|
|
70
70
|
}
|