@ac-dev/cities-service

中文文档
1.1.1发布于 2022/03/23MITTypeScriptESM + CJS零依赖近 30 天下载 6843

Get the World's cities

原始使用文档
文档目录10 节
  1. Table of contents
  2. Mission
  3. Getting started
  4. Installation
  5. Import
  6. Usage
  7. Contributors
  8. Need help?
  9. License
  10. Sponsor

Countries Service

NPM

Table of contents

  1. Mission
  2. Getting started
  3. Usage
  4. Contributors
  5. Need help
  6. Licence
  7. Sponsor

Mission

  • I've never found any complete library to get all world countries, states, and cities. I want to develop the best one. Of course, contributors are welcome!!
  • I took this data as a starting point.
  • This package is a part of countries-states-cities-service

Getting started

To get started with this library, you need to install it and add it to your project.

Installation

Cities Service is available as an npm package.

# npm
npm install @ac-dev/cities-service

# yarn
yarn add @ac-dev/cities-service

Import

Import single named import as follow:

import { Cities } from '@ac-dev/cities-service'

Usage

The code snippet below shows how to put into action cities-service in some common use cases.

  • Get all cities.
const cities = Cities.getCities()
  • Get all cities by asc sort.
const cities = Cities.getCities({
  sort: {
    mode: 'asc',
  },
})
  • Get all cities by desc sort.
const cities = Cities.getCities({
  sort: {
    mode: 'desc',
  },
})
  • Get all cities by alphabetical sort.
const cities = Cities.getCities({
  sort: {
    mode: 'alphabetical',
    key: 'name',
  },
})
  • Get Italian cities.
const cities = Cities.getCities({
  filters: {
    country_code: 'IT',
  },
})
  • Get Italian and French cities.
const cities = Cities.getCities({
  filters: {
    country_code: ['IT', 'FR'],
  },
})
  • Get Italian Ligurian cities.
const cities = Cities.getCities({
  filters: {
    country_code: 'IT',
    state_code: '42', // Region iso2
  },
})

Contributors

Any contribution is appreciated. You can get started with the steps below:

  1. Fork this repository (learn how to do this here).

  2. Clone the forked repository.

  3. Make your changes and create a pull request (learn how to do this).

  4. I will attend to your pull request and provide some feedback.

Need help?

Ping me on Twitter

License

This repository is licensed under the MIT License.

Sponsor

Don't be shy! 😜

:heart: Sponsor

版本与发布记录

@ac-dev/cities-service 共发布 3 个版本,首次发布于 2022/02/06;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.1.1latest2022/03/234 年前
1.1.02022/03/234 年前
1.0.02022/02/064 年前

关于 @ac-dev/cities-service 的常见问题

@ac-dev/cities-service 是什么?

Get the World's cities

如何安装 @ac-dev/cities-service?

在项目目录运行 npm install @ac-dev/cities-service,或使用 pnpm add / yarn add / bun add。

@ac-dev/cities-service 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ac-dev/cities-service 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@ac-dev/cities-service 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=10。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@ac-dev/cities-service 可以商用吗?

@ac-dev/cities-service 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ac-dev/cities-service 的下载量有多少?

根据 npm 官方下载统计,@ac-dev/cities-service 在 2026/10/05 – 2026/11/03 这 30 天内被下载 6,843 次,日均约 228 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ac-dev/cities-service 还在维护吗?

最新版本 1.1.1 发布于 2022/03/23(4 年前);至今共发布 3 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/02/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。