# @frogcat/ttl2jsonld 中文文档

规范地址：https://npmcn.com/package/%40frogcat/ttl2jsonld/

版本：0\.0\.11
npm 元数据更新时间：2026-10-15T01:11:48.549Z
中文译文更新时间：2026-11-15T14:34:26.773Z
软件包许可：MIT

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

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

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

- 包体积（解压后）：144 kB，5 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- 运行依赖：0 个
- 首次发布：2019-06-03T09:31:41.959Z
- 最新版本发布：2026-10-15T01:11:48.327Z
- 近 30 天下载量：80769（2026-10-16 至 2026-11-14，npm 官方下载统计）
- 已发布版本数：11（近 12 个月 1 个）

## 中文简介

Turtle 到 JSON- LD 节点和浏览器的转换器, 没有库依赖性

## 安装

```sh
npm install @frogcat/ttl2jsonld
```

也可以使用：`pnpm add @frogcat/ttl2jsonld`、`yarn add @frogcat/ttl2jsonld`、`bun add @frogcat/ttl2jsonld`

## README

# @frogcat/ttl2jsonld (英语)

Turtle to JSON-LD 用于节点.js和浏览器的转换器,没有库依赖性.

## 演示

可在线演示 [这里](https://frogcat.github.io/ttl2jsonld/demo/)。 。 。 .

使用此转换器,您可以获取 `Output JSON-LD` 从 `Input Turtle`,如 [JSON-LD 1.0 规格](https://www.w3.org/TR/json-ld/#turtle) 。 。 。 .

### 输入龟

```example66.ttl
@prefix foaf: <http://xmlns.com/foaf/0.1/> .

<http://manu.sporny.org/about#manu> a foaf:Person;
  foaf:name "Manu Sporny";
  foaf:homepage <http://manu.sporny.org/> .
```

### 产出JSON-LD

```exampl67.json
{
  "@context": {
    "foaf": "http://xmlns.com/foaf/0.1/"
  },
  "@id": "http://manu.sporny.org/about#manu",
  "@type": "foaf:Person",
  "foaf:name": "Manu Sporny",
  "foaf:homepage": { "@id": "http://manu.sporny.org/" }
}
```

## 安装

### 节点.js

```a.sh
$ npm install @frogcat/ttl2jsonld
```

### 浏览器

```a.html
<script src="https://frogcat.github.io/ttl2jsonld/ttl2jsonld.js"></script>
```

## 使用量

### 节点.js

你可以自己写代码.

```example.js
const ttl2jsonld = require('@frogcat/ttl2jsonld').parse;

const ttl = `@prefix foaf: <http://xmlns.com/foaf/0.1/> .

<http://manu.sporny.org/about#manu> a foaf:Person;
  foaf:name "Manu Sporny";
  foaf:homepage <http://manu.sporny.org/> .
`;

const jsonld = ttl2jsonld(ttl);

console.log(JSON.stringify(jsonld,null,2));

```

命令行接口也可用.

```cli.sh
$ npm install @frogcat/ttl2jsonld
$ ttl2jsonld {input_turtle} > {output_jsonld}
or
$ cat {input_turtle} | ttl2jsonld > {output_jsonld}
```

### 浏览器

此转换器被导出到 `ttl2jsonld` 全球对象。 打电话 `ttl2jsonld.parse(ttl)` 用于进行转换.

```example.html
<!-- include ttl2jsonld.js -->
<script src="https://frogcat.github.io/ttl2jsonld/ttl2jsonld.js"></script>

<!-- run script -->
<script>
const ttl = `@prefix foaf: <http://xmlns.com/foaf/0.1/> .

<http://manu.sporny.org/about#manu> a foaf:Person;
  foaf:name "Manu Sporny";
  foaf:homepage <http://manu.sporny.org/> .
`;

const jsonld = ttl2jsonld.parse(ttl);

console.log(JSON.stringify(jsonld,null,2));
</script>

```

## API 密码

鉴于 `turtle_string`, (中文(简体) ), `ttl2jsonld.parse` 返回 JSON 对象.

```a.js
var json_object = ttl2jsonld.parse(turtle_string);
```

想要通过BaseIRI时,请像这样给出第二个论证.

```a.js
var json_object = ttl2jsonld.parse(turtle_string, {
  baseIRI : "http://example.org/"
});
```

## 对于开发者

### 大楼

-   以 [国家](https://pegjs.org/)。 。 。 .
-   主代码为 `spec/ttl2jsonld.pegjs`。 。 。 .
-   编辑代码时,运行 `npm run build` 生成 `ttl2jsonld.js`。 。 。 .

### 测试

-   测试过 [测试套装](https://www.npmjs.com/package/rdf-test-suite) 财务报告和审定财务报表 [https://w3c.github.io/rdf-tests/rdf/rdf11/rdf-turtle/manifest.ttl 互联网档案馆的存檔,存档日期2014-12-21](https://w3c.github.io/rdf-tests/rdf/rdf11/rdf-turtle/manifest.ttl) 。 。 。 .
-   目前298/301次测试成功.
-   运行 `npm run spec-turtle` 开始测试套房.
-   其他杂项测试设在 `test/test.js`, (中文(简体) ), `npm run test` 运行.

## 常见问题

### @frogcat/ttl2jsonld 是什么？

Turtle 到 JSON- LD 节点和浏览器的转换器, 没有库依赖性

### 如何安装 @frogcat/ttl2jsonld？

在项目目录运行 npm install @frogcat/ttl2jsonld，或使用 pnpm add / yarn add / bun add。它还提供命令行工具 ttl2jsonld，可以用 npx ttl2jsonld 直接运行。

### @frogcat/ttl2jsonld 支持 TypeScript 吗？

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

### @frogcat/ttl2jsonld 支持 ESM 还是 CommonJS？

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

### @frogcat/ttl2jsonld 可以商用吗？

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

### @frogcat/ttl2jsonld 的下载量有多少？

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

### @frogcat/ttl2jsonld 还在维护吗？

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

