Skip to content

Commit 04ccc25

Browse files
author
Benjamin E. Coe
authored
feat: make require("cliui") work as expected for CJS (#171)
1 parent 060b73e commit 04ccc25

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

README.md

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ easily create complex multi-column command-line-interfaces.
99

1010
## Example
1111

12+
```bash
13+
npm i cliui@latest chalk@latest
14+
```
15+
1216
```js
1317
const ui = require('cliui')()
18+
const {Chalk} = require('chalk');
19+
const chalk = new Chalk();
1420

1521
ui.div('Usage: $0 [command] [options]')
1622

@@ -46,7 +52,9 @@ As of `v7` `cliui` supports [Deno](https://github.com/denoland/deno) and
4652
[ESM](https://nodejs.org/api/esm.html#esm_ecmascript_modules):
4753

4854
```typescript
49-
import cliui from "https://deno.land/x/cliui/deno.ts";
55+
import cliui from "cliui";
56+
import chalk from "chalk";
57+
// Deno: import cliui from "https://deno.land/x/cliui/deno.ts";
5058

5159
const ui = cliui({})
5260

@@ -57,11 +65,23 @@ ui.div({
5765
padding: [2, 0, 1, 0]
5866
})
5967

60-
ui.div({
61-
text: "-f, --file",
62-
width: 20,
63-
padding: [0, 4, 0, 4]
64-
})
68+
ui.div(
69+
{
70+
text: "-f, --file",
71+
width: 20,
72+
padding: [0, 4, 0, 4]
73+
},
74+
{
75+
text: "the file to load." +
76+
chalk.green("(if this description is long it wraps).")
77+
,
78+
width: 20
79+
},
80+
{
81+
text: chalk.red("[required]"),
82+
align: 'right'
83+
}
84+
)
6585

6686
console.log(ui.toString())
6787
```

index.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ export default function ui (opts) {
1111
wrap: wrapAnsi
1212
})
1313
}
14+
15+
export {ui as 'module.exports'};

0 commit comments

Comments
 (0)