@hebcal/geo-sqlite 5.7.3 → 5.8.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.
Files changed (2) hide show
  1. package/dist/index.js +16 -13
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @hebcal/geo-sqlite v5.7.2 */
1
+ /*! @hebcal/geo-sqlite v5.8.0 */
2
2
  import Database from 'better-sqlite3';
3
3
  import QuickLRU from 'quick-lru';
4
4
  import { Location, Locale } from '@hebcal/core';
@@ -511,7 +511,7 @@ function munge(s) {
511
511
  }
512
512
 
513
513
  // DO NOT EDIT THIS AUTO-GENERATED FILE!
514
- const version = '5.7.2';
514
+ const version = '5.8.0';
515
515
 
516
516
  const GEONAME_SQL = `SELECT
517
517
  g.name as name,
@@ -635,19 +635,22 @@ class GeoDb {
635
635
  * @param {any} logger
636
636
  * @param {string} zipsFilename
637
637
  * @param {string} geonamesFilename
638
+ * @param {any} options
638
639
  */
639
- constructor(logger, zipsFilename, geonamesFilename) {
640
+ constructor(logger, zipsFilename, geonamesFilename, options) {
640
641
  this.logger = logger;
641
642
  if (logger) logger.info(`GeoDb: opening ${zipsFilename}...`);
642
643
  this.zipsDb = new Database(zipsFilename, {fileMustExist: true});
643
644
  if (logger) logger.info(`GeoDb: opening ${geonamesFilename}...`);
644
645
  this.geonamesDb = new Database(geonamesFilename, {fileMustExist: true});
645
646
  this.zipStmt = this.zipsDb.prepare(ZIPCODE_SQL);
647
+ const zipsCacheSize = options?.zipsCacheSize || 150;
646
648
  /** @type {Map<string, Location>} */
647
- this.zipCache = new QuickLRU({maxSize: 150});
649
+ this.zipCache = new QuickLRU({maxSize: zipsCacheSize});
648
650
  this.geonamesStmt = this.geonamesDb.prepare(GEONAME_SQL);
651
+ const geonamesCacheSize = options?.geonamesCacheSize || 750;
649
652
  /** @type {Map<number, Location>} */
650
- this.geonamesCache = new QuickLRU({maxSize: 750});
653
+ this.geonamesCache = new QuickLRU({maxSize: geonamesCacheSize});
651
654
  /** @type {Map<string, number>} */
652
655
  this.legacyCities = new Map();
653
656
  for (const [name, id] of Object.entries(city2geonameid)) {
@@ -690,7 +693,7 @@ class GeoDb {
690
693
  lookupZip(zip) {
691
694
  const zip5 = zip.trim().substring(0, 5);
692
695
  const found = this.zipCache.get(zip5);
693
- if (typeof found !== 'undefined') return found;
696
+ if (found !== undefined) return found;
694
697
  const result = this.zipStmt.get(zip5);
695
698
  if (!result) {
696
699
  if (this.logger) this.logger.warn(`GeoDb: unknown zipcode=${zip5}`);
@@ -735,7 +738,7 @@ class GeoDb {
735
738
  geonameid = 293397;
736
739
  }
737
740
  const found = this.geonamesCache.get(geonameid);
738
- if (typeof found !== 'undefined') return found;
741
+ if (found !== undefined) return found;
739
742
  const result = this.geonamesStmt.get(geonameid);
740
743
  if (!result) {
741
744
  if (this.logger) this.logger.warn(`GeoDb: unknown geonameid=${geonameid}`);
@@ -769,10 +772,10 @@ class GeoDb {
769
772
  if (countryName === 'United States') countryName = 'USA';
770
773
  if (countryName === 'United Kingdom') countryName = 'UK';
771
774
  let cityDescr = cityName;
772
- if (countryName !== 'Israel' && admin1 && admin1.indexOf(cityName) !== 0) {
775
+ if (countryName !== 'Israel' && admin1 && !admin1.includes(cityName)) {
773
776
  const tlitCityName = transliterate(cityName);
774
777
  const tlitAdmin1 = transliterate(admin1);
775
- if (tlitAdmin1.indexOf(tlitCityName) != 0) {
778
+ if (!tlitAdmin1.includes(tlitCityName)) {
776
779
  cityDescr += ', ' + admin1;
777
780
  }
778
781
  }
@@ -796,7 +799,7 @@ class GeoDb {
796
799
  const location = new Location(
797
800
  result.latitude,
798
801
  result.longitude,
799
- result.cc == 'IL',
802
+ result.cc === 'IL',
800
803
  result.timezone,
801
804
  cityDescr,
802
805
  result.cc,
@@ -809,7 +812,7 @@ class GeoDb {
809
812
  if (admin1) {
810
813
  location.admin1 = admin1;
811
814
  }
812
- if (result.cc == 'IL' && admin1.startsWith('Jerusalem') && result.name.startsWith('Jerualem')) {
815
+ if (result.cc === 'IL' && admin1.startsWith('Jerusalem') && result.name.startsWith('Jerualem')) {
813
816
  location.jersualem = true;
814
817
  }
815
818
  if (result.population) {
@@ -884,7 +887,7 @@ class GeoDb {
884
887
  if (!this.geonamesCompStmt) {
885
888
  this.geonamesCompStmt = this.geonamesDb.prepare(GEONAME_COMPLETE_SQL);
886
889
  }
887
- qraw = qraw.replace(/"/g, '""');
890
+ qraw = qraw.replaceAll('"', '""');
888
891
  const geoRows0 = this.geonamesCompStmt.all(`{longname} : "${qraw}" *`);
889
892
  const ids = new Set();
890
893
  const geoRows = [];
@@ -934,7 +937,7 @@ class GeoDb {
934
937
  const admin1 = res.admin || loc.admin1 || '';
935
938
  const obj = {
936
939
  id: res.geonameid,
937
- value: res.longname,
940
+ value: loc.getName(),
938
941
  admin1,
939
942
  country,
940
943
  cc,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hebcal/geo-sqlite",
3
- "version": "5.7.3",
3
+ "version": "5.8.0",
4
4
  "author": "Michael J. Radwin (https://github.com/mjradwin)",
5
5
  "keywords": [
6
6
  "hebcal"
@@ -60,16 +60,16 @@
60
60
  },
61
61
  "license": "BSD-2-Clause",
62
62
  "devDependencies": {
63
- "@eslint/js": "^9.39.2",
63
+ "@eslint/js": "^10.0.1",
64
64
  "@rollup/plugin-json": "^6.1.0",
65
65
  "@rollup/plugin-node-resolve": "^16.0.3",
66
66
  "ava": "^6.4.1",
67
- "eslint": "^9.39.2",
67
+ "eslint": "^10.0.1",
68
68
  "eslint-config-google": "^0.14.0",
69
- "eslint-plugin-n": "^17.23.2",
69
+ "eslint-plugin-n": "^17.24.0",
70
70
  "globals": "^17.3.0",
71
71
  "jsdoc": "^4.0.5",
72
72
  "jsdoc-to-markdown": "^9.1.3",
73
- "rollup": "^4.57.1"
73
+ "rollup": "^4.59.0"
74
74
  }
75
75
  }