{"id":20093063,"url":"https://github.com/jojobyte/browser-import-rabbit-hole","last_synced_at":"2026-03-02T18:41:23.289Z","repository":{"id":145880281,"uuid":"594213787","full_name":"jojobyte/browser-import-rabbit-hole","owner":"jojobyte","description":"Deducing a way to use IIFE modules in browser and preserving JSDoc type hinting.","archived":false,"fork":false,"pushed_at":"2023-01-30T11:53:11.000Z","size":4,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-13T16:50:18.678Z","etag":null,"topics":["browser","browser-module","commonjs-modules","esm","esmodules","iife","jsdoc"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jojobyte.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-27T21:39:57.000Z","updated_at":"2024-10-06T23:34:26.000Z","dependencies_parsed_at":"2023-04-23T13:35:43.840Z","dependency_job_id":null,"html_url":"https://github.com/jojobyte/browser-import-rabbit-hole","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jojobyte%2Fbrowser-import-rabbit-hole","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jojobyte%2Fbrowser-import-rabbit-hole/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jojobyte%2Fbrowser-import-rabbit-hole/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jojobyte%2Fbrowser-import-rabbit-hole/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jojobyte","download_url":"https://codeload.github.com/jojobyte/browser-import-rabbit-hole/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233686670,"owners_count":18714186,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["browser","browser-module","commonjs-modules","esm","esmodules","iife","jsdoc"],"created_at":"2024-11-13T16:45:43.285Z","updated_at":"2025-09-20T20:32:14.642Z","avatar_url":"https://github.com/jojobyte.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Browser `import` Rabbit Hole\n\nDeducing a way to use IIFE modules that do not provide `export default` or `export let rabbit = 'hole'` in browser and preserving JSDoc type hinting.\n\n## TL;DR\n### Wrap it\n\n```js\n// sadness.js\n// the IIFE module you want to wrap\n\n/**\n * @typedef Foo2\n * @prop {Greet2} greet\n * @prop {Uint8Array} secret\n */\n\n/**\n * @callback Greet2\n * @param {String} name\n */\n\n/** @type {Foo2} */\nvar Foo2 = (\"object\" === typeof module \u0026\u0026 exports) || {};\n\n(function (window, Foo2) {\n  \"use strict\";\n\n  let Crypto = window.crypto || require(\"node:crypto\");\n\n  Foo2.secret = new Uint8Array(16);\n  Crypto.getRandomValues(Foo2.secret);\n\n  Foo2.greet = function (name) {\n    console.log(`Hello, ${name}!`);\n  };\n\n  window.Foo2 = Foo2;\n})(/** @type {Window} */ (globalThis.window || {}), Foo2);\n\nif (\"object\" === typeof module) {\n  module.exports = Foo2;\n}\n```\n\n```js\n// madness.js\n// Wrapper module\nimport './sadness.js'\nimport * as Types from './sadness.js'\n\n/** @type {Types} */\nlet Sadness = window.Foo2\n\nexport default Sadness\n```\n\n```html\n\u003c!-- index.html --\u003e\n\u003cscript type=\"module\"\u003e\n/**\n * now this works in modern browsers\n * with no transpilation and gives\n * JSDoc type hinting\n */\nimport madness from './madness.js';\n\nconsole.log(\n  'browser',\n  madness,\n  madness.secret.toString()\n)\n\nmadness.greet('madman')\n\u003c/script\u003e\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjojobyte%2Fbrowser-import-rabbit-hole","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjojobyte%2Fbrowser-import-rabbit-hole","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjojobyte%2Fbrowser-import-rabbit-hole/lists"}