{"id":15311831,"url":"https://github.com/aslemammad/modern-node-polyfills","last_synced_at":"2025-04-13T18:14:42.358Z","repository":{"id":41095747,"uuid":"508298782","full_name":"Aslemammad/modern-node-polyfills","owner":"Aslemammad","description":"modern polyfills for node native modules based on jspm-core","archived":false,"fork":false,"pushed_at":"2024-02-17T06:03:29.000Z","size":274,"stargazers_count":40,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-13T18:14:37.646Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Aslemammad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2022-06-28T12:54:39.000Z","updated_at":"2024-11-07T14:05:11.000Z","dependencies_parsed_at":"2022-07-08T19:49:50.132Z","dependency_job_id":"21abb26e-2250-4a33-a714-32c9618911be","html_url":"https://github.com/Aslemammad/modern-node-polyfills","commit_stats":{"total_commits":51,"total_committers":3,"mean_commits":17.0,"dds":"0.11764705882352944","last_synced_commit":"c9fe66f76de48352915f4a90f0d08eae8928629d"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aslemammad%2Fmodern-node-polyfills","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aslemammad%2Fmodern-node-polyfills/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aslemammad%2Fmodern-node-polyfills/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aslemammad%2Fmodern-node-polyfills/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Aslemammad","download_url":"https://codeload.github.com/Aslemammad/modern-node-polyfills/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248758418,"owners_count":21156957,"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":[],"created_at":"2024-10-01T08:34:42.367Z","updated_at":"2025-04-13T18:14:42.335Z","avatar_url":"https://github.com/Aslemammad.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# modern-node-polyfills\nA way to enable using Node native modules in non-node (Browser, Cloudflare, Deno,\n...) environemnts with modern polyfills from [JSPM](https://github.com/jspm/jspm-core).\n\n[Here](https://github.com/jspm/jspm-core/tree/main/nodelibs/browser) are the modules that are supported in modern-node-polyfills.\n\n# Example\n```ts\nimport { polyfillPath } from \"modern-node-polyfills\";\n\nconsole.log(await polyfillPath(\"fs\")) \n// /home/bagher/project/@jspm/core/nodelibs/browser/fs.js\n```\n\n### `polyfillPath`\nThis function returns the path of the requested module.\n```ts\nawait polyfillPath(\"fs\");\nawait polyfillPath(\"node:fs\") // Modules can have the `node` prefix\n```\n\n### `polyfillContent`\nIt returns the bundled content of a specific node module instead of a path.\n```ts\nconsole.log(await polyfillContent(\"fs\"));\n// the bundled source of `fs`\n```\n\n## `inject`\nThis function tries to do the work of [@rollup/plugin-inject](https://github.com/rollup/plugins/tree/master/packages/inject#readme) plugin! but it also adds a new option called `expressions` which is for replacing javascript expressions like `__filename`.\n\n```ts\nconsole.log(await inject(\"console.log(__filename);\", {\n  // replaces every global __filename with \"/\"\n  expressions: { __filename: \"/\" },\n  modules: {\n    // replaces every global `Buffer` with the imported `Buffer` from the polyfill buffer\n    Buffer: [await polyfillPath(\"buffer\"), \"Buffer\"],\n  }\n}))\n// logs `console.log(\"/\")`\n```\n\n## `polyfillGlobals`\nA way to polyfill all global node expressions, in this case, `process`,\n`Buffer`, `global`, `setImmediate`, `clearImmediate`, `__dirname` and `__filename`. It's possible to customize the `__filename` and `__dirname` values in the second argument of this function.\n```ts\nconsole.log(await polyfillGlobals(`\n    console.log(global);\n    console.log(process);\n    console.log(Buffer);\n    console.log(setImmediate);\n    console.log(clearImmediate);\n`))\n// shows the polyfilled content\n```\nAs a third argument, it's possible to change the path of those global polyfills or\neven disable them using `null`.\n\n```ts\nconst content = await polyfillGlobals(\n\t`\n\tconsole.log(global)\n\tconsole.log(process);\n\tconsole.log(Buffer);\n\tconsole.log(setImmediate);\n\tconsole.log(clearImmediate);\n`,\n\t{},\n\t{\n\t\tprocess: \"/here/process.js\",\n\t\tBuffer: null,\n\t\tglobal: null,\n\t\tsetImmediate: null,\n\t\tclearImmediate: null,\n\t}\n);\n```\n\n# Contribution\nFeel free to let me know what you need for this package or what issue you have,\nI'd be happy!\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faslemammad%2Fmodern-node-polyfills","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faslemammad%2Fmodern-node-polyfills","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faslemammad%2Fmodern-node-polyfills/lists"}