# @finsweet/attributes 中文文档

规范地址：https://npmcn.com/package/%40finsweet/attributes/

版本：2\.7\.1
npm 元数据更新时间：2026-05-25T07:50:07.339Z
中文译文更新时间：2026-11-14T20:11:08.765Z
软件包许可：Apache-2\.0

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

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

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

- 包体积（解压后）：927 kB，51 个文件
- 模块格式：ES Module
- TypeScript 类型：未声明
- 运行依赖：30 个
- 首次发布：2024-03-21T18:41:57.196Z
- 最新版本发布：2026-05-25T07:50:07.021Z
- 近 30 天下载量：2295（2026-10-15 至 2026-11-13，npm 官方下载统计）
- 已发布版本数：87（近 12 个月 16 个）

## 中文简介

Finsweet 属性 V2

## 安装

```sh
npm install @finsweet/attributes
```

也可以使用：`pnpm add @finsweet/attributes`、`yarn add @finsweet/attributes`、`bun add @finsweet/attributes`

## README

[![Attributes by Finsweet - Free powerful features for your site, no confusing code](https://cdn.prod.website-files.com/648b0184fc925cdf643d8b74/681bae7059f00e0e5d4e5c97_banner-attributes.png)](https://finsweet.com/attributes)

[![npm](https://img.shields.io/npm/v/@finsweet/attributes.svg)](https://www.npmjs.com/package/@finsweet/attributes) [![Hits](https://img.shields.io/jsdelivr/npm/hm/@finsweet/attributes)](https://www.npmjs.com/package/@finsweet/attributes) [![License](https://img.shields.io/npm/l/@finsweet/attributes.svg)](https://npmcn.com/package/%40finsweet/attributes/LICENSE.md)

## 什么是属性?

属性是一个开源 JavaScript 库,包含用于添加过滤器,排序,加载和搜索选项,CMS分页和滑行器的解决方案,以及更多使用简单的HTML属性向Web流量.

## 开始

请注意这里的文件 [fisweet.com/属性 互联网档案馆的存檔,存档日期2013-10-02](https://www.finsweet.com/attributes) 在 Webflow 项目中学习如何使用属性.

## API 参考

属性将注入全局 `window.FinsweetAttributes` 对象输入包含一些与库互动的方法的项目.

在尝试访问库前确保库内装入 `window.FinsweetAttributes` 对象,可以使用下列即时代码:

```javascript
window.FinsweetAttributes ||= [];
window.FinsweetAttributes.push([
  'ATTRIBUTE_KEY', // 'list', 'copyclip', 'modal', etc.
  (result) => {
    // Your code goes here.
  },
]);
```

结果对象将包含已装入属性解决方案的 API. 检查 `README.md` 每个属性解决方案的文档,以获取关于 API 的更多信息.

### 这个 `FinsweetAttributes` 对象

#### 属性

| 财产 | 类型 | 说明 |
| --- | --- | --- |
| `process` | `Set` | 包含当前活动属性解决方案. |
| `modules` | `Object` | 一个包含每个活动属性解决方案控件的密钥值对象。 每个键是相应的属性键,每个值是一个 [Finsweet 属性控制](https://npmcn.com/package/%40finsweet/attributes/#readme-the-finsweetattributecontrols-object) 对象. |
| `utils` | `Object` | 包含与属性合作的功能. |

#### 方法

| 方法 | 说明 | 参数 |
| --- | --- | --- |
| `push([key, callback])` | 在属性装入后运行回调 . | `key (string)`: 属性密钥.  
`callback (function)`:召回函数. |
| `load(key)` | 动态加载属性解决方案 . | `key (string)`: 属性密钥. |
| `destroy()` | 破坏实例和所有属性解决方案. |  |

### 这个 `FinsweetAttributeControls` 对象

#### 属性

| 财产 | 类型 | 说明 |
| --- | --- | --- |
| `version` | `string` | 属性的版本. |
| `loading` | `Promise` | 一旦属性装入并返回其 API , 就可以解决的承诺 . |

#### 方法

| 方法 | 说明 | 参数 |
| --- | --- | --- |
| `restart()` | 恢复属性 在实践中,这意味着属性会被再被销毁并装入. |  |
| `destroy()` | 摧毁属性. |  |

### 这个 `FinsweetAttributes.utils` 对象

```ts
type FinsweetAttributesUtils = {
  /**
   * Fetches and parses an external page.
   * Stores the page response in an IndexedDB if the page belongs to the same site.
   *
   * @param source The URL of the page to fetch
   * @param options Optional configuration object
   * @returns Promise that resolves to the page's Document if successful, null otherwise
   */
  fetchPage: (
    source: string | URL,
    options?: {
      cache?: boolean; // Whether to cache fetched documents. Defaults to `true`
      cacheExternal?: boolean; // Whether to cache external documents using a stale-while-revalidate strategy
      cacheKey?: string; // Manual database name for the IndexedDB instance
      cacheVersion?: number; // Manual version for the IndexedDB instance
    }
  ) => Promise<Document | null> | null;

  /**
   * Attaches external stylesheets from a fetched page to the current document head.
   * Only attaches stylesheets hosted on the Webflow Assets CDN that aren't already present.
   *
   * @param page The Document object from which to extract stylesheets
   * @returns Promise that resolves when all stylesheets have been attached
   */
  attachExternalStylesheets: (page: Document) => Promise<void>;
};
```

## 常见问题

### @finsweet/attributes 是什么？

Finsweet 属性 V2

### 如何安装 @finsweet/attributes？

在项目目录运行 npm install @finsweet/attributes，或使用 pnpm add / yarn add / bun add。

### @finsweet/attributes 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/finsweet\_\_attributes 是否存在。

### @finsweet/attributes 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @finsweet/attributes 可以商用吗？

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

### @finsweet/attributes 的下载量有多少？

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

### @finsweet/attributes 还在维护吗？

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

