IBM / report-toolkit

A toolkit for consumers of Node.js diagnostic Reports
https://ibm.github.io/report-toolkit
Other
84 stars 10 forks source link

establish convention for use of constants #25

Open boneskull opened 5 years ago

boneskull commented 5 years ago

Various packages have constants in them, and they should all export these in a similar shape.

It's absolutely useful to be able to iterate over a set of constants exported from a package. For example, names of formatters or transformers. If a package has a single entry point, then constants-as-named-exports won't get us there, because those exports may not all be constants!

I'm thinking this should be sufficient:

/**
 * @enum {string}
 */
export const constants = {
  FOO: 'foo',
  BAR: 'bar',
  BAZ: 'baz'
};

A consumer can:

import {constants as fooConstants} from '@report-toolkit/foo';
boneskull commented 5 years ago

all constants should be in a file called constants.js and re-exported from src/index.js; otherwise we are likely to introduce cyclic dependencies, which Rollup is not fond of

boneskull commented 5 years ago

I like constants.js using named exports for the constants