Last active
March 14, 2024 22:28
Helper function to load ESM packages from NPM in your browser dev tools console
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
/** | |
* Load an ESM package from npm in your JavaScript environment. | |
* | |
* Loads packages from https://www.npmjs.com/ via the CDN https://www.jsdelivr.com/ | |
* | |
* Usage: | |
* | |
* const lodash = await npm('lodash-es') | |
* const lodash = await npm('lodash-es@4') | |
* const lodash = await npm('lodash-es@4.17.21') | |
* | |
* lodash.uniq([1, 3, 2, 1, 2, 2]) // [1, 3, 2] | |
*/ | |
async function npm(name) { | |
return await import(`https://cdn.jsdelivr.net/npm/${name}/+esm`) | |
} |
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
const lodash = await npm('lodash-es') | |
lodash.uniq([1, 3, 2, 1, 2, 2]) | |
// [1, 3, 2] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: It's not available in blank tab