export.js: Export in all CommonJS environments

Closes #521
Is it possible to extract this into a (factory) function that uses less tertiaries and boolean grouping, to make the thing more readable?