Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save LeetCodes/9da46f1a6de78cc0995fb6c57018f3c1 to your computer and use it in GitHub Desktop.
Save LeetCodes/9da46f1a6de78cc0995fb6c57018f3c1 to your computer and use it in GitHub Desktop.
import browserified modules from npm
function require(mods,that=window){
return new Promise(r=>(_=>Promise.all(_.map(function (m){return import(`https://dev.jspm.io/${m.name?m.name:m}`).then(({default:module})=>[m.var?m.var:m.replace(/\-([\w])/g,(..._)=>_[1].toUpperCase()),(module.default?module.default:module)])})).then(_=>Object.fromEntries(_.map(_=>[_[0],_[1]]))))(mods).then(_=>(Object.assign(that,_),r(_))));
}
require([
{ name: "[email protected]", var: "JSZip" },
{ name: "file-saver", var: "saveAs" }
]);
//require(["ascii-data-table"]);
// or, u can name the variables w/e u want
// require([{ name: "ascii-data-table", var: "txtTable" }]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment