# @danielx/civet 中文文档

规范地址：https://npmcn.com/package/%40danielx/civet/

版本：0\.11\.16
npm 元数据更新时间：2026-08-22T07:19:29.967Z
中文译文更新时间：2026-11-11T10:42:35.468Z
软件包许可：MIT

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

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

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

- 包体积（解压后）：6.1 MB，55 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=19 \|\| ^18\.6\.0 \|\| ^16\.17\.0
- 运行依赖：2 个
- peer 依赖：@danielx/hera ^0\.9\.8，typescript \>=4\.5，yaml ^2\.4\.5
- 首次发布：2022-08-23T18:51:20.572Z
- 最新版本发布：2026-08-22T07:19:29.615Z
- 近 30 天下载量：5854（2026-10-12 至 2026-11-10，npm 官方下载统计）
- 已发布版本数：368（近 12 个月 16 个）

## 中文简介

CoffeeScript 类型样式语法

## 安装

```sh
npm install @danielx/civet
```

也可以使用：`pnpm add @danielx/civet`、`yarn add @danielx/civet`、`bun add @danielx/civet`

## README

# 密码

[![Build Status](https://img.shields.io/github/actions/workflow/status/DanielXMoore/Civet/build.yml?branch=main&logo=github&style=for-the-badge)](https://github.com/DanielXMoore/Civet/actions/workflows/build.yml) [![NPM Version](https://img.shields.io/npm/v/@danielx/civet.svg?style=for-the-badge)](https://www.npmjs.com/package/@danielx/civet) [![NPM Downloads](https://img.shields.io/npm/dm/@danielx/civet.svg?style=for-the-badge)](https://www.npmjs.com/package/@danielx/civet) [![Coverage Status](https://img.shields.io/codecov/c/github/DanielXMoore/Civet/main?style=for-the-badge&logo=codecov)](https://codecov.io/gh/DanielXMoore/Civet) [![Discord](https://img.shields.io/discord/933472021310996512?style=for-the-badge)](https://discord.com/invite/xkrW9GebBc) [![Open Collective](https://img.shields.io/opencollective/all/civet?style=for-the-badge)](https://opencollective.com/civet)

现代写作TypeScript的方法.

-   [文档](https://civet.dev/)
-   [更改日志](https://npmcn.com/package/%40danielx/civet/CHANGELOG.md)
-   [设计哲学](https://civet.dev/philosophy)
-   [Civet 游戏场](https://civet.dev/playground)
-   [Civet VSCode 扩展](https://marketplace.visualstudio.com/items?itemName=DanielX.civet)
-   [Discord 服务器](https://discord.gg/xkrW9GebBc)
-   用于 [维特、斯库特、阿斯特罗、农场、倒塌、倒塌、倒塌、网络包装](https://npmcn.com/package/%40danielx/civet/source/unplugin), (中文(简体) ), [无害环境管理/CJS装载器](https://npmcn.com/package/%40danielx/civet/source/esm.civet), (中文(简体) ), [宝贝](https://npmcn.com/package/%40danielx/civet/source/babel-plugin.civet), (中文(简体) ), [欢乐](https://github.com/DanielXMoore/Civet/blob/main/integration/jest), (中文(简体) ), [古尔普](https://npmcn.com/package/%40danielx/civet/integration/gulp), (中文(简体) ), [阿宝](https://npmcn.com/package/%40danielx/civet/source/bun-civet.civet), (中文(简体) ), [`<script>` 标签](https://github.com/DanielXMoore/Civet/tree/main/integration/script)
-   启动模板 [固态](https://github.com/edemaine/civet-solid-vite-template) (单位:千美元)[年龄](https://github.com/orenelbaum/solid-civet-template)和 [固态启动](https://github.com/orenelbaum/solid-start-civet-template)

## 快速启动指南

```bash
# Install
npm install -g @danielx/civet
# Run Civet code directly in a REPL
civet
# Transpile typed Civet code into TypeScript in a REPL
civet -c
# Compile Civet source file to TypeScript
civet < source.civet > output.ts
# Execute a .civet script
civet source.civet ...args...
# Execute a .civet source file in node
node --import @danielx/civet/register source.civet
# Type check entire project, which requires TypeScript installed
npm install -g typescript
civet --typecheck
```

![image](https://user-images.githubusercontent.com/18894/184558519-b675a903-7490-43ba-883e-0d8addacd4b9.png)

## 代码样本

```typescript
ts, {CompilerOptions} from typescript

DefaultCompilerOptions : CompilerOptions :=
  allowNonTsExtensions: true
  allowJs: true
  target: ts.ScriptTarget.Latest
  moduleResolution: ts.ModuleResolutionKind.NodeJs
  module: ts.ModuleKind.CommonJS
  allowSyntheticDefaultImports: true
  experimentalDecorators: true

fileCache : Record<string, any> := {}

createCompilerHost := (options: CompilerOptions, moduleSearchLocations : string[]) ->
  fileExists := (fileName: string) : boolean ->
    fileCache[fileName]?

  readFile := (fileName: string) ->
    fileCache[fileName]
```

## 概览

Civet本质上是TypeScript的一款有品味的超级集.

### 新的和拟议的环境科学特征的执行情况

见 [文档](https://civet.dev/) 实例 和其他特征.

-   模式匹配(基于 [TC39提案](https://github.com/tc39/proposal-pattern-matching)(中文(简体) )
    -   `switch` 能够匹配模式,例如 `[{type: "text", name}, ...rest]`
-   管道运算符(基于 [F# 管道](https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/symbol-and-operator-reference/#function-symbols-and-operators), (中文(简体) ), [垃圾管道](https://docs.hhvm.com/hack/expressions-and-operators/pipe) 编辑 [TC39提案](https://github.com/tc39/proposal-pipeline-operator)(中文(简体) )
    -   `data |> Object.keys |> console.log` 等值为 `console.log(Object.keys(data))`
    -   使用单参数箭头函数或 `&` 手写 指定如何使用左侧
    -   `|> await`, (中文(简体) ), `|> yield`,以及 `|> return` (期末) 用于左侧包装操作
-   短函数块语法 [Ruby 符号到 proc](https://ruby-doc.org/core-3.1.2/Symbol.html#method-i-to_proc), (中文(简体) ), [晶体](https://crystal-lang.org/reference/1.6/syntax_and_semantics/blocks_and_procs.html#short-one-parameter-syntax), (中文(简体) ), [榆树记录访问](https://elm-lang.org/docs/records#access)
    -   访问 : `x.map &.name` 或者说 `x.map .name` → `x.map(a => a.name)`
    -   嵌入式访问+切片 : `x.map &.profile?.name[0...3]` → `x.map(a => a.profile?.name.slice(0, 3))`
    -   函数调用 : `x.map &.callback a, b` → `x.map($ => $.callback(a, b))`
    -   一元运算符 : `x.map !!&` → `x.map($ => !!$)`
    -   二进制运算符 : `x.map &+1` → `x.map($ => $+1)`
-   对象字面缩写
    -   `{foo()}` → `{foo: foo()}`, (中文(简体) ), `{props.foo}` → `{foo: props.foo}`
    -   ``{`${x}${y}`: z}`` → ``{[`${x}${y}`]: z}``
    -   `data.{x,y}` 或者说 `data{x,y}` → `{x: data.x, y: data.y}`
    -   以 [从 Live 脚本](https://livescript.net/#literals-objects)数字 : `{+debug, -live, !verbose}` → `{debug: true, live: false, verbose: false}`
-   自定义任何双参数函数的内插运算符
-   `do` 表达式, `if` 表达式, `for` 表达式

### ES6+的方便使用 特征

-   Const 任务简写 : `a := b` → `const a = b`, (中文(简体) ), `{a, b} := c` → `const {a, b} = c`
-   让任务简短: `a .= b` → `let a = b`
-   上述类型版本: `a: number .= 5` → `let a: number = 5` (但请注意 `a: number = 5` 是对象的正文 `{a: (number = 5)}`) (中文(简体) ).
-   `@#id` → `this.#id` 私人标识符的缩写
-   `import` 手写 : `x from ./x` → `import x from "./x"`
-   动态 `import` 手写 : `import './x'` 非顶级 (例如:. `await import './x'` (或功能内) `import('./x')`
-   可选导入重命名对应去结构重命名的语法 `import {x: y} from "./z"` → `import {x as y} from "./z"`。你还可以 使用情况 `as` 与现有的ES进口相容.
-   `export` 手写 : `export x, y` → `export {x, y}`
-   三重回击模板字符串删除前缀以清晰
-   类构造快手 `@( ... )`
-   类Static 锁 `@ { ... }`
-   `<` 作为 `extends` 手写
-   `///` 块正则Exp [就像Python re.X一样](https://docs.python.org/3/library/re.html#re.X)

### JSX 加强

灵感来自 [固态讨论](https://github.com/solidjs-community/solid-dsl/discussions) 财务报告和审定财务报表 [jsx 规格问题](https://github.com/facebook/jsx/issues)

-   缩进: 而不是明确关闭 `<tag>`s 或 (简体中文) `<>`s, (中文(简体) ), 你可以缩进孩子们 赛维特会帮你关上标签
-   多个相邻元素和/或碎片自动获得 结合成碎片.
-   箭头函数子不需要用括号来包裹 (假定它们之前没有案文);这是明确的,因为 `>` 无效的JSX文本。 譬如说, `<For> (item) => ...` (其中函数正体可以缩入).
-   `#foo` 缩写 `id="foo"`· ; (单位:千美元) `#"foo bar"`, (中文(简体) ), `` #`foo ${bar}` ``, (中文(简体) ), `#{expr}`
-   `.foo` 缩写 `class="foo"` (但必须在 标签名称);以及 `.foo.bar`, (中文(简体) ), `."foo bar"`, (中文(简体) ), `` .`foo ${bar}` ``, (中文(简体) ), `.{expr}`
    -   `"civet react"` 旗帜使用 `className` 改为 `class`
-   `+foo` 缩写 `foo={true}`, (中文(简体) ), `-foo`编号 :`!foo` 缩写 `foo={false}`
-   任何被绑定的对象文字都可以用作属性: `{foo}` → `foo={foo}`, (中文(简体) ), `{foo: bar}` → `foo={bar}`, (中文(简体) ), `{...foo}` 保持原样; 方法和获得者/制定者也发挥作用.
-   属性 `...foo` 缩写 `{...foo}`
-   没有空白或适当包裹的属性值 (括号大小表达式、字符串和模板字符串, 正则表达式,数组字元,被绑定的对象字元) 不需要牙套 : `foo=bar` → `foo={bar}`, (中文(简体) ), `count=count()` → `count={count()}`, (中文(简体) ), `sum=x+1` → `sum={x+1}`, (中文(简体) ), `list=[1, 2, 3]` → `list={[1, 2, 3]}`
-   属性可以使用计算属性名称: `[expr]={value}` → `{...{[expr]: value}}`
-   `"civet solid"` 旗帜为JSX元素和碎片添加了正确的类型. 使用 `"civet solid client"` (默认)只针对客户端代码, `"civet solid server"` 仅用于服务器代码(仅限SSR),或 `"civet solid client server"` 用于运行的同位素代码 客户端和服务器(SSR + 水合).
-   XML 注释 : `<!-- ... -->` → `{/* ... */}`

### 类型脚本增强

-   自动重写 `.[mc]ts` → `.[mc]js` 进口额(为: [https://github.com/microsoft/TypeScript/issues/37582 互联网档案馆的存檔,存档日期2013-12-21](https://github.com/microsoft/TypeScript/issues/37582)(中文(简体) )
-   `:=` 只读类字段初始化器
    
    ```typescript
      class A
        x := 3
    ```
    
    ```typescript
      class A {
        readonly x = 3
      }
    ```
    
-   建议: [已键入结构](https://github.com/DanielXMoore/Civet/discussions/126)
-   建议: [类型标记](https://github.com/DanielXMoore/Civet/discussions/190)
-   建议: [模块接口](https://github.com/DanielXMoore/Civet/discussions/179) [https://github.com/microsoft/TypeScript/issues/38511 互联网档案馆的存檔,存档日期2013-12-21](https://github.com/microsoft/TypeScript/issues/38511)
-   东都: [声明类型](https://github.com/DanielXMoore/Civet/issues/176)

### ES6的变化

-   隐性返回,即使用于多报表函数 (通过指定 `void` 返回类型,添加后缀 `;` 或者说 明确 `return`,或通过指令 `"civet -implicitReturns"`(中文(简体) )
-   取消对单个参数箭头函数的描述 . `x => ...` 必须是 `(x) => ...` 理由是 `x -> ...` => `x(function() ...)` 在 Coffee 脚本和有 `->` 财务报告和审定财务报表 `=>` 行为比他们已经做的更不同是坏的。 将匿名功能传递给 应用没有参数也是方便的.
-   `for(i of x) ...` 默认声明 `for(const i of x) ...`
-   在条件和许多其他地方取消逗号运算符. `if x, y` 不允许。 不过 `for i = 0, l = a.length; i < l; i++, i *= 2` 允许.
-   逗号运算符在 `case`编号 :`when` 反而变成了多重条件.
-   数字不能以点结尾( 否则会与 CoffeeScript 切片模糊) `y[0..x]`) (中文(简体) ). 这也意味着你不能访问属性 数字 `1..toString()` 使用情况 `1.toString()` 换句话说 当责任人跟随一个点时,它就被当作财产进入,因为责任人 可能是有效的财产 `1.e10` → `1..e10`。工作范围是添加后零 `1.0e10` 或删除 expresent 之前的点 `1e10`。 。 。 .
-   其他保留词 `and`, (中文(简体) ), `or`, (中文(简体) ), `loop`, (中文(简体) ), `until`, (中文(简体) ), `unless`
-   实验装饰语法是 `@@` 改为 `@` 因为 `@` 溢价不动产,以及 `@id` → `this.id`,以及 `@` 也是静态场/方法等.
    
    ```
    @@classDecorator
    class X
      @@methodDecorator
      method() {}
    ```
    
-   `when` 内切换自动断开并添加块范围.
-   `else` 内部开关增加了块范围.
-   无效操作符和操作符之间没有空白 。 条件和三分之一之间的强制空白 `?` 前辈. `x ? a : b` 自此以来 `x?` 是非活性运算符.
-   已写入标签 `:label` (特殊情况除外) `$:` 用于斯维尔特)

### 脚本改进

-   Shebang 行在输出中保持未修改
    
    ```civet
    #!./node_modules/.bin/ts-node
    console.log "hi"
    ```
    

### 与 Coffee 脚本的比较

看看这个 [详细 Civet // CoffeeScript 比较](https://npmcn.com/package/%40danielx/civet/notes/Comparison-to-CoffeeScript.md)

### 指令

Civet不仅仅是一种语言;它可以多种方式配置 通过指令添加或去除语言特征,或改善行为 在某些环境中. 见 [配置文档](https://civet.dev/config)。 。 。 .

### 在您的节点环境中使用 Civet

您现在已经确信 Civet 适合您的当前/下一个项目 。 是这样的 来创造你的环境 立即生产 并有一个良好的时间SM.

### 测试

代码覆盖 [c8 (单位:千美元)](https://github.com/bcoe/c8) 感谢他们的原始地图 集成和Civet的源地图.

#### c8 + 莫查语

`package.json`

```json
  "scripts": {
    "test": "c8 mocha",
    ...
  },
  "c8": {
    "extension": [
      ".civet"
    ]
  },
  "mocha": {
    "extension": [
      "civet"
    ],
    "loader": [
      "@danielx/civet/esm"
    ],
    ...
  ...
```

如果你不关心代码覆盖,你可以跳过c8(但是这太容易了,为什么不保留它?).

您还可以添加 `.js` 财务报告和审定财务报表 `.ts` 如果您想要混合和匹配, 则扩展 ! 连 `.coffee` 需要的话会工作 `coffeescript/register` 或为此增加一个装载器.

执行测试

```bash
pnpm test
```

步骤4:享受!

### 发展中国家

使用 Alpha 版本的 [Civet 语言服务器](https://marketplace.visualstudio.com/items?itemName=DanielX.civet)

语言服务器提供语法加亮,补全,悬浮文档,符号大纲,红色qui,并去定义.

* * *

_问?_ 为什么我不能只使用内置的VSCode TypeScript LSP?

_问:_ VSCode 建于 TypeScript LSP 无法解决非 `.ts/.js`,甚至没有插件。 也许有一天他们会允许 让您调整解析器并插入转接步骤的插件,但在此之前需要单独的语言服务器.

* * *

_问?_ 有时文件大纲会消失 红色的松鼠都跑错地方了 也许会发出通知 关于某种LSP错误.

_问:_ 很遗憾发生了这种事 但西维特语言服务器仍然在快速改进 请告诉我 到底发生了什么 我下次会努力做得更好.

当您的 Civet 文件出现语法错误时, 可能会发生这种情况 。 您可以检查并检查它是否同时使用 CLI 工具编译 .

请提交错误报告/ 特性请求 .

### 大楼

我强烈建议使用 [兴建](https://esbuild.github.io/) 用于构建/包装您的 Civet 项目.

```javascript
import esbuild from 'esbuild'
import civetPlugin from '@danielx/civet/esbuild'

esbuild.build({
  ...,
  plugins: [
    civetPlugin({ ts: 'preserve' })
  ]
}).catch(() => process.exit(1))
```

超快的,很厉害!

## 赞助

如果你这么倾向,你可以赞助Civet on [开放集体](https://opencollective.com/civet)。 。 。 .

## 常见问题

### @danielx/civet 是什么？

CoffeeScript 类型样式语法

### 如何安装 @danielx/civet？

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

### @danielx/civet 支持 TypeScript 吗？

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

### @danielx/civet 支持 ESM 还是 CommonJS？

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

### @danielx/civet 需要什么版本的 Node\.js？

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

### @danielx/civet 可以商用吗？

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

### @danielx/civet 的下载量有多少？

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

### @danielx/civet 还在维护吗？

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

