@devicefarmer/stf-device-db

中文文档
2.0.1发布于 2026/11/07(CC-BY-SA-4.0 AND Apache-2.0)TypeScriptCommonJS零依赖构建来源已验证近 30 天下载 3784

A smartphone/device database for STF.

原始使用文档
文档目录13 节
  1. Data Pipeline & Sources
  2. Coverage
  3. Requirements
  4. Building & Testing
  5. Releasing
  6. Usage
  7. find(properties)
  8. sample() & brandsMatch(a, b)
  9. generateDeviceSvg(params) & getDeviceSvgDataUri(params)
  10. Migrating from v1.x to v2.0
  11. Contributing
  12. License
  13. Google Play device identifiers

@devicefarmer/stf-device-db

@devicefarmer/stf-device-db is an open-data smartphone, tablet, and wearable database with deterministic dynamic SVG generation for DeviceFarmer STF.

Data Pipeline & Sources

The database (dist/devices.json) is generated by scripts/build-db.mjs with Node.js's built-in fetch and no native dependencies:

  1. Google Play Supported Devices (supported_devices.csv): retail brand, marketing name, device codename and model. Google publishes the list without a stated license, and only these factual identifiers are taken from it.
  2. LineageOS Wiki (LineageOS/lineage_wiki): hardware specifications (release, soc, cpu_cores, cpu_freq, ram, storage), read from the repository tarball. Licensed under CC-BY-SA-3.0.
  3. Wikidata SPARQL (query.wikidata.org): publication dates (P577) of smartphone and tablet models (wd:Q19723451, wd:Q17517, wd:Q155972). Dedicated to the public domain under CC0.

Coverage

Every model in the Google Play list has a brand and a marketing name, about 45,000 models in all. Hardware specifications come only from LineageOS, so only about 1,400 models (3%), mostly phones LineageOS supports, have cpu and memory, and about 1,450 have a date. For everything else these fields are null; STF fills them from the connected device.

The data is rebuilt monthly by the Update device database workflow, which opens a pull request when the sources change.

Requirements

Building & Testing

To rebuild dist/devices.json from the upstream sources and verify the database:

npm install
npm run build
npm test

Releasing

  1. Run the Prepare release workflow with the new version. It bumps package.json, updates CHANGELOG.md and pushes a release/v<version> branch.
  2. Open a pull request for that branch, label it ignore-for-release and merge it once the checks pass.
  3. Run the Release workflow with the same version. It tags the release, creates the GitHub release and publishes to npm through trusted publishing, with no npm token.

Usage

Install via NPM:

npm install --save @devicefarmer/stf-device-db

find(properties)

Query device metadata by model (primary, case-insensitive), name (codename fallback / disambiguator), and optional brand / manufacturer / platform guards:

const db = require('@devicefarmer/stf-device-db')

const data = db.find({
  model: 'Nexus 5',
  name: 'hammerhead',
  manufacturer: 'LGE'
})

data returns:

{
  name: { id: 'Nexus 5', long: 'LGE Nexus 5' },
  brand: 'LGE',
  marketName: 'Nexus 5',
  date: '2013-10-31',
  cpu: {
    name: 'Qualcomm MSM8974 Snapdragon 800',
    cores: 4,
    freq: 2.26
  },
  memory: {
    ram: 2048, // MB
    rom: 16    // GB
  },
  image: 'Nexus_5.svg'
}

If neither model nor name matches an entry in dist/devices.json (or platform is non-Android, or brand/manufacturer belongs to a conflicting OEM), find() returns null.

sample() & brandsMatch(a, b)

  • db.sample() returns a random device record ({ model, name, brand, marketName, date, cpu, memory, image }) from dist/devices.json for test/mock device generation.
  • db.brandsMatch(a, b) checks whether two brand/manufacturer strings belong to the same OEM brand family (e.g. Xiaomi/Redmi/POCO, HMD Global/Nokia, Motorola/Lenovo, Nothing/CMF by Nothing).

generateDeviceSvg(params) & getDeviceSvgDataUri(params)

Generate deterministic, form-factor-aware device SVGs (x24, x120, x800) across wearable, foldable-tablet, legacy-16-9, modern-punch-hole, and ultra-tall-21-9 profiles:

const svg = db.generateDeviceSvg({
  model: 'Pixel 9',
  name: 'tokay',
  width: 1080,
  height: 2424,
  xdpi: 422,
  ydpi: 422,
  sdk: 34,
  size: 'x120'
})

const dataUri = db.getDeviceSvgDataUri({ model: 'Pixel 9', size: 'x24' })

Migrating from v1.x to v2.0

  • Static JPEG files under dist/icon/* and dist/photo/* (and dist/devices-latest.json) are replaced by dist/devices.json + runtime generateDeviceSvg() / getDeviceSvgDataUri().
  • memory.ram remains in MB, while memory.rom is now in GB, matching STF's hardware probe.
  • Legacy carrier, maker, os, display, and flags fields from 1.x were replaced by brand, marketName, YYYY-MM-DD date, nullable cpu/memory, and image SVG tokens.

Contributing

See CONTRIBUTING.md.

License

  • Data (dist/devices.json): Licensed under CC-BY-SA-4.0, adapted from the LineageOS Wiki (CC-BY-SA-3.0) and Wikidata (CC0).
  • Code (index.js, index.d.ts, brands.js, scripts/*, test/*): Licensed under Apache-2.0.

Google Play device identifiers

The brand, marketing name, codename and model of every device come from the Google Play Supported Devices list, which Google publishes without a stated license. They are used deliberately: no openly licensed source maps Android model numbers to marketing names at this scale, and LineageOS alone would cover about 2% of the models. Only these factual identifiers are taken. The CC-BY-SA-4.0 grant covers DeviceFarmer's selection and arrangement of them, not the identifiers themselves, and does not license the Google Play list as a whole.

See LICENSE for full details.

版本与发布记录

@devicefarmer/stf-device-db 共发布 5 个版本,首次发布于 2020/05/16;过去 12 个月发布了 2 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.0.1latest2026/11/074 天前
2.0.02026/10/2716 天前
1.4.02023/08/183 年前
1.3.02022/11/253 年前
1.2.02020/05/166 年前

关于 @devicefarmer/stf-device-db 的常见问题

@devicefarmer/stf-device-db 是什么?

A smartphone/device database for STF.

如何安装 @devicefarmer/stf-device-db?

在项目目录运行 npm install @devicefarmer/stf-device-db,或使用 pnpm add / yarn add / bun add。

@devicefarmer/stf-device-db 支持 TypeScript 吗?

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

@devicefarmer/stf-device-db 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@devicefarmer/stf-device-db 需要什么版本的 Node.js?

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

@devicefarmer/stf-device-db 可以商用吗?

@devicefarmer/stf-device-db 使用 (CC-BY-SA-4.0 AND Apache-2.0) 许可。声明的许可为 (CC-BY-SA-4.0 AND Apache-2.0),请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@devicefarmer/stf-device-db 的下载量有多少?

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

@devicefarmer/stf-device-db 还在维护吗?

最新版本 2.0.1 发布于 2026/11/07(4 天前);至今共发布 5 个版本,其中过去 12 个月发布了 2 个;首次发布于 2020/05/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。