# @didomi/iabtcf-core 中文文档

规范地址：https://npmcn.com/package/%40didomi/iabtcf-core/

版本：1\.6\.6
npm 元数据更新时间：2026-10-20T14:10:37.277Z
中文译文更新时间：2026-11-12T07:48:37.660Z
软件包许可：Apache-2\.0

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

原始 npm 页面：https://www.npmjs.com/package/%40didomi/iabtcf-core
原文对照：https://npmcn.com/package/%40didomi/iabtcf-core/?lang=original
项目主页：https://iabtcf.com/
源码仓库：https://github.com/InteractiveAdvertisingBureau/iabtcf-es

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

- 包体积（解压后）：331 kB，241 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- 首次发布：2021-06-29T12:05:03.067Z
- 最新版本发布：2026-10-20T14:10:36.427Z
- 近 30 天下载量：2973（2026-10-12 至 2026-11-10，npm 官方下载统计）
- 已发布版本数：20（近 12 个月 2 个）

## 中文简介

确保对iab的TC信号进行一致的编码和解码. 透明度和同意框架.

## 安装

```sh
npm install @didomi/iabtcf-core
```

也可以使用：`pnpm add @didomi/iabtcf-core`、`yarn add @didomi/iabtcf-core`、`bun add @didomi/iabtcf-core`

## README

[![NPM version](https://img.shields.io/npm/v/@iabtcf/core.svg?style=flat-square)](https://www.npmjs.com/package/@iabtcf/core) [![npm module downloads per month](http://img.shields.io/npm/dm/@iabtcf/core.svg?style=flat)](https://www.npmjs.org/package/@iabtcf/core) [![InteractiveAdvertisingBureau](https://circleci.com/gh/InteractiveAdvertisingBureau/iabtcf-es.svg?style=shield)](https://circleci.com/gh/InteractiveAdvertisingBureau/iabtcf-es)

# @ iabtcf/ 核心

确保对 [IAB 透明度和同意框架](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework) [TC 字符串](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20Consent%20string%20and%20vendor%20list%20formats%20v2.md#about-the-transparency--consent-string-tc-string) 在提供处理和操纵《公约》的工具的同时,明确坚持透明和同意信息 [TCF 调制](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework) [全球供应商名单](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20Consent%20string%20and%20vendor%20list%20formats%20v2.md#the-global-vendor-list) 数据全部自由和开放源代码( e)[许可证](https://npmcn.com/package/%40didomi/iabtcf-core/LICENSE)) (中文(简体) ).

-   [安装](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-installation)
-   [包括你的项目](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-including-in-your-project)
-   [`TCModel`](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-tcmodel) - 创建一种状态模型,以存储透明与同意用户与该数据库指定的所有字段的交互 [TC 字符串](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20Consent%20string%20and%20vendor%20list%20formats%20v2.md#about-the-transparency--consent-string-tc-string) 编码计划.
    -   [存储在 TC 字符串中的信息( 规格)](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20Consent%20string%20and%20vendor%20list%20formats%20v2.md#what-information-is-stored-in-a-tc-string)
-   [全球在线](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-gvl) - 那个 [全球供应商名单](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20Consent%20string%20and%20vendor%20list%20formats%20v2.md#the-global-vendor-list) 本部分包含关于供应商和法律语言的所有信息,在《议定书》/《公约》缔约方会议用户界面中向用户显示,本部分有助于管理.
    -   [自动装入最新供应商名单。 json](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-autoload-latest-vendor-listjson)
    -   [自动装入特定版本的供应商列表. json](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-autoload-specific-version-vendor-listjson)
    -   [传出供应商列表.json 对象](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-pass-vendor-listjson-object)
    -   [更改 GVL 语言](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-change-gvl-language)
    -   [用非默认语言克隆 GVL](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-cloning-a-gvl-with-a-non-default-language)
    -   [仅让具有特定特点或目的的供应商在法律依据下参与](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-get-only-vendors-with-a-specific-feature-or-purpose-under-legal-basis)
    -   [缩小供应商名单](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-narrow-the-list-of-vendors)
    -   [过滤](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-narrow-the-list-of-vendors) gVL 子集的供应商.
    -   [根据目的法律依据对供应商进行分类](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-get-only-vendors-with-a-specific-feature-or-purpose-under-legal-basis) 《议定书》/《公约》缔约方会议需要让销售商了解情况.
    -   装入 [GVL JSON 文件](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-autoload-specific-vendor-listjson)
    -   装入 [语言翻译](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-change-gvl-language) 目的、特征、特殊特征、特殊目的和堆积
-   [TCString 键](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-tcstring) - 编码 a [`TCModel`](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-tcmodel) 改为 a [TC 字符串](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20Consent%20string%20and%20vendor%20list%20formats%20v2.md#about-the-transparency--consent-string-tc-string) 并解码 a [TC 字符串](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20Consent%20string%20and%20vendor%20list%20formats%20v2.md#about-the-transparency--consent-string-tc-string) 改为 a [`TCModel`](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-tcmodel)
    -   [解码 IAB TC 字符串](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-decode-an-iab-tc-string)
    -   [编码 IAB TC 字符串](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-encode-an-iab-tc-string)

#### 安装

无

```
npm install @iabtcf/core --save
```

线条

```
yarn add @iabtcf/core
```

#### 使用

这个例子证明了CMP创建"默认全无"TC字符串的基本用途案例.

```javascript
import {TCModel, TCString, GVL} from '@iabtcf/core';

/**
 *  the IAB requires CMPs to host their own vendor-list.json files.  This must
 *  be set before creating any instance of the GVL class.
 */
GVL.baseUrl = "http://mydomain.com/cmp/vendorlist";

// create a new TC string
const tcModel = new TCModel(new GVL());

// Some fields will not be populated until a GVL is loaded
tcModel.gvl.readyPromise.then(() => {

  // Set values on tcModel...

  const encodedString = TCString.encode(tcModel);

  console.log(encodedString); // TC string encoded begins with 'C'

});

// take an encoded TC string and decode into a TCModel
const decodedTCModel = TCString.decode(encodedString);

```

# 三角形模型

### 创建新的 TCModel

编码 a `TCModel` (单位:千美元) `GVL` 必须包含.

```javascript
import {TCModel} from '@iabtcf/core';

// creates a TCModel
const tcModel = new TCModel();

// to encode you must have a cmpId and cmpVersion
tcModel.cmpId = //{myCMPID}
tcModel.cmpVersion = //{myCMPVersion}

/**
 * we now have a TCString assigned with a GVL which will set vendorListVersion,
 * tcfPolicyVersion and consentLanguage
 */

```

### CMP 元字段

这个示例说明如何设置所有TC字符串需要设置的基本字段.

```javascript
import {TCModel} from '@iabtcf/core';

const tcModel = new TCModel();
tcModel.cmpId = // my CMP ID
tcModel.cmpVersion = // my CMP Version
tcModel.consentScreen = // On which 'screen' consent was captured; this is a cmp proprietary number encoded into the TC string
```

### 向量

这个 `TCModel` 杠杆a [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) 样式 `Vector` 数据结构用于设定同意、选择、允许、披露和合法权益建立。 影响此数据结构的属性为:

-   **供应商**
    -   `vendorConsents`
    -   `vendorLegitimateInterests`
    -   `vendorsAllowed`
    -   `vendorsDisclosed`
-   **全球目的**
    -   `purposeConsents`
    -   `purposeLegitimateInterests`
-   **特殊特性**
    -   `specialFeatureOptins`
-   **出版商**
    -   `publisherConsents`
    -   `publisherCustomConsents`
    -   `publisherLegitimateInterests`
    -   `publisherCustomLegitimateInterests`
    -   `publisherRestrictions`
        -   这个矢量很特别 `PurposeRestrictionVector` 联 合 国 `PurposeRestrictions`

**示例 `vendorConsents`**

这个 `vendorConsents` 财产 `TCModel` 是一个 `Vector`。这个例子说明一种 `Vector`。除 `publisherRestrictions`,用于执行不同类型 `PurposeRestrictionVector`,上面所有的矢量都会有这个接口和功能.

```javascript
// Give Vendor ID 24 consent
tcModel.vendorConsents.set(24);

console.log(tcModel.vendorConsents.has(24)); // true
console.log(tcModel.vendorConsents.maxId); // 24
console.log(tcModel.vendorConsents.size); // 1

// remove vendor 24
tcModel.vendorConsents.unset(24);
console.log(tcModel.vendorConsents.has(24)); // false
console.log(tcModel.vendorConsents.maxId); // 0
console.log(tcModel.vendorConsents.size); // 0

// give a group of vendors consent
tcModel.vendorConsents.set([24, 14, 24, 100, 102]);
console.log(tcModel.vendorConsents.has(24)); // true
console.log(tcModel.vendorConsents.has(14)); // true
console.log(tcModel.vendorConsents.has(200)); // false
console.log(tcModel.vendorConsents.maxId); // 102
console.log(tcModel.vendorConsents.size); // 5

// loop through all ids 1 to maxId (102 loops)
tcModel.vendorConsents.forEach((hasConsent, vendorId) => {

  // check each id for consent

});

// empty everything
tcModel.vendorConsents.empty();

console.log(tcModel.vendorConsents.has(24)); // false
console.log(tcModel.vendorConsents.maxId); // 0
console.log(tcModel.vendorConsents.size); // 0
```

### 设置出版商限制

A 类 [出版者限制](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20Consent%20string%20and%20vendor%20list%20formats%20v2.md#what-are-publisher-restrictions) 是由出版商限制供应商处理个人数据的目的。 这个 `TCModel.publisherRestrictions` 是一个实例 `PurposeRestrictionVector`,这是含有 `PurposeRestrictions`对.

**设置出版商限制的实例**

```javascript

import {TCModel, PurposeRestriction, RestrictionType} from '@iabtcf/core';

// first you must create a PurposeRestriction
const purposeRestriction = new PurposeRestriction();

purposeRestriction.purposeId = 2;
purposeRestriction.restrictionType = RestrictionType.NOT_ALLOWED;

// vendorID and restriction
tcModel.publisherRestrictions.add(2000, purposeRestriction);

```

# 全球在线

-   [自动装入最新供应商名单。 json](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-autoload-latest-vendor-listjson)
-   [自动装入特定供应商名单](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-autoload-specific-vendor-listjson)
-   [传出供应商列表.json 对象](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-pass-vendor-list.json-object)
-   [更改 GVL 语言](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-change-gvl-language)
-   [用非默认语言克隆 GVL](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-cloning-a-gvl-with-a-non-default-language)
-   [仅让具有特定特点或目的的供应商在法律依据下参与](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-get-only-vendors-with-a-specific-feature-or-purpose-under-legal-basis)
-   [缩小供应商名单](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-narrow-the-list-of-vendors)

这个 `GVL` 阶级提供了两种即时反应的方法. 要么通过一个销售商列表. json反对插入,要么从一个url自动装入一个销售商列表. json.

### 自动装入最新供应商名单。 json

自动加载一个供应商列表. json会接受一个供应商列表的版本号,或者如果没有任何内容或"LATEST"通过,它会加载最新的供应商列表. 说明。 你必须设置 `GVL.baseUrl` 参数在即时化 GVL 实例前。 如果需要的话 `GVL.latestFilename` 如果 `vendor-list.json` 未使用.

**正在装入默认文件名**

```javascript
import {GVL} from '@iabtcf/core';

// only needs to be set once per application as this is a static variable
GVL.baseUrl = 'http://cmp.mysupercoolcmp.com/cmp/';

// loads 'http://cmp.mysupercoolcmp.com/cmp/vendor-list.json'
const gvl = new GVL();

gvl.readyPromise.then(() => {

  // GVL has loaded and it's ready to use

});
```

**装入自定义文件名**

```javascript
import {GVL} from '@iabtcf/core';

// only needs to be set once per application as this is a static variable
GVL.baseUrl = 'http://cmp.mysupercoolcmp.com/cmp/';

GVL.latestFilename = 'latest/vendorlist.js';

// loads 'http://cmp.mysupercoolcmp.com/cmp/latest/vendorlist.json'
const gvl = new GVL();

gvl.readyPromise.then(() => {

  // GVL has loaded and it's ready to use

});
```

### 自动装入特定版本的供应商列表. json

自动加载特定版本需要你们两个设置 `GVL.baseUrl` 静态变量并传递到构建器中您想要加载的版本编号。 如果您的文件名有其它版本, 可选择 `vendor-list-v[VERSION].json` 您可以设置一个不同的文件名, 版本为 `GVL.versionedFilename = 'vendorlist[VERSION].json';` 和标志 `[version]` 将替换为您通过到构建器的版本编号.

**正在装入版本的默认文件名**

```javascript
import {GVL} from '@iabtcf/core';

// only needs to be set once per application as this is a static variable
GVL.baseUrl = 'http://cmp.mysupercoolcmp.com/cmp/';

// loads 'http://cmp.mysupercoolcmp.com/cmp/archives/vendor-list-v23.json'
const gvl = new GVL(23);

gvl.readyPromise.then(() => {

  // GVL has loaded and it's ready to use

});
```

**更改版本名称方案**

```javascript
import {GVL} from '@iabtcf/core';

// only needs to be set once per application as this is a static variable
GVL.baseUrl = 'http://cmp.mysupercoolcmp.com/cmp/';

GVL.versionedFilename = 'vendorlist[VERSION].json';

// loads 'http://cmp.mysupercoolcmp.com/cmp/vendorlist23.json'
const gvl = new GVL(23);

gvl.readyPromise.then(() => {

  // GVL has loaded and it's ready to use

});
```

### 传出供应商列表.json 对象

您也可以在 Json 对象中通过( 未被固定)

```javascript
import {GVL} from '@iabtcf/core';

const gvl = new GVL(gvljson);

// no need for ready promise because no asynchronous action has occurred
// gvl is ready to use
```

### 更改 GVL 语言

所有卖家名单默认以英文发布. iab出版的还有替代语言,即没有供应商的供应商名单. `GVL.baseUrl` 必须被设定用于改变标签。 要装入候补您只需拨打 `gvl.changeLanguage(/**language*/);` laanguge是同位素639-1双字母laanguge代码. [提供的全部iab语言翻译列表请点击此处](https://register.consensu.org/Translation)。如果需要的话 `GVL.languageFilename` 如果 `purposes-[LANG].json` 未使用.

**默认文件名负载**

```javascript
import {GVL} from '@iabtcf/core';

// only needs to be set once per application as this is a static variable
GVL.baseUrl = 'http://cmp.mysupercoolcmp.com/';

const gvl = new GVL(gvljson);

// loads the French langauge
gvl.changeLanguage('fr').then(() => {

  // French Language GVL is ready for use

});
```

**更改文件名负载**

```javascript
import {GVL} from '@iabtcf/core';

const gvl = new GVL(gvljson);

// only needs to be set once per application as this is a static variable
GVL.baseUrl = 'http://cmp.mysupercoolcmp.com/';

GVL.langaugeFilename = 'langauges/purp[LANG].json';

// loads the French langauge from 'http://cmp.mysupercoolcmp.com/purpfr.json'
gvl.changeLanguage('fr').then(() => {

  // French Language GVL is ready for use

});
```

### 用非默认语言克隆 GVL

在以非默认语言复制 GVL 时, 请确保任何先前的 `changeLanguage` 电话解决了。 如果改变语言还没有解决, `clone` 将请求 http 的当前语言,但无法显示该请求是否得到解决,因为它是同步的.

```javascript
import {GVL} from '@iabtcf/core';

const gvl = new GVL();

// Resolving changeLanguage promise using thenables.
gvl.changeLanguage('fr').then(() => {

  const clone = gvl.clone();

})

// Resolving changeLanguage through async/await
const someAsyncFunction = async () => {

  await gvl.changeLanguage('fr');
  const clone = gvl.clone();

}
```

### 仅让具有特定特点或目的的供应商在法律依据下参与

《议定书》/《公约》缔约方会议UI不妨将供应商分组,按其使用何种法律依据和/或特征。 通过使用6个分组方法之一,可以很容易地做到这一点:

-   `getVendorsWithConsentPurpose(purposeId)`
-   `getVendorsWithFeature(featureId)`
-   `getVendorsWithFlexiblePurpose(purposId)`
-   `getVendorsWithLegIntPurpose(purposId)`
-   `getVendorsWithSpecialFeature(featureId)`
-   `getVendorsWithSpecialPurpose(purposId)`

所有6个分组方法都返回 `IntMap<Vendor>` 对象

```javascript
import {GVL} from '@iabtcf/core';

// only needs to be set once per application as this is a static variable
GVL.baseUrl = 'http://cmp.mysupercoolcmp.com/cmp/';

// loads 'http://cmp.mysupercoolcmp.com/cmp/vendor-list.json'
const gvl = new GVL();

gvl.readyPromise.then(() => {

  const vendorMap = gvl.getVendorsWithConsentPurpose(1);

  // logs all vendor ids who have specified they require consent for purpose 1
  Object.keys(vendorMap).forEach(console.log);

});

```

### 缩小供应商名单

如果装入《议定书》/《公约》缔约方会议想要显示供应商名单的一个子集,则只能将过滤器传给与名单上的供应商一起工作.

```javascript
import {GVL} from '@iabtcf/core';

// only needs to be set once per application as this is a static variable
GVL.baseUrl = 'http://cmp.mysupercoolcmp.com/cmp/';

// loads 'http://cmp.mysupercoolcmp.com/cmp/vendor-list.json'
const gvl = new GVL();

gvl.readyPromise.then(() => {

  // now this gvl instance only has these 3 vendors
  gvl.narrowVendorsTo([1,2,3]);

  // will only show the Vendor objects for 1, 2, and 3
  console.log(gvl.vendors);

  // will only return the vendors within the narrowed vendor list
  const vendorsWithLegInt2 = gvl.getVendorsWithLegIntPurpose(2);


});

```

# TCString 键

-   [解码](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-decode-an-iab-tc-string)
-   [编码](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-encode-an-iab-tc-string)
-   [编码选项](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-encoding-options)
-   [编码一个出版商 TC 片段](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-encoding-a-publisher-tc-segment)

### 解码 IAB TC 字符串

```typescript

import {TCString, TCModel} from '@iabtcf/core';

const myTCModel = TCString.decode(encodedTCString);

```

_返回 :_ [`TCModel`](https://npmcn.com/package/%40didomi/iabtcf-core/#readme-tcmodel)

### 编码 IAB TC 字符串

```typescript
import {TCString, TCModel, GVL} from '@iabtcf/core';

/**
 * With v2.0 of the TCF, CMPs are required to host their own vendor-list.json for
 * their client-side scripts to consume.  This GVL class follows the convention
 * outlined in the GVL URL Version scheme.  (latest at vendor-list.json and
 * version specific at archives/vendor-list-v{vendor-list-version}.json
 */
GVL.baseUrl = "http://mydomain.com/cmp/vendorlist";

// we'll get the latest GVL to encode this TCString to
const gvl = new GVL("LATEST");

// have to wait for it to fetch the json
gvl.readyPromise.then(() => {

  const tcModel = new TCModel(gvl);
  const encodedTCString = TCString.encode(tcModel);

  /**
   * this will output a default all "no" encoded string to the console at the
   * lastest GVL version.
   */
  console.log(encodedTCString);

});
```

### 一次解码一段

可以通过提及已创建的 `TCModel` 并在模型中添加单个片段。 这方面的一个重要用途是使用全球范围的TC字符串,并将出版商TC片段单独存储在一党饼干中.

```typescript

import {TCString, Segment} from '@iabtcf/core';

// if you had a getCookie function that returned just that segment
const publisherTCSegment = getCookie('euconsent-ptc');

let tcModel;

// if you had an asynchronous function to get the cookie from global
getGlobalTCString().then((encodedTCString) => {

  tcModel = TCString.decode(encodedTCString);
  TCString.decode(publisherTCSegment, tcModel);

  // now you have a combined TCModel

});


```

### 编码选项

选项可能会被传递到编码器来覆盖默认值. 在大多数情况下,编码器可以找出要包括哪些部分,但如果字符串被浮出销售商的表面或用于将编码存储在饼干中,则编码略有不同. 这个 `@iabtcf/cmpapi` 处理这种差异, CMPs不需要担心.

```typescript
import {TCString, Segment} from '@iabtcf/core';

// produces the version of the string for the __tcfapi function
const cmpApiEncodedString = TCString.encode(tcModel, { isForVendors: true });

// Overrides default segments (not recommended unless you know what you're doing)
const encodingOptions = {
  segments: [
    Segment.CORE,
    Segment.VENDORS_DISCLOSED,
    Segment.VENDORS_ALLOWED,
    Segment.PUBLISHER_TC,
  ]
}

const customEncodedString = TCString.encode(tcModel, encodingOptions);

```

### 编码一个出版商 TC 片段

默认,如果 `TCModel.isServiceSpecific = true` 然后编码一个字符串,包括出版商TC段。 不过如果 `TCModel.isServiceSpecific = false` 然后,该段只应被浮出 `__tcfapi` 界面,而不保存到全局饼干。 然而,人们需要一种方法来访问并保存出版商TC部分与主TC String分开,以作为一党饼干来存储. 这样的话,你可以使用 `EncodingOptions` 只生成一个 Publicer TC 部分.

```typescript
const encodingOptions = {
  segments: [Segment.PUBLISHER_TC]
}
const publisherTCSegment = TCString.encode(tcModel, encodingOptions);
```

## 常见问题

### @didomi/iabtcf-core 是什么？

确保对iab的TC信号进行一致的编码和解码\. 透明度和同意框架\.

### 如何安装 @didomi/iabtcf-core？

在项目目录运行 npm install @didomi/iabtcf-core，或使用 pnpm add / yarn add / bun add。

### @didomi/iabtcf-core 支持 TypeScript 吗？

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

### @didomi/iabtcf-core 支持 ESM 还是 CommonJS？

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

### @didomi/iabtcf-core 可以商用吗？

@didomi/iabtcf-core 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @didomi/iabtcf-core 的下载量有多少？

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

### @didomi/iabtcf-core 还在维护吗？

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

