
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
metropolis-tz
Advanced tools
A lightweight and efficient TypeScript/JavaScript library for managing city timezone information worldwide
A high-performance TypeScript/JavaScript library for managing city timezone information worldwide. Uses optimized data structures and binary search for extremely fast lookups.
npm install metropolis-tz
import CityTimezones from 'metropolis-tz';
const cityTz = new CityTimezones();
// Get timezone for a city
const timezone = cityTz.getTimezone('New York', 'US');
console.log(timezone); // 'America/New_York'
// Search for cities (with typo tolerance)
const cities = cityTz.searchCitiesFuzzy('londun', 2);
// Will find 'London' despite the typo
// Validate city and timezone
const isValidCity = cityTz.isValidCity('Paris', 'FR'); // true
const isValidTz = cityTz.isValidTimezone('Europe/Paris'); // true
// Get time difference
const diff = cityTz.getTimeDifference('New York', 'US', 'London', 'GB');
console.log(cityTz.formatTimeDifference(diff!));
// "behind by 5 hours" (during EDT)
getTimezone(cityName: string, country: string): string | nullGets the IANA timezone identifier for a city.
const timezone = cityTz.getTimezone('Paris', 'FR');
// Returns: 'Europe/Paris'
searchCities(query: string): CityInfo[]Searches for cities by name (case-insensitive, partial match).
const cities = cityTz.searchCities('san');
// Returns: San Francisco, San Diego, San Jose, etc.
searchCitiesFuzzy(query: string, maxDistance: number = 2): CityInfo[]Searches for cities with typo tolerance using Levenshtein distance.
const cities = cityTz.searchCitiesFuzzy('londun', 2);
// Returns: London (despite the typo)
isValidCity(cityName: string, country: string): booleanChecks if a city exists in the database.
const isValid = cityTz.isValidCity('Paris', 'FR'); // true
isValidTimezone(timezone: string): booleanChecks if a timezone is supported.
const isValid = cityTz.isValidTimezone('Europe/Paris'); // true
getTimezoneOffset(timezone: string): number | nullGets the current UTC offset in minutes for a timezone.
const offset = cityTz.getTimezoneOffset('America/Los_Angeles');
// Returns: -420 (7 hours behind UTC during PDT)
getTimeDifference(fromCity: string, fromCountry: string, toCity: string, toCountry: string): number | nullCalculates time difference between cities in minutes.
const diff = cityTz.getTimeDifference('Tokyo', 'JP', 'London', 'GB');
console.log(cityTz.formatTimeDifference(diff!));
// Returns human-readable time difference
convertTime(time: Date, fromCity: string, fromCountry: string, toCity: string, toCountry: string): Date | nullConverts a time from one city's timezone to another's.
const time = new Date('2024-03-15T12:00:00');
const converted = cityTz.convertTime(time, 'New York', 'US', 'Tokyo', 'JP');
findNearestCities(lat: number, lon: number, maxResults: number = 5): CityInfo[]Finds cities closest to given coordinates.
const nearby = cityTz.findNearestCities(51.5074, -0.1278, 3); // Near London
formatCityInfo(city: CityInfo, format: string = '{name}, {country}'): stringFormats city information using a template string.
const city = cityTz.findNearestCities(51.5074, -0.1278, 1)[0];
console.log(cityTz.formatCityInfo(city, '{name}, {country} ({coordinates})'));
// "London, GB (51.5074,-0.1278)"
getAllCities(): CityInfo[]Returns all cities in the database.
getCitiesByTimezone(timezone: string): CityInfo[]Gets all cities in a specific timezone.
getUniqueCountries(): string[]Returns all unique country codes.
getUniqueTimezones(): string[]Returns all unique timezone identifiers.
getCitiesByCountry(country: string): CityInfo[]Returns all cities in a specific country.
interface CityInfo {
name: string; // City name
country: string; // ISO country code (e.g., 'US', 'GB')
timezone: string; // IANA timezone (e.g., 'America/New_York')
latitude: number; // Geographical latitude
longitude: number; // Geographical longitude
}
The library uses optimized data structures and algorithms:
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)This project is licensed under the Mozilla Public License 2.0 - see the LICENSE file for details.
Jace Sleeman
FAQs
A lightweight and efficient TypeScript/JavaScript library for managing city timezone information worldwide
We found that metropolis-tz demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.