Skip to content

Commit

Permalink
Expose minimist (#661)
Browse files Browse the repository at this point in the history
* Document minmist exposure

* Expose minimist package globally

* Update package-lock

* Improve minimsit test

* Re-sort globals to be alphabetical
  • Loading branch information
LionC committed Aug 15, 2023
1 parent 497db7e commit b1ca232
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,13 @@ console.log(YAML.parse('foo: bar').foo)

### `minimist` package

The [minimist](https://www.npmjs.com/package/minimist) package available
as global const `argv`.
The [minimist](https://www.npmjs.com/package/minimist) package.

```js
let myCustomArgv = minimist(process.argv.slice(2), { boolean: ["force", "help"] })
```

A minimist-parsed version of the process args as `argv` (parsed without any config).

```js
if (argv.someFlag) {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ declare global {
var fs: typeof _.fs
var glob: typeof _.glob
var globby: typeof _.globby
var minimist: typeof _.minimist
var nothrow: typeof _.nothrow
var os: typeof _.os
var path: typeof _.path
Expand Down
1 change: 1 addition & 0 deletions src/goods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import chalk from 'chalk'
export { default as chalk } from 'chalk'
export { default as fs } from 'fs-extra'
export { default as which } from 'which'
export { default as minimist } from 'minimist'
export { default as YAML } from 'yaml'
export { default as path } from 'node:path'
export { default as os } from 'node:os'
Expand Down
19 changes: 19 additions & 0 deletions test/goods.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,25 @@ test('which() available', async () => {
assert.is(which.sync('npm'), await which('npm'))
})

test('minimist available', async () => {
assert.is(typeof minimist, 'function')
})

test('minimist works', async () => {
assert.equal(
minimist(
['--foo', 'bar', '-a', '5', '-a', '42', '--force', './some.file'],
{ boolean: 'force' }
),
{
a: [5, 42],
foo: 'bar',
force: true,
_: ['./some.file'],
}
)
})

test('sleep() works', async () => {
const now = Date.now()
await sleep(100)
Expand Down

0 comments on commit b1ca232

Please sign in to comment.