{"name":"modern-node-polyfills","version":"0.0.0","description":"modern polyfills for node native modules based on jspm-core","type":"module","main":"index.js","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","default":"./dist/esm/index.js"},"./global":{"types":"./dist/global.d.ts","default":"./dist/esm/global.js"}},"dependencies":{"@jspm/core":"2.0.0-beta.24","@rollup/plugin-inject":"^4.0.4","acorn":"^8.7.1","esbuild":"^0.14.47","local-pkg":"^0.4.1","rollup":"^2.75.7"},"devDependencies":{"@rollup/pluginutils":"^3.1.0","estree-walker":"^2.0.1","magic-string":"^0.25.7","@types/node":"^18.0.0","resolve.exports":"^1.1.0","tsup":"^6.1.2","typescript":"^4.7.4","vitest":"^0.16.0"},"gitHead":"987e6fff3d9747a4e9b3d3f854639319cd8eafac","_id":"modern-node-polyfills@0.0.0","_nodeVersion":"16.15.1","_npmVersion":"8.11.0","dist":{"integrity":"sha512-4UzjBm31ilvsyONSOSb/RL6+/fNSaLnWpyXYsTKpH8LbpuP4ypmOZE3VZuMtjKblK2w9/eHiQ6rQSkvBuWf3Bg==","shasum":"b8de1df8743aa919e6cc8a09af47dc3a17257e76","tarball":"http://registry-npm.ywwl.com/modern-node-polyfills/download/modern-node-polyfills-0.0.0.tgz","fileCount":11,"unpackedSize":843410,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDX0mCCkRQRp2rHdPmLyJKdlT2PzBEt5GIUaNaLDDh88wIgeFRRmE1NNuF6SlyTjSPqdRcTpI6wjR0j58RCDYR5R/0="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJi0cvzACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmo1rhAAgCU86mFQTz9dt0v/8wGofPekiYu5F9Zs66OXwh9P0z/Y7tv1\r\n2EuEYNpFURhXT7sdM+/C9BgSyhAidtEmVSFjb93OohxTcMxILkftOUlve8S5\r\n84wQrvSkMc9M8jtYg3xjix/yekGboys1YmlqIXoPmt/5qDlr2BtyojRDnEyW\r\n3Xh3zSA4sH+fS4kwkwJ7VlpcVZw1TI8gXC51NQ25pdaD4TZ8XF3SJ5Td6C6J\r\nFZBPy14cTIJfWakuKpjjib59d3aw7uXQPdmkdLNOaeWW8UUVKSULlf8UST2W\r\nL4aD1m+C7xACPqLt02ZdWWlkZ3ykZ6EU641YCTCf2YyBcfAkWb5CjN6Fnpg1\r\nnf/OdjwUmG/ZPZ8FZgaZCFMMOw8KfmbvDZJztabl/rDBo5yRj3EaPlpajqAW\r\nzfaxuqjTcxcNjRKbzoAOUHmxPY1Dml1EvG4MhwPhlxZzVtpRmXmD5p52eB36\r\nSB5M5A8j3AD2T7VQQiEf4QyiaDe3rkHJTDSEn6uWZqpKUMsbRaNmspTBfwRn\r\n5IElQJbepgy+LLu43vkjFvGDoZOiZYZYptJ4cmrFrsZ4P7KXVaYr8AtzwhF5\r\n/N9l9GTZDhriMivGQd7GAAsPnqxqPrRZM5IxjgbAKJa/UHyBUWTIP+QMkr5b\r\nQvqpxT2KGFh3jL/ubwu/Q/ycBBONm/sXs5w=\r\n=5sDX\r\n-----END PGP SIGNATURE-----\r\n","size":176839,"noattachment":false,"key":"/modern-node-polyfills/-/modern-node-polyfills-0.0.0.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.0.0_1657916402471_0.06998471810533569"},"_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":1657916403044,"_cnpm_publish_time":1657916403044,"dist-tags":{"latest":"1.0.0"}}