Skip to content package
knitwork v0.1.3 [![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href] [![Github Actions][github-actions-src]][github-actions-href] [![Codecov][codecov-src]][codecov-href]
node any 0 deps esm cjs types open source
overview readme
license MIT
deps 0
unpacked 20.5 kB
files 6
node any $ npm install knitwork@0.1.3n npmREADME GitHub-flavored package documentation.
downloads Across all versions.
Download trend unavailable.
compatibility Runtime metadata.
install size Estimated unpacked size across 1 packages.
40.2 kB
Includes dependencies.
versions Latest published Nov 14, 2025
maintainers Registry package owners.
contents Install ESM genDynamicImport(specifier, options) genDynamicTypeImport(specifier, name, options) genExport(specifier, exports?, options) genImport(specifier, imports?, options) genTypeImport(specifier, imports, options) Serialization genArrayFromRaw(array, indent, options) genObjectFromRaw(object, indent, options) genObjectFromRawEntries(array, indent, options) genObjectFromValues(obj, indent, options) String escapeString(id) genSafeVariableName(name) genString(input, options) Typescript genAugmentation(specifier) genInlineTypeImport(specifier, name, options) genInterface(name, contents?, options, indent) genTypeExport(specifier, imports, options) genTypeObject(object, indent) Utils genObjectKey(key) wrapInDelimiters(lines, indent, delimiters, withComma) Contribution License 🧶 knitwork
Utilities to generate JavaScript code.
Install
nypm
install
knitwork
# npm
npm install knitwork
# yarn
yarn add knitwork
# pnpm
pnpm add knitwork
# bun
bun install knitwork
# deno
deno install npm:knitwork
copy
import {} from "knitwork" ; copy CommonJS (Legacy Node.js)
const {} = require ( "knitwork" ); copy import {} from "https://esm.sh/knitwork" ; copy
ESM
genDynamicImport(specifier, options)Generate an ESM dynamic import() statement.
genDynamicTypeImport(specifier, name, options)Generate an ESM type import() statement.
genExport(specifier, exports?, options)Generate an ESM export statement.
genImport(specifier, imports?, options)Generate an ESM import statement.
genImport ( "pkg" , "foo" );
// ~> `import foo from "pkg";`
genImport ( "pkg" , [ "foo" ]);
// ~> `import { foo } from "pkg";`
genImport ( "pkg" , [ "a" , "b" ]);
// ~> `import { a, b } from "pkg`;
genImport ( "pkg" , [{ name: "default" , as: "bar" }]);
// ~> `import { default as bar } from "pkg`;
genImport ( "pkg" , [{ name: "foo" , as: "bar" }]);
// ~> `import { foo as bar } from "pkg`;
genImport ( "pkg" , "foo" , { attributes: { type: "json" } });
// ~> `import foo from "pkg" with { type: "json" };
genExport ( "pkg" , "foo" );
// ~> `export foo from "pkg";`
genExport ( "pkg" , [ "a" , "b" ]);
// ~> `export { a, b } from "pkg";`
// export * as bar from "pkg"
genExport ( "pkg" , { name: "*" , as: "bar" });
// ~> `export * as bar from "pkg";` copy
genTypeImport(specifier, imports, options)Generate an ESM import type statement.
Serialization
genArrayFromRaw(array, indent, options)Serialize an array to a string.
Values are not escaped or quoted.
genArrayFromRaw ([ 1 , 2 , 3 ])
// ~> `[1, 2, 3]` copy
genObjectFromRaw(object, indent, options)Serialize an object to a string.
Values are not escaped or quoted.
genObjectFromRaw ({ foo: "bar" , test: '() => import("pkg")' })
// ~> `{ foo: bar, test: () => import("pkg") }` copy
genObjectFromRawEntries(array, indent, options)Serialize an array of key-value pairs to a string.
Values are not escaped or quoted.
genObjectFromValues(obj, indent, options)Serialize an object to a string.
Values are escaped and quoted if necessary.
genObjectFromValues ({ foo: "bar" })
// ~> `{ foo: "bar" }` copy
String
escapeString(id)Escape a string for use in a javascript string.
genSafeVariableName(name)Generate a safe javascript variable name.
Generate a string with double or single quotes and handle escapes.
Typescript
genAugmentation(specifier)Generate typescript declare module augmentation.
genInlineTypeImport(specifier, name, options)Generate an typescript typeof import() statement for default import.
genInterface(name, contents?, options, indent)Generate typescript interface.
genTypeExport(specifier, imports, options)Generate a typescript export type statement.
genTypeObject(object, indent)Generate typescript object type.
Utils
genObjectKey(key)Generate a safe javascript variable name for an object key.
wrapInDelimiters(lines, indent, delimiters, withComma)Wrap an array of strings in delimiters.
Contribution
Local development
Clone this repository
Install the latest LTS version of Node.js
Enable Corepack using corepack enable
Install dependencies using bun install
Run tests using bun dev
License