承接 annexare/countries-list 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

annexare/countries-list

Composer 安装命令:

composer require annexare/countries-list

包简介

Continents & countries: ISO 3166-1 alpha-2 code, name, ISO 639-1 languages, capital, ISO 4217 currencies (symbols & numeric codes), native name, phone. JSON, CSV and SQL.

README 文档

README

Monthly Downloads NPM Packagist CI: JS CI: PHP Twitter

Continents & countries: ISO 3166-1 alpha-2 code (with alpha-2 to alpha-3 set), name, ISO 639-1 languages, capital, ISO 4217 currencies (with symbols & numeric codes), native name, calling codes. Lists are available in JSON, CSV and SQL formats. Also, contains separate JSON files with additional country Emoji flags data.

Version 3.0: Breaking changes

Version 3 comes with some data structure changes. It was completely reworked under the hood with TypeScript, ESM exports and a Bun workspaces monorepo structure.

Everything is strongly typed so you can easily use data with auto-complete in your IDE.

Note: If your projects depend on the old structure, carefully specify required versions in your dependencies.

Installation

Package is available via:

  • Bun bun add countries-list
  • NPM npm install countries-list
  • Composer / Packagist composer require annexare/countries-list

Usage (version 3.x)

Module exports continents, countries, languages and utility functions.

// Interfaces and types
import type {
  ICountry,
  ICountryData,
  ILanguage,
  TContinentCode,
  TCountryCode,
  TLanguageCode,
} from 'countries-list'

// Main data and utils
import { continents, countries, languages } from 'countries-list'
// Utils
import { getCountryCode, getCountryData, getCountryDataList, getEmojiFlag } from 'countries-list'

// Minimal data in JSON
import countries2to3 from 'countries-list/minimal/countries.2to3.min.json'
import countries3to2 from 'countries-list/minimal/countries.3to2.min.json'
import languageNames from 'countries-list/minimal/languages.native.min'

getCountryCode('Ukraine') // 'UA'
getCountryCode('Україна') // 'UA'
getCountryData('UA') // ICountryData

Built files are in the dist directory of this repository, and packages/countries directory contains source data.

Note: JS build contains ES modules, CommonJS and IIFE (for now)

  • CJS cjs/index.js
  • ESM mjs/index.js
  • IIFE index.iife.js

Currencies (ISO 4217)

Full ISO 4217 currency data — English and native name, UI symbol, native symbol, 3-digit numeric code and minor-unit decimals — is an opt-in import via the countries-list/currencies subpath, so it does not affect the main bundle size:

import type { ICurrency, ICurrencyData, TCurrencyCode } from 'countries-list'
import { currencies, getCurrency, getCurrencyByNumeric } from 'countries-list/currencies'

// Minimal maps (code -> value)
import currencySymbols from 'countries-list/minimal/currencies.symbol.min.json'
import currencyNumbers from 'countries-list/minimal/currencies.numeric.min.json'

currencies.UAH // { name: 'Ukrainian Hryvnia', native: 'українська гривня', symbol: '₴', symbolNative: '₴', numeric: '980', decimals: 2 }
getCurrency('JPY') // ICurrencyData: { code: 'JPY', name: 'Japanese Yen', symbol: '¥', decimals: 0, ... }
getCurrencyByNumeric('840') // ICurrencyData for USD — numeric lookup, e.g. for banking

The dataset covers the complete active ISO 4217 list plus a few withdrawn codes still referenced by country data (e.g. ANG, flagged with withdrawn: true). symbol falls back to the ISO code where a currency has no distinct Latin glyph (e.g. CHF, KWD); the local glyph is then in symbolNative. Symbols come from Unicode CLDR (ISO 4217 itself defines no symbols).

Data structure examples

const continents = {
  AF: 'Africa',
  AN: 'Antarctica',
  AS: 'Asia',
  EU: 'Europe',
  NA: 'North America',
  OC: 'Oceania',
  SA: 'South America',
}

const countries = {
  // ...
  UA: {
    name: 'Ukraine',
    native: 'Україна',
    phone: [380],
    continent: 'EU',
    capital: 'Kyiv',
    currency: ['UAH'],
    languages: ['uk'],
  },
  // ...
}

const languages = {
  // ...
  uk: {
    name: 'Ukrainian',
    native: 'Українська',
  },
  ur: {
    name: 'Urdu',
    native: 'اردو',
    rtl: 1,
  },
  // ...
}

const currencies = {
  // ...
  UAH: {
    name: 'Ukrainian Hryvnia',
    native: 'українська гривня',
    symbol: '₴',
    symbolNative: '₴',
    numeric: '980',
    decimals: 2,
  },
  // ...
}

Contributing to this repository

Everything is generated from strongly typed files in packages/countries/src, including SQL file.

Everything in dist is generated, so please make data related changes ONLY to files from packages/countries, commit them. Use bun run build / bun run test to build/test generated files.

The currencies dataset (packages/countries/src/data/currencies.ts) is generated from the official ISO 4217 list and Unicode CLDR via packages/scripts/generateCurrencies.ts. Refresh it with cd packages/scripts && bun run generate:currencies (requires network) when ISO 4217 publishes an update, rather than editing the data by hand.

Credits

Prepared by Annexare Studio from different public sources. Feel free to use it as you need in your apps or send updates into this public repository. It's under MIT license.

annexare/countries-list 适用场景与选型建议

annexare/countries-list 是一款 基于 TypeScript 开发的 Composer 扩展包,目前已累计 263.28k 次下载、GitHub Stars 达 1.32k, 最近一次更新时间为 2016 年 01 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「sql」 「json」 「data」 「csv」 「currency」 「emoji」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 annexare/countries-list 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 annexare/countries-list 我们能提供哪些服务?
定制开发 / 二次开发

基于 annexare/countries-list 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 263.28k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1324
  • 点击次数: 32
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 1323
  • Watchers: 17
  • Forks: 425
  • 开发语言: TypeScript

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-01-09