{"name":"modern-node-polyfills","version":"0.1.3","description":"modern polyfills for node native modules based on jspm-core","type":"module","main":"./dist/index.cjs","module":"./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":"./index.js","require":"./dist/index.cjs","default":"./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":"ec0dd74cd1490983a718b447fe35bcd5bca559b9","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.3","_nodeVersion":"18.12.1","_npmVersion":"8.19.2","dist":{"integrity":"sha512-/4dB85Sdkt9MjWwtpKnsNTYhh0+fqjFC4ZEgDP4B0e6kyzbGUnX4NDxTUCaVwRLVF9gcEDcRQjol8pn05B3TUQ==","shasum":"ae8ff3bfc8311421413173a782ecfc6bf240491a","tarball":"http://registry-npm.ywwl.com/modern-node-polyfills/download/modern-node-polyfills-0.1.3.tgz","fileCount":11,"unpackedSize":466275,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDXX8Uh6H6vuJtS+ZovFc8zWZ2o4oBflptlDacrKGOl0AiBWB6cOL9sSViPPnp4L2N0EcWHS8x1N+fNvVdMKQZHWCA=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkRe4oACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrKGBAAnR1q1tMtFhEsAbg0Xl7+qndfMoMGxZG/VfQeV1caehgvf4nF\r\nLHY7fe7PwNLyxJgj2QsLK926dJUGK0TI8zXZecUUTWF137lIWF8uhWkg6PhN\r\nLVibUfcDZhdTspdmctLf9DqdfAOU46jpdZySKE6vv+2GMaRqoAI/jT8qO7xu\r\nUYSINdTpJSckrQ7CGQR9UKCa2QK8hcvNmyLDtxx9h9jFCvCT6mSEOBiTW3fQ\r\ngr0sQCRIi5B8SBbS73ZQnkma+frMpbuoO9+SN9D6VuP98kK8iqiJbcR8AtVU\r\ne+n9FjMDA3Lh6j+sr2SNZx2u63PybYqo/PY+UrqeJN0GgLkGOmeJVO7w0mrG\r\niMB0001weWuEC5QTQFXR6+OISELkxOkgaI8+p+p9tA4ATebkx0szsF5b2TOs\r\nzV56rzK28IcnHAk1jOVAVxfpRguRQ7xu5Hnw0JeOiFrYGMkUMzIXg5JtO1yq\r\ntlWPwYMi46HR9nZeMsNRFhgOWWfvXWs+gdlEcyTZrB5lc1713RXYhlxe2ac8\r\nUxdgtfzu7ahsh84W6uWcegwYUVusDZE+DWNX2QxqsHlAoYWC1L3jb1FMi+l1\r\nHLv5tRldFWcmoUhp3Jiz6KKsTHWaC/N7O9mW6SHtBDexMUQw5DgCbIs77yDU\r\nSI7TMJUWc7RmqkZ4geIK8ZYEkxryvB4szH8=\r\n=MifD\r\n-----END PGP SIGNATURE-----\r\n","size":104465,"noattachment":false,"key":"/modern-node-polyfills/-/modern-node-polyfills-0.1.3.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.3_1682304551883_0.10835483570305948"},"_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":1682304552052,"_cnpm_publish_time":1682304552052,"dist-tags":{"latest":"1.0.0"}}