From 29ab43a26134e48bf458cde7ff070783ea17da35 Mon Sep 17 00:00:00 2001 From: gimy Date: Sat, 7 Oct 2023 10:26:13 +0800 Subject: [PATCH] fix: make recommendMethod work on the browser as well --- package.json | 2 +- pnpm-lock.yaml | 102 +++++++++++++-------------------------- src/MethodRecommender.ts | 8 +-- 3 files changed, 38 insertions(+), 74 deletions(-) diff --git a/package.json b/package.json index 03866cc..16c2b47 100644 --- a/package.json +++ b/package.json @@ -95,8 +95,8 @@ } }, "dependencies": { + "@rapideditor/country-coder": "^5.2.2", "adhan": "^4.4.3", - "country-locator": "^2.1.1", "rxjs": "^7.5.6", "tslog": "^4.4.4" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2c6f457..6d02e6d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,6 +9,7 @@ importers: '@antfu/utils': ^0.5.2 '@npmcli/ci-detect': ^3.0.2 '@observablehq/plot': ^0.6.11 + '@rapideditor/country-coder': ^5.2.2 '@semantic-release/changelog': ^6.0.1 '@semantic-release/git': ^10.0.1 '@types/d3': ^7.4.1 @@ -19,7 +20,6 @@ importers: '@vitest/ui': ^0.23.4 adhan: ^4.4.3 bumpp: ^8.2.1 - country-locator: ^2.1.1 d3: ^7.8.5 eslint: ^8.22.0 eslint-config-prettier: ^8.5.0 @@ -40,8 +40,8 @@ importers: vitest: ^0.22.0 vue: ^3.2.39 dependencies: + '@rapideditor/country-coder': 5.2.2 adhan: 4.4.3 - country-locator: 2.1.1 rxjs: 7.8.0 tslog: 4.4.4 devDependencies: @@ -1117,6 +1117,13 @@ packages: resolution: {integrity: sha512-a5Sab1C4/icpTZVzZc5Ghpz88yQtGOyNqYXcZgOssB2uuAr+wF/MvN6bgtW32q7HHrvBki+BsZ0OuNv6EV3K9g==} dev: true + /@rapideditor/country-coder/5.2.2: + resolution: {integrity: sha512-xGkI+wHX694sFcKKVdy20/uNeHuIiJACnke2vp7LzX22PRPJJv+pcn1OU5nb1urnad275EMfJQR33ayi2hWZOQ==} + engines: {node: '>=16.14.0'} + dependencies: + which-polygon: 2.2.1 + dev: false + /@rollup/plugin-alias/3.1.9_rollup@2.79.1: resolution: {integrity: sha512-QI5fsEvm9bDzt32k39wpOwZhVzRcL5ydcffUHMyLVaVaLeC70I8TJZ17F1z1eMoLu4E/UOcH9BWVkKpIKdrfiw==} engines: {node: '>=8.0.0'} @@ -1328,31 +1335,6 @@ packages: engines: {node: '>= 10'} dev: true - /@turf/boolean-point-in-polygon/6.5.0: - resolution: {integrity: sha512-DtSuVFB26SI+hj0SjrvXowGTUCHlgevPAIsukssW6BG5MlNSBQAo70wpICBNJL6RjukXg8d2eXaAWuD/CqL00A==} - dependencies: - '@turf/helpers': 6.5.0 - '@turf/invariant': 6.5.0 - dev: false - - /@turf/helpers/6.5.0: - resolution: {integrity: sha512-VbI1dV5bLFzohYYdgqwikdMVpe7pJ9X3E+dlr425wa2/sMJqYDhTO++ec38/pcPvPE6oD9WEEeU3Xu3gza+VPw==} - dev: false - - /@turf/intersect/6.5.0: - resolution: {integrity: sha512-2legGJeKrfFkzntcd4GouPugoqPUjexPZnOvfez+3SfIMrHvulw8qV8u7pfVyn2Yqs53yoVCEjS5sEpvQ5YRQg==} - dependencies: - '@turf/helpers': 6.5.0 - '@turf/invariant': 6.5.0 - polygon-clipping: 0.15.3 - dev: false - - /@turf/invariant/6.5.0: - resolution: {integrity: sha512-Wv8PRNCtPD31UVbdJE/KVAWKe7l6US+lJItRR/HOEW3eh+U/JwRCSUl/KZ7bmjM/C+zLNoreM2TU6OoLACs4eg==} - dependencies: - '@turf/helpers': 6.5.0 - dev: false - /@types/chai-subset/1.3.3: resolution: {integrity: sha512-frBecisrNGz+F4T6bcc+NLeolfiojh5FxW2klu669+8BARtyQv2C/GkNW6FUodVe4BroGMP/wER/YDGc7rEllw==} dependencies: @@ -2528,16 +2510,6 @@ packages: yaml: 1.10.2 dev: true - /country-locator/2.1.1: - resolution: {integrity: sha512-ad+CoZPkoSWn8syw5gfigelB09LEsMiw/fNLtC/8JzXz1b5QMyCCG+yQFsqw0jpPyeXcvTb0ZT6QNnSYOTjhuw==} - dependencies: - '@turf/boolean-point-in-polygon': 6.5.0 - '@turf/helpers': 6.5.0 - '@turf/intersect': 6.5.0 - jsonfile: 6.1.0 - path: 0.12.7 - dev: false - /cross-spawn/7.0.3: resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} engines: {node: '>= 8'} @@ -4234,6 +4206,7 @@ packages: /graceful-fs/4.2.11: resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==} + dev: true optional: true /grapheme-splitter/1.0.4: @@ -4398,10 +4371,6 @@ packages: wrappy: 1.0.2 dev: true - /inherits/2.0.3: - resolution: {integrity: sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw==} - dev: false - /inherits/2.0.4: resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} dev: true @@ -4777,6 +4746,7 @@ packages: universalify: 2.0.0 optionalDependencies: graceful-fs: 4.2.11 + dev: true /jsonparse/1.3.1: resolution: {integrity: sha512-POQXvpdL69+CluYsillJ7SUhKvytYjW9vG/GKpnf+xP8UWgYEM/RaMzHHofbALDiKbbP1W8UEYmgGl39WkPZsg==} @@ -4814,6 +4784,10 @@ packages: type-check: 0.4.0 dev: true + /lineclip/1.1.5: + resolution: {integrity: sha512-KlA/wRSjpKl7tS9iRUdlG72oQ7qZ1IlVbVgHwoO10TBR/4gQ86uhKow6nlzMAJJhjCWKto8OeoAzzIzKSmN25A==} + dev: false + /lines-and-columns/1.2.4: resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==} dev: true @@ -5554,13 +5528,6 @@ packages: engines: {node: '>=8'} dev: true - /path/0.12.7: - resolution: {integrity: sha512-aXXC6s+1w7otVF9UletFkFcDsJeO7lSZBPUQhtb5O0xJe8LtYhj/GxldoL09bBj9+ZmE2hNoHqQSFMN5fikh4Q==} - dependencies: - process: 0.11.10 - util: 0.10.4 - dev: false - /pathe/0.2.0: resolution: {integrity: sha512-sTitTPYnn23esFR3RlqYBWn4c45WGeLcsKzQiUpXJAyfcWkolvlYpV8FLo7JishK946oQwMFUCHXQ9AjGPKExw==} dev: true @@ -5626,12 +5593,6 @@ packages: hasBin: true dev: true - /polygon-clipping/0.15.3: - resolution: {integrity: sha512-ho0Xx5DLkgxRx/+n4O74XyJ67DcyN3Tu9bGYKsnTukGAW6ssnuak6Mwcyb1wHy9MZc9xsUWqIoiazkZB5weECg==} - dependencies: - splaytree: 3.1.2 - dev: false - /postcss-selector-parser/6.0.11: resolution: {integrity: sha512-zbARubNdogI9j7WY4nQJBiNqQf3sLS3wCP4WfOidu+p28LofJqDH1tcXypGrcmMHhDk2t9wGhCsYe/+szLTy1g==} engines: {node: '>=4'} @@ -5682,11 +5643,6 @@ packages: resolution: {integrity: sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==} dev: true - /process/0.11.10: - resolution: {integrity: sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==} - engines: {node: '>= 0.6.0'} - dev: false - /prompts/2.4.2: resolution: {integrity: sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==} engines: {node: '>= 6'} @@ -5722,6 +5678,16 @@ packages: engines: {node: '>=8'} dev: true + /quickselect/1.1.1: + resolution: {integrity: sha512-qN0Gqdw4c4KGPsBOQafj6yj/PA6c/L63f6CaZ/DCF/xF4Esu3jVmKLUDYxghFx8Kb/O7y9tI7x2RjTSXwdK1iQ==} + dev: false + + /rbush/2.0.2: + resolution: {integrity: sha512-XBOuALcTm+O/H8G90b6pzu6nX6v2zCKiFG4BJho8a+bY6AER6t8uQUZdi5bomQc0AprCWhEGa7ncAbbRap0bRA==} + dependencies: + quickselect: 1.1.1 + dev: false + /rc/1.2.8: resolution: {integrity: sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==} hasBin: true @@ -6152,10 +6118,6 @@ packages: resolution: {integrity: sha512-rr+VVSXtRhO4OHbXUiAF7xW3Bo9DuuF6C5jH+q/x15j2jniycgKbxU09Hr0WqlSLUs4i4ltHGXqTe7VHclYWyA==} dev: true - /splaytree/3.1.2: - resolution: {integrity: sha512-4OM2BJgC5UzrhVnnJA4BkHKGtjXNzzUfpQjCO8I05xYPsfS/VuQDwjCGGMi8rYQilHEV4j8NBqTFbls/PZEE7A==} - dev: false - /split/1.0.1: resolution: {integrity: sha512-mTyOoPbrivtXnwnIxZRFYRrPNtEFKlpB2fvjSnCQUiAA6qAZzqwna5envK4uk6OIeP17CsdF3rSBGYVBsU0Tkg==} dependencies: @@ -6575,6 +6537,7 @@ packages: /universalify/2.0.0: resolution: {integrity: sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==} engines: {node: '>= 10.0.0'} + dev: true /untyped/0.5.0: resolution: {integrity: sha512-2Sre5A1a7G61bjaAKZnSFaVgbJMwwbbYQpJFH69hAYcDfN7kIaktlSphS02XJilz4+/jR1tsJ5MHo1oMoCezxg==} @@ -6612,12 +6575,6 @@ packages: resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} dev: true - /util/0.10.4: - resolution: {integrity: sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A==} - dependencies: - inherits: 2.0.3 - dev: false - /validate-npm-package-license/3.0.4: resolution: {integrity: sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==} dependencies: @@ -6912,6 +6869,13 @@ packages: is-symbol: 1.0.4 dev: true + /which-polygon/2.2.1: + resolution: {integrity: sha512-RlpWbqz12OMT0r2lEHk7IUPXz0hb1L/ZZsGushB2P2qxuBu1aq1+bcTfsLtfoRBYHsED6ruBMiwFaidvXZfQVw==} + dependencies: + lineclip: 1.1.5 + rbush: 2.0.2 + dev: false + /which/2.0.2: resolution: {integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==} engines: {node: '>= 8'} diff --git a/src/MethodRecommender.ts b/src/MethodRecommender.ts index d51dd42..ca84320 100644 --- a/src/MethodRecommender.ts +++ b/src/MethodRecommender.ts @@ -1,9 +1,9 @@ -import { findCountryByCoordinate } from 'country-locator' +import { iso1A3Code } from '@rapideditor/country-coder' import { CountryMethods } from './data/methods' import type { Methods } from './types/Methods' import type { CoordinatesObject } from './types/Coordinates' -export function recommendMethod({ latitude, longitude }: CoordinatesObject): Methods[] | undefined { - const countryInfo = findCountryByCoordinate(latitude, longitude) - return countryInfo?.code ? (CountryMethods as Record)[countryInfo?.code] : undefined +export function recommendMethod({ longitude, latitude }: CoordinatesObject): Methods[] | undefined { + const countryCode = iso1A3Code([longitude, latitude]) + return countryCode ? (CountryMethods as Record)[countryCode] : undefined }