Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

establish convention for use of constants #25

Open
boneskull opened this issue Jul 17, 2019 · 2 comments
Open

establish convention for use of constants #25

boneskull opened this issue Jul 17, 2019 · 2 comments
Assignees
Labels
chore Related to tests, packaging, build, releases, etc.

Comments

@boneskull
Copy link
Contributor

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 boneskull added the chore Related to tests, packaging, build, releases, etc. label Jul 17, 2019
@boneskull boneskull self-assigned this Jul 17, 2019
@boneskull
Copy link
Contributor Author

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
Copy link
Contributor Author

I like constants.js using named exports for the constants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Related to tests, packaging, build, releases, etc.
Projects
None yet
Development

No branches or pull requests

1 participant