Skip to content

Instantly share code, notes, and snippets.

@nyteshade
Created April 20, 2024 00:42
Show Gist options
  • Save nyteshade/90a90bf095fde03eda5809f1998d8c58 to your computer and use it in GitHub Desktop.
Save nyteshade/90a90bf095fde03eda5809f1998d8c58 to your computer and use it in GitHub Desktop.
Simple snippet of JavaScript to make exporting vanilla javascript easier
function ship(code) {
const _ne = Object.entries(code)
.reduce((a, [k,v]) => ({ ...a, [k]:v }), {});
const { defaults = {} } = code;
const [_den, _de] = Object.entries(defaults)?.[0];
if (typeof module !== 'undefined' && module.exports) {
module.exports = _ne || {};
}
else if (_den && _de) { globalThis[_den] = _de; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment