knitwork-x

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
knitwork-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
gen*
functions return strings suitable for splicing into source; they are pure and do not mutate inputs.
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

核心参考

TopicDescriptionReference
OverviewPurpose, install, when to usecore-overview
ESMImport, export, default export, dynamic importcore-esm
StringgenString, escapeString, genTemplateLiteralcore-string
VariablegenVariable, genVariableNamecore-variable
Design GuidelinesNaming, params, options (for contributors)core-design-guidelines
主题描述参考链接
概述用途、安装方法、适用场景core-overview
ESM导入、导出、默认导出、动态导入core-esm
字符串genString、escapeString、genTemplateLiteralcore-string
变量genVariable、genVariableNamecore-variable
设计指南命名规范、参数、选项(面向贡献者)core-design-guidelines

Features

功能特性

TopicDescriptionReference
ClassgenClass, genConstructor, genProperty, genMethod, getter/setterfeatures-class
InterfacegenInterface, genIndexSignaturefeatures-interface
EnumgenEnum, genConstEnumfeatures-enum
FunctiongenFunction, genArrowFunction, genBlock, genParamfeatures-function
TypegenTypeAlias, genUnion, genIntersection, genMappedType, etc.features-type
ConditionalgenConditionalType, genTernaryfeatures-conditional
DecoratorgenDecoratorfeatures-decorator
Module & NamespacegenModule, genNamespace, genDeclareNamespacefeatures-module-namespace
ConditiongenIf, genElse, genElseIffeatures-condition
TrygenTry, genCatch, genFinallyfeatures-try
LoopgenFor, genForOf, genWhile, genDoWhilefeatures-loop
SwitchgenSwitch, genCase, genDefaultfeatures-switch
StatementgenReturn, genThrow, genPrefixedBlockfeatures-statement
Object & SerializationgenObject, genArray, genMap, genSet, genTypeObjectfeatures-object
UtilsgenComment, genKey, genLiteral, genRegExp, wrapInDelimitersfeatures-utils
主题描述参考链接
genClass、genConstructor、genProperty、genMethod、getter/setterfeatures-class
接口genInterface、genIndexSignaturefeatures-interface
枚举genEnum、genConstEnumfeatures-enum
函数genFunction、genArrowFunction、genBlock、genParamfeatures-function
类型genTypeAlias、genUnion、genIntersection、genMappedType等features-type
条件类型genConditionalType、genTernaryfeatures-conditional
装饰器genDecoratorfeatures-decorator
模块与命名空间genModule、genNamespace、genDeclareNamespacefeatures-module-namespace
条件语句genIf、genElse、genElseIffeatures-condition
异常处理genTry、genCatch、genFinallyfeatures-try
循环语句genFor、genForOf、genWhile、genDoWhilefeatures-loop
分支语句genSwitch、genCase、genDefaultfeatures-switch
基础语句genReturn、genThrow、genPrefixedBlockfeatures-statement
对象与序列化genObject、genArray、genMap、genSet、genTypeObjectfeatures-object
工具函数genComment、genKey、genLiteral、genRegExp、wrapInDelimitersfeatures-utils

Key Points

关键要点

  • Return type: Every
    gen*
    function returns a
    string
    (code fragment).
  • Options: Most accept an optional
    options
    object (e.g.
    export
    ,
    singleQuotes
    ,
    indent
    ); default to
    {}
    .
  • Indent: When supported, pass
    indent
    as the last parameter; use
    indent + "  "
    for nested blocks.
  • Strings: Use
    genString(input, options)
    for quoted/escaped output so
    singleQuotes
    is respected.
  • Composing: Combine
    gen*
    outputs (e.g.
    genClass(..., [genConstructor(...)])
    ) to build larger snippets.
  • 返回类型: 每个
    gen*
    函数都返回一个
    string
    (代码片段)。
  • 选项配置: 大多数函数接受可选的
    options
    对象(例如
    export
    singleQuotes
    indent
    );默认值为
    {}
  • 缩进处理: 当支持缩进时,将
    indent
    作为最后一个参数传入;嵌套块使用
    indent + "  "
  • 字符串处理: 使用
    genString(input, options)
    生成带引号/转义的输出,以遵循
    singleQuotes
    配置。
  • 组合使用: 可以拼接多个
    gen*
    函数的输出(例如
    genClass(..., [genConstructor(...)])
    )来构建更大的代码片段。