# @commercetools-test-data/commons 中文文档

规范地址：https://npmcn.com/package/%40commercetools-test-data/commons/

版本：10\.18\.2
npm 元数据更新时间：2025-05-08T11:21:05.935Z
中文译文更新时间：2026-11-10T12:04:40.776Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40commercetools-test-data/commons
原文对照：https://npmcn.com/package/%40commercetools-test-data/commons/?lang=original
项目主页：https://github.com/commercetools/test-data#readme
源码仓库：https://github.com/commercetools/test-data

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：270 kB，86 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：10 个
- 首次发布：2020-10-08T14:17:07.094Z
- 最新版本发布：2025-05-08T11:21:05.735Z
- 近 30 天下载量：10814（2026-10-11 至 2026-11-09，npm 官方下载统计）
- 已发布版本数：606（近 12 个月 0 个）

## 中文简介

商务工具平台通用类型数据模型

## 安装

```sh
npm install @commercetools-test-data/commons
```

也可以使用：`pnpm add @commercetools-test-data/commons`、`yarn add @commercetools-test-data/commons`、`bun add @commercetools-test-data/commons`

## README

# @ commercialtools- test-data/ commons (英语)

此软件包为商务工具平台提供了常见类型的数据模型

[https://docs.com.com/api/types (中文(简体) )](https://docs.commercetools.com/api/types)

# 安装

```bash
$ pnpm add -D @commercetools-test-data/commons
```

# 使用量

-   [地址](https://npmcn.com/package/%40commercetools-test-data/commons/#readme-address)  
    
-   [精密货币](https://npmcn.com/package/%40commercetools-test-data/commons/#readme-centprecisionmoney)  
    
-   [客户端日志](https://npmcn.com/package/%40commercetools-test-data/commons/#readme-clientlogging)  
    
-   [折扣线项目组合](https://npmcn.com/package/%40commercetools-test-data/commons/#readme-dicountedlineitemportion)  
    
-   [贴现 项目价格](https://npmcn.com/package/%40commercetools-test-data/commons/#readme-discountedlineitemprice)  
    
-   [高精度货币](https://npmcn.com/package/%40commercetools-test-data/commons/#readme-highprecisionmoney)  
    
-   [键](https://npmcn.com/package/%40commercetools-test-data/commons/#readme-keyreference)  
    
-   [本地化结构](https://npmcn.com/package/%40commercetools-test-data/commons/#readme-localizedstring)  
    
-   [钱](https://npmcn.com/package/%40commercetools-test-data/commons/#readme-money)  
    
-   [价格](https://npmcn.com/package/%40commercetools-test-data/commons/#readme-price)  
    
-   [参考文献](https://npmcn.com/package/%40commercetools-test-data/commons/#readme-reference)  
    
-   [价格比较](https://npmcn.com/package/%40commercetools-test-data/commons/#readme-pricetier)  
    

## `Address`

```ts
import {
  Address,
  AddressDraft,
  type TAddress,
  type TAddressDraft,
} from '@commercetools-test-data/commons';

const address = Address.random().build<TAddress>();
const addressDraft = AddressDraft.random().build<TAddressDraft>();
```

# 精密货币

```ts
import {
  CentPrecisionMoney,
  CentPrecisionMoneyDraft,
  type TCentPrecisionMoney,
  type TCentPrecisionMoneyDraft,
} from '@commercetools-test-data/commons';

const centPrecisionMoney =
  CentPrecisionMoney.random().build<TCentPrecisionMoney>();
const centPrecisionMoneyDraft =
  CentPrecisionMoneyDraft.random().build<TCentPrecisionMoneyDraft>();
```

# 客户端日志

```ts
import {
  ClientLogging,
  type TClientLogging,
} from '@commercetools-test-data/commons';
const clientLogging = ClientLogging.random().build<TClientLogging>();
```

# 折扣线项目组合

```ts
import {
  DiscountedLineItemPortionRest,
  DiscountedLineItemPortionDraftRest,
  DiscountedLineItemPortionGraphql,
  DiscountedLineItemPortionDraftGraphql,
} from '@commercetools-test-data/commons';

const restDiscountedLineItemPortion = \
  DiscountedLineItemPortionRest.random().build();
const restDiscountedLineItemPortionDraft =
  DiscountedLineItemPortionDraftRest.random().build();

const graphqlDiscountedLineItemPortion =
  DiscountedLineItemPortionGraphql.random().build();
const graphqlDiscountedLineItemPortionDraft =
  DiscountedLineItemPortionDraftGraphql.random().build();
```

# 贴现 项目价格

```ts
import {
  DiscountedLineItemPriceRest,
  DiscountedLineItemPriceGraphql,
} from '@commercetools-test-data/commons';

const restDiscountedLineItemPrice = \
  DiscountedLineItemPriceRest.random().build();
const restDiscountedLineItemPriceDraft =
  DiscountedLineItemPriceDraftRest.random().build();
```

# 高精度货币

```ts
import {
  HighPrecisionMoney,
  HighPrecisionMoneyDraft,
  type THighPrecisionMoney,
  type THighPrecisionMoneyDraft,
} from '@commercetools-test-data/commons';

const highPrecisionMoney =
  HighPrecisionMoney.random().build<THighPrecisionMoney>();
const highPrecisionMoneyDraft =
  HighPrecisionMoneyDraft.random().build<THighPrecisionMoneyDraft>();
```

## `KeyReference`

```ts
import {
  KeyReference,
  KeyReferenceDraft,
  type TKeyReference,
  type TKeyReferenceDraft,
} from '@commercetools-test-data/commons';

const productKeyRef = KeyReference.random()
  .typeId('product')
  .build<TKeyReference<'product'>>();
const productKeyRefDraft = KeyReferenceDraft.random()
  .typeId('product')
  .build<TKeyReferenceDraft<'product'>>();
```

## `LocalizedString`

```ts
import {
  LocalizedString,
  LocalizedStringDraft,
  type TLocalizedString,
  type TLocalizedStringDraft,
} from '@commercetools-test-data/commons';

const name = LocalizedString.random().build<TLocalizedString>();
const nameDraft = LocalizedStringDraft.random().build<TLocalizedString>();

// Presets
const emptyName = LocalizedString.presets.empty().build<TLocalizedString>();
const emptyNameDraft = LocalizedStringDraft.presets
  .empty()
  .build<TLocalizedStringDraft>();
```

## `Money`

```ts
import {
  Money,
  MoneyDraft,
  type TMoney,
  type TMoneyDraft,
} from '@commercetools-test-data/money';

const Money = Money.random().build<TMoney>();
const MoneyDraft = MoneyDraft.random().build<TMoneyDraft>();
```

## `Price`

```ts
import {
  Price,
  PriceDraft,
  type TPrice,
  type TPriceDraft,
} from '@commercetools-test-data/commons';

const price = Price.random().build<TPrice>();
const priceDraft = PriceDraft.random().build<TPriceDraft>();
```

## `Reference`

```ts
import {
  Reference,
  ReferenceRest,
  ReferenceGraphql,
  ReferenceDraft,
  ReferenceDraftRest,
  ReferenceDraftGraphql,
  type TReference,
  type TReferenceDraft,
} from '@commercetools-test-data/commons';

// DEPRECATED. Please use one of the methods below
const productRef = Reference.random()
  .typeId('product')
  .build<TReference<'product'>>();
const restProductRef = ReferenceRest.random().
  .typeId('product')
  .build();
const graphqlProductRef = ReferenceGraphql.random().
  .typeId('product')
  .build();

// DEPRECATED. Please use one of the methods below
const productRefDraft = ReferenceDraft.random()
  .typeId('product')
  .build<TReferenceDraft<'product'>>();
const restProductRefDraft = ReferenceDraftRest.random().
  .typeId('product')
  .build();
const graphqlProductRefDraft = ReferenceDraftGraphql.random().
  .typeId('product')
  .build();


// Presets
const restCategoryRef = ReferenceRest.presets
  .category()
  .build();
const graphqlCategoryRefDraft = ReferenceDraftGraphql.presets
  .category()
  .build();
```

## `PriceTier`

```ts
import { PriceTier, type TPriceTier } from '@commercetools-test-data/commons';

const productRef = PriceTier.random().build<TPriceTier>();

// Presets
const categoryRef = PriceTier.presets.build<TPriceTier>();
```

## 常见问题

### @commercetools-test-data/commons 是什么？

商务工具平台通用类型数据模型

### 如何安装 @commercetools-test-data/commons？

在项目目录运行 npm install @commercetools-test-data/commons，或使用 pnpm add / yarn add / bun add。

### @commercetools-test-data/commons 支持 TypeScript 吗？

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

### @commercetools-test-data/commons 支持 ESM 还是 CommonJS？

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

### @commercetools-test-data/commons 可以商用吗？

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

### @commercetools-test-data/commons 的下载量有多少？

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

### @commercetools-test-data/commons 还在维护吗？

最新版本 10\.18\.2 发布于 2025/05/08（1\.5 年前）；至今共发布 606 个版本，其中过去 12 个月发布了 0 个；首次发布于 2020/10/08。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

