{"name":"modern-node-polyfills","version":"1.0.0","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.1","@rollup/pluginutils":"^5.0.2","local-pkg":"^0.4.3"},"devDependencies":{"@rollup/plugin-inject":"^5.0.3","@types/node":"^18.16.17","acorn":"^8.8.2","esbuild":"^0.18.0","estree-walker":"^3.0.3","magic-string":"^0.30.0","resolve.exports":"^2.0.2","rollup":"^2.79.1","tsup":"^6.7.0","typescript":"^5.1.3","vitest":"^0.32.0"},"peerDependencies":{"esbuild":"^0.14.0 || ^0.15.0 || ^0.16.0 || ^0.17.0 || ^0.18.0"},"repository":{"type":"git","url":"git+https://github.com/Aslemammad/modern-node-polyfills.git"},"engines":{"node":">=14.0.0"},"gitHead":"4e2d23b7384ed491d5aeaf6ba66f01c13f0622a8","bugs":{"url":"https://github.com/Aslemammad/modern-node-polyfills/issues"},"homepage":"https://github.com/Aslemammad/modern-node-polyfills#readme","_id":"modern-node-polyfills@1.0.0","_nodeVersion":"17.9.1","_npmVersion":"8.11.0","dist":{"integrity":"sha512-w1yb6ae5qSUJJ2u41krkUAxs+L7i9143Qam8EuXwDMeZHxl1JN8RfTSXG4S2bt0RHIRMeoWm/HCeO0pNIHmIYQ==","shasum":"f0ac8eddb49dd18f51a9f6e72d2934392bbc9720","tarball":"http://registry-npm.ywwl.com/modern-node-polyfills/download/modern-node-polyfills-1.0.0.tgz","fileCount":11,"unpackedSize":457803,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD/0xvhd36BQilp1mCABCW9W2/dKzOPrvS3vJpQLpjREQIgT1iPBC0SqsJw/dT157euDsBFmKxk+JOCsN9EfZBOEfs="}],"size":103570,"noattachment":false,"key":"/modern-node-polyfills/-/modern-node-polyfills-1.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_1.0.0_1686599228750_0.32519700113292793"},"_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":1686599228915,"_cnpm_publish_time":1686599228915,"dist-tags":{"latest":"1.0.0"}}