{"id":31646819,"url":"https://github.com/zachleat/import-module-string","last_synced_at":"2025-10-07T05:56:24.428Z","repository":{"id":290983260,"uuid":"976201875","full_name":"zachleat/import-module-string","owner":"zachleat","description":"Use import('data:') and import(Blob) to execute arbitrary JavaScript strings","archived":false,"fork":false,"pushed_at":"2025-08-08T21:29:42.000Z","size":180,"stargazers_count":16,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-14T07:31:54.673Z","etag":null,"topics":[],"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/zachleat.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,"zenodo":null}},"created_at":"2025-05-01T17:22:26.000Z","updated_at":"2025-08-13T13:49:20.000Z","dependencies_parsed_at":"2025-05-01T18:32:26.527Z","dependency_job_id":"349ddcbd-d5de-4328-a87f-c671163b00c1","html_url":"https://github.com/zachleat/import-module-string","commit_stats":null,"previous_names":["zachleat/import-module-string"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/zachleat/import-module-string","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zachleat%2Fimport-module-string","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zachleat%2Fimport-module-string/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zachleat%2Fimport-module-string/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zachleat%2Fimport-module-string/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zachleat","download_url":"https://codeload.github.com/zachleat/import-module-string/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zachleat%2Fimport-module-string/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278728316,"owners_count":26035412,"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","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-10-07T05:56:15.925Z","updated_at":"2025-10-07T05:56:24.412Z","avatar_url":"https://github.com/zachleat.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `import-module-string`\n\nUse `import('data:')` and `import(Blob)` to execute arbitrary JavaScript strings. A simpler alternative to [`node-retrieve-globals`](https://github.com/zachleat/node-retrieve-globals/) that works in more runtimes.\n\n## Installation\n\nAvailable on `npm` as [`import-module-string`](https://www.npmjs.com/package/import-module-string).\n\n```\nnpm install import-module-string\n```\n\n## Features\n\n- Multi-runtime: tested with Node (18+), Deno (limited), Chromium, Firefox, and WebKit.\n- Defers to `export` when used, otherwise implicitly `export` all globals (via `var`, `let`, `const`, `function`, `Array` or `Object` destructuring assignment, `import` specifiers, etc)\n- Supports top-level async/await (as expected for ES modules)\n- Emulates `import.meta.url` when `filePath` option is supplied\n- `addRequire` option adds support for `require()` (in Node)\n- Extremely limited dependency footprint (`acorn` for JS parsing only)\n- Supports data object to pass in data (must be JSON.stringify friendly, more serialization options may be added later)\n- Subject to URL content [size maximums](https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Schemes/data#length_limitations): Chrome `512MB`, Safari `2048MB`, Firefox `512MB`, Firefox prior to v137 `32MB`\n\n|Feature|Server|Browser|\n|---|---|---|\n|`import('./file.js')`|✅|✅ (Import Map-friendly)|\n|`import('bare')`|✅|✅ (Import Map-friendly)|\n|`import('built-in')`|✅|_N/A_|\n|`require()`|✅ with `addRequire` option|❌|\n|`import.meta.url`|✅ with `filePath` option|✅ with `filePath` option|\n\nNotes:\n\n- [built-in](https://nodejs.org/api/module.html#moduleisbuiltinmodulename) modules are provided by the JavaScript runtime. `node:fs` is one example.\n- `bare` specifiers are packages referenced by their bare name. In Node this might be a package installed from npm.\n\n## Usage\n\nImport the script first!\n\n```js\nimport { importFromString } from \"import-module-string\";\n```\n\nView the [test suite file](https://github.com/zachleat/import-module-string/blob/main/test/import-module-string.test.js) for more examples.\n\n### Export\n\n```js\nawait importFromString(`export var a = 1;\nexport const c = 3;\nexport let b = 2;`);\n\n// Returns\n{ a: 1, c: 3, b: 2 }\n```\n\n### No export\n\n```js\nimport { importFromString } from \"import-module-string\";\n\nawait importFromString(`var a = 1;\nconst c = 3;\nlet b = 2;`);\n\n// Returns\n{ a: 1, c: 3, b: 2 }\n```\n\n### Pass in data\n\n```js\nawait importFromString(\"const a = b;\", { data: { b: 2 } });\n\n// Returns\n{ a: 2 }\n```\n\n### Pass in filePath\n\n```js\nawait importFromString(\"const a = import.meta.url;\", { filePath: import.meta.url });\n\n// Returns value for import.meta.url, example shown\n{ a: `file:///…` }\n```\n\n### Imports (experimental feature)\n\n#### Relative references\n\n```js\n// `dependency.js` has the content `export default 2;`\nawait importFromString(\"import dep from './dependency.js';\");\n\n// Returns\n{ dep: 2 }\n```\n\n#### Bare references\n\nUses `import.meta.resolve` to resolve paths, which will also resolve using Import Maps (where available).\n\n```js\n// maps with `import.meta.resolve(\"@zachleat/noop\"))` in-browser (Import Map friendly)\nawait importFromString(\"import {noop} from '@zachleat/noop';\");\n\n// Returns\n{ noop: function() {} }\n```\n\n#### Builtins\n\n```js\nawait importFromString(\"import fs from 'node:fs';\");\n\n// Returns (where available: `node:fs` is not typically available in browser)\n{ fs: { /* … */ } }\n```\n\nAs a side note, you _can_ shim `fs` into the browser with [`memfs`](https://github.com/streamich/memfs).\n\n## Changelog\n\n- `v2.0.0` removes `adapter` (no longer necessary!)\n- `v1.0.5` bug fixes\n- `v1.0.4` add `adapter` option (add `adapter: \"fs\"` or `adapter: \"fetch\"`) to resolve imports in various environments.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzachleat%2Fimport-module-string","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzachleat%2Fimport-module-string","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzachleat%2Fimport-module-string/lists"}