Skip to content

Commit

Permalink
docs: Fix example of coerce (#2316)
Browse files Browse the repository at this point in the history
  • Loading branch information
regseb committed Apr 28, 2023
1 parent 0196a25 commit 731c06b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions docs/api.md
Expand Up @@ -198,11 +198,14 @@ all other modifications, such as [`.normalize()`](#normalize).
_Examples:_

```js
var argv = require('yargs/yargs')(process.argv.slice(2))
.coerce('file', function (arg) {
return await require('fs').promises.readFile(arg, 'utf8')
import { readFile } from 'node:fs/promises';
import yargs from 'yargs';
const argv = await yargs(process.argv.slice(2))
.coerce('file', async (arg) => {
const content = await readFile(arg, 'utf8');
return JSON.parse(content);
})
.argv
.parseAsync();
```

Optionally `.coerce()` can take an object that maps several keys to their
Expand Down

0 comments on commit 731c06b

Please sign in to comment.