@allegro/convert-description

中文文档
0.5.7发布于 2025/07/30ESM + CJS近 30 天下载 1871

A JavaScript library to convert HTML-rich offer & product descriptions into a format accepted by Allegro Rest API.

原始使用文档
文档目录6 节
  1. Motivation
  2. Requirements
  3. Installation
  4. Usage
  5. API
  6. CLI

@allegro/convert-description

A JavaScript library to convert HTML-rich offer & product descriptions into a format accepted by Allegro Rest API.

npm version npm downloads GitHub license

Live demo.

Motivation

Provide means to ease the conversion of HTML-rich offer & product descriptions into a format accepted by Allegro Rest API. As such, the library covers basic functionality. Any client-specific behavior must be provided externally. The library can facilitate that through extensibility.

Requirements

The library requires DOM API, which can be provided in two ways: either implicitly as globals by the browser environment or explicitly as the parseToDOM function in the Node.js environment (see Usage section).

The following requirements apply to Node.js as a runtime or build environment.

  • node version >=20
  • npm version >=10

Installation

npm i @allegro/convert-description

For the Node.js runtime environment, include jsdom.

npm i @allegro/convert-description jsdom

Usage

API

JavaScript code

import { convertDescriptionToItems } from '@allegro/convert-description';

const description = `
    <div>
          <div>test content</div>
          <img src="/test_url" />
    </div>
    `;

const items = convertDescriptionToItems(description);

console.log(JSON.stringify(items));

Code output

[{"type":"TEXT","content":"<p>test content</p>"},{"type":"IMAGE","url":"/test_url"}]

For the Node.js runtime environment, pass the parseToDOM function.

import { convertDescriptionToItems } from '@allegro/convert-description';
import { JSDOM } from 'jsdom';

function parseToDOM(html) {
  return new JSDOM(html);
}

const description = `
    <div>
          <div>test content</div>
          <img src="/test_url" />
    </div>
    `;
const items = convertDescriptionToItems(description, { parseToDOM });

console.log(JSON.stringify(items));

[!CAUTION] Any option to convertDescriptionToItems that is not mentioned in the documentation is subject to change. If you need anything more than the listed options, ask a question by opening an issue or contribute by creating a pull request.

CLI

$ echo "<p>Hello World</p>" | npx @allegro/convert-description
[{"type":"TEXT","content":"<p>Hello World</p>"}]

版本与发布记录

@allegro/convert-description 共发布 11 个版本,首次发布于 2024/08/12;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.5.7latest2025/07/301.3 年前
0.5.62025/07/291.3 年前
0.5.52025/07/281.3 年前
0.5.42024/12/171.9 年前
0.5.32024/12/171.9 年前
0.5.22024/12/171.9 年前

关于 @allegro/convert-description 的常见问题

@allegro/convert-description 是什么?

A JavaScript library to convert HTML-rich offer & product descriptions into a format accepted by Allegro Rest API.

如何安装 @allegro/convert-description?

在项目目录运行 npm install @allegro/convert-description,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 convert-description,可以用 npx convert-description 直接运行。

@allegro/convert-description 支持 TypeScript 吗?

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

@allegro/convert-description 支持 ESM 还是 CommonJS?

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

@allegro/convert-description 需要什么版本的 Node.js?

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

@allegro/convert-description 可以商用吗?

@allegro/convert-description 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@allegro/convert-description 的下载量有多少?

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

@allegro/convert-description 还在维护吗?

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