Created
April 20, 2024 00:42
-
-
Save nyteshade/90a90bf095fde03eda5809f1998d8c58 to your computer and use it in GitHub Desktop.
Simple snippet of JavaScript to make exporting vanilla javascript easier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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