Skip to content

Commit df97efc

Browse files
committed
add jsdoc to README
1 parent b66ac02 commit df97efc

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,40 @@
22

33
JSON configurable command-line options parser
44

5-
3.x Under developing... not tested yet
5+
3.x Under developing... not tested yet
6+
7+
```javascript
8+
/**
9+
* @typedef {string} VarKey Variable name
10+
* @typedef {string | boolean | string[]} VarVal Variable value
11+
* @typedef {string} OptStr Option string, e.g. '--', '-o', '--option'
12+
* @typedef {OptStr | null} OptDef Option definitions, e.g. '--', '-o', '--option', or `null` to refer to the variable name
13+
* @typedef {OptDef | OptDef[]} OptKit one or more option definitions
14+
*
15+
* @typedef {object} VarKit Variable configuration object
16+
* @property {VarVal} def Variable **def**inition & **def**ault value (pun intended)
17+
* @property {OptKit} [set] Array of options to set the variable value
18+
* @property {OptKit} [rst] Array of options to reset the variable value
19+
*
20+
* @typedef {OptKit} HaltKit Halt options, identical to `OptKit`, for now...
21+
* @typedef {{opt: OptStr, key: VarKey}} HaltRes
22+
* @typedef {Record<VarKey, VarKit | HaltKit>} KeyKitMap
23+
* @typedef {Record<VarKey, VarVal>} KeyValMap
24+
*
25+
* @callback CanQuit
26+
* @param {{msg: string, i: number, opt: OptStr, key?: VarKey, val?: VarVal }} err
27+
* @returns {boolean} Whether the parsing should continue (false) or quit (true)
28+
* @typedef {Record<OptStr, VarKey>} OptKeyMap internal type
29+
*/
30+
/**
31+
* Command line argument parser function
32+
* @param {string[]} argv Command line arguments array
33+
* @param {number} i Index of current argument being processed
34+
* @param {KeyKitMap} req Options structure definition
35+
* @param {KeyValMap} res Object to store parsed results
36+
* @param {CanQuit} err Error handler function
37+
* @returns {{ i: number, halt?: HaltRes }}
38+
* @example
39+
*/
40+
export default function parse(argv, i, req, res, err);
41+
```

0 commit comments

Comments
 (0)