nation-zone
v1.1.6
Published
From BANDENG developer team.
Downloads
558
Readme
Nation Zone
Welcome to the Nation Zone project. This project is designed to convert time zones and currencies for different countries and regions.
TypeScript Support
This package includes full TypeScript support with type definitions. Simply install the package and TypeScript will automatically recognize the types.
Module Compatibility
This package supports both CommonJS and ES6 module imports:
CommonJS (Node.js):
const {MAP_NATIONS_CURRENCY, getNationTimeNow} = require('nation-zone')ES6 Modules (Modern Frontend):
import {MAP_NATIONS_CURRENCY, getNationTimeNow} from 'nation-zone'Note:
- This module is completely implemented based on UTC, and it does not support switching between winter time and daylight saving time.
- Follow the ISO8601 standard.
- Comprehensive country/region coverage with 118 countries and regions supported.
Features
Comprehensive Country Coverage: Support for 118 countries and regions across Europe (42 countries), Americas (34 countries), Asia, Africa, and Oceania.
Time Zone Matching: Match the time zone corresponding to the country/region.
Currency Matching: Match the currency corresponding to the country/region, including 85 currency units.
Time Zone Conversion: Converts the local time zone to the time zone of the specified country/region.
Timestamp Conversion: Converts a time string to a timestamp in the time zone of the specified country/region.
Time Period Splitting: Split timestamp paragraphs by day, week and month based on the time zone of the country/region.
Recent Updates
v1.1.6
- Senegal: Added
SEN(ISO 3166-1 alpha-3) with currencyXOF(ISO 4217), charge unitXOF-XOF, symbolCFA, and UTC+0 timezone - Sri Lanka: Added
LKA(ISO 3166-1 alpha-3) with currencyLKR(ISO 4217), charge unitLKR-CENT, symbolRs, and UTC+5.5 timezone
Installation
To install the necessary dependencies, run the following command:
npm install nation-zoneUsage
Basic Examples
Get country currency:
import {MAP_NATIONS_CURRENCY} from 'nation-zone'
const chinaCurrency = MAP_NATIONS_CURRENCY.get('CHN') // 'CNY'
const usaCurrency = MAP_NATIONS_CURRENCY.get('USA') // 'USD'Get currency symbol:
import {MAP_NATIONS_CURRENCY_SYMBOL} from 'nation-zone'
const chinaSymbol = MAP_NATIONS_CURRENCY_SYMBOL.get('CHN') // '¥'
const usaSymbol = MAP_NATIONS_CURRENCY_SYMBOL.get('USA') // '$'Get country time zone:
import {MAP_TIME_ZONES} from 'nation-zone'
const chinaTimezone = MAP_TIME_ZONES.get('CHN') // [8]
const usaTimezone = MAP_TIME_ZONES.get('USA') // [-5]Convert timestamp to country time:
import {getNationTimeNow} from 'nation-zone'
const chinaTime = getNationTimeNow('CHN') // "2024-01-15 14:30:25.123"
const usaTime = getNationTimeNow('USA') // "2024-01-15 01:30:25.123"Parse time string to timestamp:
import {parseNationTimestamp} from 'nation-zone'
const timestamp = parseNationTimestamp('CHN', '2024-01-15 14:30:25')
// Returns timestamp in milliseconds (UTC)Have fun exploring global time zones and currencies!
License
This project is licensed under the MIT License.
Contact
For any questions or feedback, please contact [email protected].
Nation Zone
欢迎使用 Nation Zone。本项目用于不同国家/地区的时区与货币转换。
TypeScript 支持
本包提供完整的 TypeScript 类型定义,安装后 TypeScript 可自动识别类型。
模块兼容性
同时支持 CommonJS 与 ES Module 两种导入方式:
CommonJS(Node.js):
const {MAP_NATIONS_CURRENCY, getNationTimeNow} = require('nation-zone')ES Module(现代前端):
import {MAP_NATIONS_CURRENCY, getNationTimeNow} from 'nation-zone'说明
- 本模块完全基于 UTC 实现,不支持冬令时/夏令时切换。
- 时间格式遵循 ISO8601 标准。
- 覆盖 118 个国家/地区。
功能特性
广泛的国家/地区覆盖:支持欧洲(42 国)、美洲(34 国)、亚洲、非洲及大洋洲,共 118 个国家/地区。
时区匹配:匹配国家/地区对应的 UTC 时区。
货币匹配:匹配国家/地区对应的 ISO 4217 货币代码,含 85 种货币。
时区转换:将本地时区转换到指定国家/地区的时区。
时间戳转换:将时间字符串转换为指定国家/地区时区下的 UTC 毫秒时间戳。
时间段拆分:按国家/地区时区,以天、周、月为单位拆分时间戳区间。
最近更新
v1.1.6
- 塞内加尔:新增
SEN(ISO 3166-1 alpha-3),货币XOF(ISO 4217),计价单位XOF-XOF,符号CFA,时区 UTC+0 - 斯里兰卡:新增
LKA(ISO 3166-1 alpha-3),货币LKR(ISO 4217),计价单位LKR-CENT,符号Rs,时区 UTC+5.5
安装
npm install nation-zone用法
基础示例
获取国家/地区货币:
import {MAP_NATIONS_CURRENCY} from 'nation-zone'
const chinaCurrency = MAP_NATIONS_CURRENCY.get('CHN') // 'CNY'
const usaCurrency = MAP_NATIONS_CURRENCY.get('USA') // 'USD'获取货币符号:
import {MAP_NATIONS_CURRENCY_SYMBOL} from 'nation-zone'
const chinaSymbol = MAP_NATIONS_CURRENCY_SYMBOL.get('CHN') // '¥'
const usaSymbol = MAP_NATIONS_CURRENCY_SYMBOL.get('USA') // '$'获取国家/地区时区:
import {MAP_TIME_ZONES} from 'nation-zone'
const chinaTimezone = MAP_TIME_ZONES.get('CHN') // [8]
const usaTimezone = MAP_TIME_ZONES.get('USA') // [-5]将时间戳转换为指定国家/地区时间:
import {getNationTimeNow} from 'nation-zone'
const chinaTime = getNationTimeNow('CHN') // "2024-01-15 14:30:25.123"
const usaTime = getNationTimeNow('USA') // "2024-01-15 01:30:25.123"将时间字符串解析为时间戳:
import {parseNationTimestamp} from 'nation-zone'
const timestamp = parseNationTimestamp('CHN', '2024-01-15 14:30:25')
// 返回 UTC 毫秒时间戳祝使用愉快!
许可证
本项目采用 MIT License。
联系方式
如有问题或建议,请联系 [email protected]。
