knitwork-x
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseknitwork-x provides programmatic code generation for JavaScript and TypeScript. It is forked from knitwork and adds comprehensive TypeScript helpers: ESM (import/export), strings, variables, classes, interfaces, functions, types, control flow (if/try/loop/switch), and serialization (object/array/map/set). All functions return strings suitable for splicing into source; they are pure and do not mutate inputs.
gen*Use this skill when an agent needs to generate code strings (e.g. for codegen tools, plugins, or dynamic module output).
knitwork-x 提供程序化代码生成能力,支持JavaScript和TypeScript。它是从knitwork分叉而来,并新增了全面的TypeScript辅助功能:ESM(导入/导出)、字符串、变量、类、接口、函数、类型、控制流(if/try/循环/switch)以及序列化(对象/数组/映射/集合)。所有函数都返回适合嵌入源码的字符串;它们是纯函数,不会修改输入内容。
gen*当Agent需要生成代码字符串时(例如用于代码生成工具、插件或动态模块输出),可以使用此技能。
Core References
核心参考
| Topic | Description | Reference |
|---|---|---|
| Overview | Purpose, install, when to use | core-overview |
| ESM | Import, export, default export, dynamic import | core-esm |
| String | genString, escapeString, genTemplateLiteral | core-string |
| Variable | genVariable, genVariableName | core-variable |
| Design Guidelines | Naming, params, options (for contributors) | core-design-guidelines |
| 主题 | 描述 | 参考链接 |
|---|---|---|
| 概述 | 用途、安装方法、适用场景 | core-overview |
| ESM | 导入、导出、默认导出、动态导入 | core-esm |
| 字符串 | genString、escapeString、genTemplateLiteral | core-string |
| 变量 | genVariable、genVariableName | core-variable |
| 设计指南 | 命名规范、参数、选项(面向贡献者) | core-design-guidelines |
Features
功能特性
| Topic | Description | Reference |
|---|---|---|
| Class | genClass, genConstructor, genProperty, genMethod, getter/setter | features-class |
| Interface | genInterface, genIndexSignature | features-interface |
| Enum | genEnum, genConstEnum | features-enum |
| Function | genFunction, genArrowFunction, genBlock, genParam | features-function |
| Type | genTypeAlias, genUnion, genIntersection, genMappedType, etc. | features-type |
| Conditional | genConditionalType, genTernary | features-conditional |
| Decorator | genDecorator | features-decorator |
| Module & Namespace | genModule, genNamespace, genDeclareNamespace | features-module-namespace |
| Condition | genIf, genElse, genElseIf | features-condition |
| Try | genTry, genCatch, genFinally | features-try |
| Loop | genFor, genForOf, genWhile, genDoWhile | features-loop |
| Switch | genSwitch, genCase, genDefault | features-switch |
| Statement | genReturn, genThrow, genPrefixedBlock | features-statement |
| Object & Serialization | genObject, genArray, genMap, genSet, genTypeObject | features-object |
| Utils | genComment, genKey, genLiteral, genRegExp, wrapInDelimiters | features-utils |
| 主题 | 描述 | 参考链接 |
|---|---|---|
| 类 | genClass、genConstructor、genProperty、genMethod、getter/setter | features-class |
| 接口 | genInterface、genIndexSignature | features-interface |
| 枚举 | genEnum、genConstEnum | features-enum |
| 函数 | genFunction、genArrowFunction、genBlock、genParam | features-function |
| 类型 | genTypeAlias、genUnion、genIntersection、genMappedType等 | features-type |
| 条件类型 | genConditionalType、genTernary | features-conditional |
| 装饰器 | genDecorator | features-decorator |
| 模块与命名空间 | genModule、genNamespace、genDeclareNamespace | features-module-namespace |
| 条件语句 | genIf、genElse、genElseIf | features-condition |
| 异常处理 | genTry、genCatch、genFinally | features-try |
| 循环语句 | genFor、genForOf、genWhile、genDoWhile | features-loop |
| 分支语句 | genSwitch、genCase、genDefault | features-switch |
| 基础语句 | genReturn、genThrow、genPrefixedBlock | features-statement |
| 对象与序列化 | genObject、genArray、genMap、genSet、genTypeObject | features-object |
| 工具函数 | genComment、genKey、genLiteral、genRegExp、wrapInDelimiters | features-utils |
Key Points
关键要点
- Return type: Every function returns a
gen*(code fragment).string - Options: Most accept an optional object (e.g.
options,export,singleQuotes); default toindent.{} - Indent: When supported, pass as the last parameter; use
indentfor nested blocks.indent + " " - Strings: Use for quoted/escaped output so
genString(input, options)is respected.singleQuotes - Composing: Combine outputs (e.g.
gen*) to build larger snippets.genClass(..., [genConstructor(...)])
- 返回类型: 每个函数都返回一个
gen*(代码片段)。string - 选项配置: 大多数函数接受可选的对象(例如
options、export、singleQuotes);默认值为indent。{} - 缩进处理: 当支持缩进时,将作为最后一个参数传入;嵌套块使用
indent。indent + " " - 字符串处理: 使用生成带引号/转义的输出,以遵循
genString(input, options)配置。singleQuotes - 组合使用: 可以拼接多个函数的输出(例如
gen*)来构建更大的代码片段。genClass(..., [genConstructor(...)])