worldtimeapi-lib
v0.2.0
Published
Basic library for calling http://worldtimeapi.com programatically.
Downloads
7
Maintainers
Readme
world time API lib
This simple library exposes one function getTimezone
, which will take care
of everything the underlying API allows.
Preconditions
- have Node.js LTS with
npm
installed. Library enforces using Node.js version 20.x or higher, due to internal usage offetch
function.
Usage
Get all timezones' areas
import { getTimezone } from "worldtimeapi-lib";
const [data, status] = await getTimezone();
if (status) {
console.log(JSON.stringify(data));
}
Get specific area with its locations
const [data, status] = await getTimezone({ timezone: "Europe" });
Get specific location data of the area timezone
const [data, status] = await getTimezone({ timezone: "Europe/Prague" });
Get data for IP address
IP address is not provided
import { getIpAddress } from "worldtimeapi-lib";
const [data, status] = await getIpAddress();
if (status) {
console.log(JSON.stringify(data));
}
IP address explicitly provided
const [data, status] = await getIpAddress({ ip: "8.8.8.8" });