{"name":"modern-node-polyfills","version":"0.1.2","description":"modern polyfills for node native modules based on jspm-core","type":"module","main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","sideEffects":false,"scripts":{"dev":"pnpm tsup --watch","build":"pnpm tsup","test":"pnpm vitest"},"keywords":["polyfills","shims","edge"],"author":{"name":"Mohammad Bagher Abiat"},"license":"MIT","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs","default":"./dist/index.js"},"./global":{"types":"./dist/global.d.ts","import":"./dist/global.js","require":"./dist/global.cjs","default":"./dist/global.js"}},"dependencies":{"@jspm/core":"2.0.0-beta.24","esbuild":"^0.14.54","@rollup/pluginutils":"^3.1.0","local-pkg":"^0.4.3"},"devDependencies":{"@rollup/plugin-inject":"^4.0.4","@types/node":"^18.15.13","acorn":"^8.8.2","estree-walker":"^2.0.2","magic-string":"^0.25.9","resolve.exports":"^1.1.1","rollup":"^2.79.1","tsup":"^6.7.0","typescript":"^4.9.5","vitest":"^0.16.0"},"repository":{"type":"git","url":"git+https://github.com/Aslemammad/modern-node-polyfills.git"},"gitHead":"3858c34d87fe1e670209b1e64ea869fa6cd599bf","bugs":{"url":"https://github.com/Aslemammad/modern-node-polyfills/issues"},"homepage":"https://github.com/Aslemammad/modern-node-polyfills#readme","_id":"modern-node-polyfills@0.1.2","_nodeVersion":"18.12.1","_npmVersion":"8.19.2","dist":{"integrity":"sha512-EtgJ5dRAqJaqOMg1/ivrTyP9R3Zy/8WlD5blQtbXkyIiX7r00mrCPscxxeuklhIqsG/wxb2EPnhFsTQpN3ZlNw==","shasum":"df662f9e6001a22c8f54d693f7f9b06cb65b2924","tarball":"http://registry-npm.ywwl.com/modern-node-polyfills/download/modern-node-polyfills-0.1.2.tgz","fileCount":10,"unpackedSize":466345,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGgpOB7wg9CFhFLcOzIlaQA9r5wg0yX+tcURlGR+wn4YAiAZAd6zbw8AjzgtlGTjvuvfwsOuOPAgrPDyvtLHPDe9Ag=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkRYQMACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmoc7Q//a8cSpL9JJgxBhLgAUPtfZYQlwsdZZFJ2h9wePjksFTcG+ALa\r\nZyrdOpTAM+Dedm0np/9oL4JsQ9qxL0fwSBf4EEZ5pCKDFpatsuWj0GcR8VAy\r\nbLKOBh/z/p8+lwt5Mw56aB9ardFM87fPUgoMjV7S1NAtn38JQ7tPba2c0TI/\r\nrHuk7rSm0XsGRewbwASiL+SPbWf/g8UTllEcgRSnevykIbBgHc+lVFtoWXOb\r\n0fmyw+kJ3/qKvXDUDCX9HijbXot8WO8p1n8VedZcZmdSFOvOL4PdegUa+Z2L\r\nwDRU51pmqG9NToO3H0zlJzvSers5Z4ShP5lJ8svZODnob3Km+zL2Vb3dsnA0\r\n6zCXTTiv9OWuK95J3agPjn47ZNIU473RvU158wX6rKFO9LKY97QaqVPVFW2B\r\nnqxOkV7US5gP3/LC5uX1GKw2Jvvrk9RqYIzXOECnt7yD9fgjyVRwFaaQH/x7\r\nDG/rxt9xR1Rrl0N2JYRRdUIf9L/HAEmbPOD1egjDu3k9i5EzcnTaz1IDfllF\r\n0jUcCJ5YKLp/rFMpJ4iTvuHaFXtuUUl5D6Z+J/j049hC8eGWeh54D9rVqM4K\r\nrSubyIQeP9cV8o4wKKhQVdAIv3cQe/ER3nt3IPyBnfY3DvysAZy9PcQ2twxP\r\n11M3eyMymYfDaO6oJLtmnF8aeX38scD0XzI=\r\n=4N3z\r\n-----END PGP SIGNATURE-----\r\n","size":104461,"noattachment":false,"key":"/modern-node-polyfills/-/modern-node-polyfills-0.1.2.tgz"},"_npmUser":{"name":"aslemammad","email":"zorofight94@gmail.com"},"directories":{},"maintainers":[{"name":"aslemammad","email":"zorofight94@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/modern-node-polyfills_0.1.2_1682277388538_0.1786910426092747"},"_hasShrinkwrap":false,"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","publish_time":1682277388729,"_cnpm_publish_time":1682277388729,"dist-tags":{"latest":"1.0.0"}}