@swiftlyme/locationbycsc
v0.0.4
Published
An incredibly fast O(1) location finder for Countries, States, Cities, Regions, and Subregions.
Maintainers
Readme
Fast Location Finder
A high-performance O(1) lookup tool for World Countries, States, Cities, Regions, and Subregions.
Installation
npm install @swiftlyme/locationbycsc@latestUsage
const { getLocationDetails, getAllCountries } = require('@swiftlyme/locationbycsc');
// 1. Basic Usage (Accessing the first result)
const results = getLocationDetails("Rohtak");
if (results.length > 0) {
const location = results[0];
console.log(`Found: ${location.data.name} (${location.type})`);
// Output: Found: Rohtak (City)
}
// 2. Handling Collisions (e.g. "Lucknow" exists in India and Australia)
const multiple = getLocationDetails("Lucknow");
console.log(`Found ${multiple.length} locations:`);
multiple.forEach(loc => {
if (loc.type === 'City') {
console.log(` - City in ${loc.parent_country.name}`);
}
});
// Output:
// - City in India
// - City in Australia
const countries = getAllCountries();
console.log(`Total countries: ${countries.length}`);
// Preview first few
countries.slice(0, 5).forEach((country, index) => {
console.log(`${index + 1}. ${country.name} (ID: ${country.id})`);
});
