pmj-static-data
Advanced tools
Comparing version 1.0.4 to 1.0.6
@@ -10,2 +10,7 @@ "use strict"; | ||
const phone_numbers_1 = require("./data/phone-numbers"); | ||
function countMatches(searchTerm, text) { | ||
const regex = new RegExp(searchTerm, "gi"); | ||
const matches = text.match(regex); | ||
return matches ? matches.length : 0; | ||
} | ||
function GetAllCountriesPhoneCodes() { | ||
@@ -79,8 +84,8 @@ let data = []; | ||
return { airports: airports.sort((a, b) => { | ||
const aMatchCount = a?.iata_code?.toLowerCase() === query?.toLowerCase() || a?.city_name?.toLowerCase() === query?.toLowerCase(); | ||
const bMatchCount = b?.iata_code?.toLowerCase() === query?.toLowerCase() || b?.city_name?.toLowerCase() === query?.toLowerCase(); | ||
if (bMatchCount) { | ||
const aMatchCount = countMatches(query, a); | ||
const bMatchCount = countMatches(query, b); | ||
if (aMatchCount > bMatchCount) { | ||
return -1; | ||
} | ||
else if (aMatchCount) { | ||
else if (aMatchCount < bMatchCount) { | ||
return 1; | ||
@@ -92,8 +97,8 @@ } | ||
}).slice(0, limit || 10), cities: cities.sort((a, b) => { | ||
const aMatchCount = a?.iata_code?.toLowerCase() === query?.toLowerCase() || a?.city_name?.toLowerCase() === query?.toLowerCase(); | ||
const bMatchCount = b?.iata_code?.toLowerCase() === query?.toLowerCase() || b?.city_name?.toLowerCase() === query?.toLowerCase(); | ||
if (bMatchCount) { | ||
const aMatchCount = countMatches(query, a); | ||
const bMatchCount = countMatches(query, b); | ||
if (aMatchCount > bMatchCount) { | ||
return -1; | ||
} | ||
else if (aMatchCount) { | ||
else if (aMatchCount < bMatchCount) { | ||
return 1; | ||
@@ -216,8 +221,8 @@ } | ||
return cities.sort((a, b) => { | ||
const aMatchCount = a?.iata_code?.toLowerCase() === query?.toLowerCase() || a?.city_name?.toLowerCase() === query?.toLowerCase(); | ||
const bMatchCount = b?.iata_code?.toLowerCase() === query?.toLowerCase() || b?.city_name?.toLowerCase() === query?.toLowerCase(); | ||
if (bMatchCount) { | ||
const aMatchCount = countMatches(query, a); | ||
const bMatchCount = countMatches(query, b); | ||
if (aMatchCount > bMatchCount) { | ||
return -1; | ||
} | ||
else if (aMatchCount) { | ||
else if (aMatchCount < bMatchCount) { | ||
return 1; | ||
@@ -224,0 +229,0 @@ } |
{ | ||
"name": "pmj-static-data", | ||
"version": "1.0.4", | ||
"version": "1.0.6", | ||
"description": "Search Airports, Cities, Countries and many other data in Plan My Journey DATABASE.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
Sorry, the diff of this file is not supported yet
266150
19076525