0

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.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302

1 Answers1

1

Have you tired @lends? It seems legit to document static members like that

CMD.initEnum(/** @lends CMD */{
  REBOOT: { byte: 0x00 },
  SLEEP:  { byte: 0x01 },
});
Lesha Ogonkov
  • 1,218
  • 8
  • 20
  • This seems promising--but I cannot figure out the magic incantation to avoid getting duplicate entries for both the `CMD` class (I've also tried using `@namespace`) *and* the individual members. I don't even know how many combinations I've tried, probably at least a dozen or two :( I may have to move away from JSDoc. – Dave Newton Jun 27 '18 at 15:01