Generators

jsimport


The jsimport generator generates JavaScript usage example to be imported.

Example

Input

<!-- automd:jsimport cjs cdn name="pkg" imports="foo,bar" -->
<!-- /automd -->

Output

<!-- automd:jsimport cjs cdn name="pkg" imports="foo,bar" -->

**ESM** (Node.js, Bun)

```js
import { foo, bar } from "pkg";
```

**CommonJS** (Legacy Node.js)

```js
const { foo, bar } = require("pkg");
```

**CDN** (Deno, Bun and Browsers)

```js
import { foo, bar } from "https://esm.sh/pkg";
```

<!-- /automd -->

Arguments

name
string

The package name (by default tries to read from the name field in package.json).

import/imports
string

Array or comma seperated list of export names.

no-esm
boolean

Disable ESM instructions.

cdn
boolean

Generate CDN import usage.

cjs
boolean

Generate CommonJS require usage.

src
boolean

Auto scan export names from src using unjs/mlly.

printWidth
number

The maximum length that requires wrapping lines. Default is 80