Using the Enumify library.
I want to document the enums I create, e.g.,
import { Enum } from 'enumify';
class CMD extends Enum {};
CMD.initEnum({
REBOOT: { byte: 0x00 },
SLEEP: { byte: 0x01 },
});
export default CMD;
In mainline code they're accessed like this:
import CMD from './command';
console.log(CMD.REBOOT);
Since the enums are attached to CMD
, and created during the initEnum
call,
there's no way to embed the definition inside the creation.
The only workaround I've been able to come up with is to pull out the values,
document each const
, and use the values in initEnum
:
/** Some doc */
const REBOOT = { byte: 0x00 };
/** More doc */
const SLEEP = { byte: 0x01 };
CMD.initEnum({
REBOOT,
SLEEP,
});
This isn't awful, but it does not make the hierarchy clear, e.g., it's CMD.REBOOT to the outside world.
Using @name
fails because I cannot embed the enum's "container" in the name
without quoting it, and quotes show up in the docs. I also have to tag it with
something that it really isn't so JSDoc knows how to document it:
/**
* @name 'CMD.REBOOT'
* @global
*/
Are there any other options? I just need to indicate in the docs that they exist, preferably with low overhead since they're often just simple values that we don't even care about.