# @forthix/forthic 中文文档

规范地址：https://npmcn.com/package/%40forthix/forthic/

版本：0\.24\.0
npm 元数据更新时间：2026-11-13T21:19:51.222Z
中文译文更新时间：2026-11-15T09:46:00.264Z
软件包许可：BSD-2-Clause

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

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

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

- 包体积（解压后）：1.8 MB，300 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=16\.0\.0
- 运行依赖：1 个
- peer 依赖：temporal-polyfill ^0\.3\.0
- 首次发布：2025-10-13T23:59:24.008Z
- 最新版本发布：2026-11-13T21:19:51.042Z
- 近 30 天下载量：5204（2026-10-16 至 2026-11-14，npm 官方下载统计）
- 已发布版本数：37（近 12 个月 31 个）

## 中文简介

基于堆叠的,可相容的变换语言 - TypeScript/JavaScript 运行时间

## 安装

```sh
npm install @forthix/forthic
```

也可以使用：`pnpm add @forthix/forthic`、`yarn add @forthix/forthic`、`bun add @forthix/forthic`

## README

# 虚拟类型脚本运行时间

**类型脚本/ JavaScript 运行时间 [福尔特](https://github.com/forthix/forthic)** - 说吧 _页:1_ 基于堆栈的,可调和的语言用于可相容的转换.

使用 Forthic 将您的 TypeScript/ JavaScript 代码包入可复写词中, 利用绝对原理来进行干净而强大的抽象 .

**[在 extix.com 学习](https://forthix.com/)** | **[福特医生](https://github.com/forthix/forthic)** | **[开始](https://npmcn.com/package/%40forthix/forthic/#readme-getting-started)** | **[实例](https://npmcn.com/package/%40forthix/forthic/examples/)** | **[API 文档](https://npmcn.com/package/%40forthix/forthic/docs/)**

* * *

## 佛提克是什么来着?

Fortic 启用 **绝对编码** - 一种解决问题的方法,从有轨电车而不是同化的角度看待问题。 此类型脚本运行时间允许您 :

1.  **环绕已存在的代码** 带有简单的装饰器
2.  **组成转换** 干净地使用基于堆栈的操作
3.  **构建强大的抽象** 从简单的原始人

**[更多地了解分类编码 –](https://forthix.com/blog/category-theory-for-the-rest-of-us-coders)**

见 [福斯库](https://github.com/forthix/forthic) 用于技术文件和API参考.

* * *

## 快速示例

### 创建模块

```typescript
import { DecoratedModule, Word } from '@forthix/forthic';

export class AnalyticsModule extends DecoratedModule {
  constructor() {
    super("analytics");
  }

  @Word("( numbers:number[] -- avg:number )", "Calculate average")
  async AVERAGE(numbers: number[]) {
    return numbers.reduce((a, b) => a + b, 0) / numbers.length;
  }

  @Word("( numbers:number[] stdDevs:number -- filtered:number[] )", "Filter outliers")
  async FILTER_OUTLIERS(numbers: number[], stdDevs: number) {
    // Your existing logic here
    return filteredNumbers;
  }
}
```

### 用这个

```typescript
import { Interpreter } from '@forthix/forthic';
import { AnalyticsModule } from './analytics-module';

const interp = new Interpreter();
interp.register_module(new AnalyticsModule());

await interp.run(`
  ["analytics"] USE-MODULES

  [1 2 3 100 4 5] 2 FILTER-OUTLIERS AVERAGE
`);

const result = interp.stack_pop(); // Clean average without outliers
```

* * *

## 安装

### 无

```bash
npm install @forthix/forthic
```

### 线条

```bash
yarn add @forthix/forthic
```

### 需求:全球 `Temporal`

Forthic 的日期和时间值基于 [TC39 临时API](https://tc39.es/proposal-temporal/)。运行时间参考 a **全球 `Temporal` 对象** 而不捆绑一个多填料,所以主机负责提供一个. 任何使用日期/时间的Forthic程序(`TODAY`, (中文(简体) ), `NOW`,日期字节类似 `2020-06-05`,则 `datetime` 模块,或时间值的线条序列化)将抛出 `Temporal is not defined` 如果没有全局 `Temporal` 已提供.

土著 `Temporal` 尚未在Node.js、Chrome或Safari发货,所以大多数消费者需要多功能填充。 安装 [`temporal-polyfill`](https://www.npmjs.com/package/temporal-polyfill) 导入 **一次** 在您申请的切入点, 在运行 Forthic 之前:

```bash
npm install temporal-polyfill
```

```typescript
import "temporal-polyfill/global"; // installs globalThis.Temporal
import { Interpreter } from "@forthix/forthic";
```

`temporal-polyfill` 被宣布为 **可选同伴依赖**: 仅在您的运行时间已经提供本地全局时跳过 `Temporal`,或者程序从不触及日期/时间。 对于 TypeScript 类型检查 Temperal 类型,也添加 `temporal-spec` 是一个非常依赖.

* * *

## 开始

### 节点使用

```typescript
import { Interpreter } from '@forthix/forthic';

const interp = new Interpreter();

// Execute Forthic code
await interp.run(`
  [1 2 3 4 5] "2 *" MAP  # Double each element
`);

const result = interp.stack_pop(); // [2, 4, 6, 8, 10]
```

### 浏览器使用

```html
<script type="module">
  import { Interpreter } from 'https://unpkg.com/@forthix/forthic';

  const interp = new Interpreter();
  await interp.run('[1 2 3] "2 *" MAP');
  console.log(interp.stack_pop()); // [2, 4, 6]
</script>
```

### 创建您的第一个模块

```typescript
import { DecoratedModule, Word } from '@forthix/forthic';

export class MyModule extends DecoratedModule {
  constructor() {
    super("mymodule");
  }

  @Word("( data:any[] -- result:any )", "Process data your way")
  async PROCESS(data: any[]) {
    // Wrap your existing code
    return myExistingFunction(data);
  }
}

// Register and use
const interp = new Interpreter();
interp.register_module(new MyModule());

await interp.run(`
  ["mymodule"] USE-MODULES
  SOME-DATA PROCESS
`);
```

见 [实例/README.md](https://npmcn.com/package/%40forthix/forthic/examples/README.md) 用于详细的教程和实例.

* * *

## 特征

### 标准库

TypeScript运行时间包括全面的标准模块:

-   **数组** - MAP、SELECT、SORT、GROUP-BY、ZIP、REDUCE、FLATTEN(30+操作)
-   **记录** - REC@, <REC,MERGE, 关键词, VALUES, 永远的KEYS
-   **字符串** - SPLIT, JOIN, UPPERCASE, LOWERCASE, TRIM, REPLACE(英语:PERLACE)) - (英语)
-   **数学** - +, -, \*, /, ROUND, ABS, MIN, MAX, 变相
-   **约会时间** - >日期,>日期,日期,日期,日期,格式,日期
-   **乔森** - "杰森,杰森",杰森-普雷蒂菲
-   **布尔** - ==, <, > 和,或,不

见 [文档/模块/](https://npmcn.com/package/%40forthix/forthic/docs/modules/) 完全参考.

### 简单模块创建

这个 `@Word` 装饰使包装代码变得微不足道:

```typescript
@Word("( input:type -- output:type )", "Description", "MY-WORD")
async MY_WORD(input: any) {
  return yourLogic(input);
}
```

### 类型脚本和 JavaScript 支持

-   完整类型脚本类型定义
-   使用ES模块和通用JS的工程
-   浏览器和节点相容
-   支持同步/等待

### 软件包导出

平方位- ts 为不同的使用例提供多导入路径:

```typescript
// Main package - Core interpreter and standard library (works everywhere)
import { Interpreter, DecoratedModule, Word } from '@forthix/forthic';

// WebSocket support - Browser-compatible multi-runtime execution
import { ActionCableClient, WebSocketRemoteModule } from '@forthix/forthic/websocket';

// JSON-RPC support - Node.js-only multi-runtime execution
import { JsonRpcClient, RemoteModule, startJsonRpcServer } from '@forthix/forthic/jsonrpc';
```

**环境相容性**数字 :

-   **主要软件包** (单位:千美元)`@forthix/forthic`: 在节点J和浏览器中工作
-   **网络安全套** (单位:千美元)`@forthix/forthic/websocket`: 在节点J和浏览器中工作
-   **JSON-RPC 软件公司** (单位:千美元)`@forthix/forthic/jsonrpc`: 仅节点.js(使用) `http` 全球 `fetch`(中文(简体) )

* * *

## 文档

### 学习资源

-   **[extix.com (英语)](https://forthix.com/)** - 了解福特和分类编码
-   **[编码器的类别理论](https://forthix.com/blog/category-theory-for-the-rest-of-us-coders)** - 了解基础

### 此运行时间

-   **[开始](https://npmcn.com/package/%40forthix/forthic/docs/getting-started.md)** - TypeScript特定设置
-   **[模块 API 参考](https://npmcn.com/package/%40forthix/forthic/docs/modules/)** - 标准图书馆文件
-   **[实例](https://npmcn.com/package/%40forthix/forthic/examples/)** - 工作代码样本

### 核心福特概念

-   **[主福特医生](https://github.com/forthix/forthic)** - 哲学、语言指南
-   **[为什么是福斯克?](https://github.com/forthix/forthic/blob/main/docs/why-forthic.md)** - 动机和核心原则
-   **[类别理论](https://github.com/forthix/forthic/blob/main/docs/language/category-theory.md)** - 数学基础
-   **[建构模块](https://github.com/forthix/forthic/blob/main/docs/tutorials/building-modules.md)** - 模块创建模式

* * *

## 实例

参见 [实例](https://npmcn.com/package/%40forthix/forthic/examples/) 目录.

* * *

## 大楼

```bash
# Install dependencies
npm install

# Build both CJS and ESM
npm run build

# Run tests
npm test

# Generate documentation
npm run docs:build
```

* * *

## 多次运行

从其他语言运行时无缝调用代码 - 从TypeScript调用Python的熊猫,或者从Ruby调用TypeScript的fs模块.

### 快速示例

```typescript
import { Interpreter } from '@forthix/forthic';
import { JsonRpcClient, RemoteModule } from '@forthix/forthic/jsonrpc';

const interp = new Interpreter();

// Connect to Python runtime
const client = new JsonRpcClient('localhost:8765');
const pandas = new RemoteModule('pandas', client, 'python');
await pandas.initialize();

interp.register_module(pandas);

// Now use Python pandas from TypeScript!
await interp.run(`["pandas"] USE-MODULES  [records] DF-FROM-RECORDS`);
```

### 方针

-   **JSON-RPC 软件公司** - Node.js QQ Python Ruby(服务器对服务器,没有本地依赖)
-   **网络安全套** - 浏览器QQ铁路(ActionCable,客户端-服务器)

### 学习更多

📖 **[完成多运行文档](https://npmcn.com/package/%40forthix/forthic/docs/multi-runtime/)**

-   **[概览](https://npmcn.com/package/%40forthix/forthic/docs/multi-runtime/)** - 何时以及如何使用多跑时间
-   **[JSON-RPC 设置](https://npmcn.com/package/%40forthix/forthic/docs/multi-runtime/jsonrpc.md)** - 服务器和客户端配置
-   **[WebSocket 设置](https://npmcn.com/package/%40forthix/forthic/docs/multi-runtime/websocket.md)** - 与浏览器兼容的通信
-   **[配置](https://npmcn.com/package/%40forthix/forthic/docs/multi-runtime/configuration.md)** - YAML 配置和连接管理
-   **[实例](https://npmcn.com/package/%40forthix/forthic/examples/)** - 工作代码样本(05-jsonrpc-server.ts,06-jsonrpc-client.ts)

**运行时状态 :** QQ TypeScript, Python, Ruby QQ rust QQ Java, .NET (英语)

* * *

## 捐款

我们欢迎捐款! 见 [捐款额](https://npmcn.com/package/%40forthix/forthic/CONTRIBUTING.md) 用于:

-   开发设置
-   类型脚本编码标准
-   测试准则
-   公关程序

另见 [主要福特贡献指南](https://github.com/forthix/forthic/blob/main/CONTRIBUTING.md) 哲学和社区准则.

* * *

## 社区

-   **主仓库 :** [平方正弦/正弦](https://github.com/forthix/forthic)
-   **问题:** [报告问题](https://github.com/forthix/forthic-ts/issues)
-   **讨论:** [GitHub 讨论](https://github.com/forthix/forthic-ts/discussions)
-   **实例:** [现实世界应用](https://github.com/forthix/forthic-ts#examples)

* * *

## 许可证

[BSD-2- 休闲许可证](https://npmcn.com/package/%40forthix/forthic/LICENSE) - 版权2024 LinkedIn Corporation. 版权2025Forthix LLC.

* * *

## 相关

-   **[福特克 (主还原)](https://github.com/forthix/forthic)** - 核心文件和概念

* * *

**福尔特**: 包装. 作曲. 摘要.

## 常见问题

### @forthix/forthic 是什么？

基于堆叠的,可相容的变换语言 - TypeScript/JavaScript 运行时间

### 如何安装 @forthix/forthic？

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

### @forthix/forthic 支持 TypeScript 吗？

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

### @forthix/forthic 支持 ESM 还是 CommonJS？

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

### @forthix/forthic 需要什么版本的 Node\.js？

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

### @forthix/forthic 可以商用吗？

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

### @forthix/forthic 的下载量有多少？

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

### @forthix/forthic 还在维护吗？

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

