{"name":"modern-node-polyfills","version":"0.1.0","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","@rollup/plugin-inject":"^4.0.4","acorn":"^8.8.0","esbuild":"^0.14.47","local-pkg":"^0.4.1","rollup":"^2.75.7"},"devDependencies":{"@rollup/pluginutils":"^3.1.0","@types/node":"^18.0.0","estree-walker":"^2.0.1","magic-string":"^0.25.7","resolve.exports":"^1.1.0","tsup":"^6.1.3","typescript":"^4.7.4","vitest":"^0.16.0"},"repository":{"type":"git","url":"git+https://github.com/Aslemammad/modern-node-polyfills.git"},"gitHead":"ffea714e7332226c3d828b755bdb2423a3158b89","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.0","_nodeVersion":"17.9.1","_npmVersion":"8.11.0","dist":{"integrity":"sha512-/Z9mlC56KBxjLZvdNSLqSEFw9jSav43dsUxhLYLN3bZgcSX5VFdixat+QGjb/4NxaGCwW09ABJhZA5oHFj4W4A==","shasum":"f2ee8603c17da05cc4336871e61f64bf05f7edc3","tarball":"http://registry-npm.ywwl.com/modern-node-polyfills/download/modern-node-polyfills-0.1.0.tgz","fileCount":10,"unpackedSize":104848,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIH5Ns8es8ScIwbJb36hsE1/BUZyrh0i4+8WyxmwxVRrkAiBgelGTWtBgRzSCJM2g0qdx/dZcnW3TjRJf2X0+6wIW8A=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj8QOzACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmr41g//VfS/XGgo/RnkGi4N6n3N9nhDBXf6FI6+7UB57B05IqucMXA9\r\nC8ozJ/xMHk5/3xg+oUaOTRthOFnEHRXWFgM56dp9MABo5zH+yV1X5sa/LNVK\r\nFhs4WDCX+Uvz8lNUFl5pbEZjlq9OSmI2VxtuOkXq0eQhZtG2/Ti7e3pOOUca\r\nzT5OUWrtad1yogb5v7pBUbDDjZzNOkniRnMbtXZIN3OoYTdvihrCArlxyuQ4\r\nFuEPzrxnWm4ZGr29mrxB4+2Q5ZyPzawKZKPJ5q/HG2r6MQfU+vY6+bfrKQR4\r\nw0daSX3pyHySe4cycYqVWtm2J7QKzOqG5qV57DCC9HnZufwkSxkBeb87rny0\r\ny5D0+xV4BYqtWSGleMInFi5wKIxTyaVSFlQYgEA/NTF2VtxpgsyQJA7u1wus\r\nLBfwr9IuZu8RN8O6NL/gW29ESGYK3rM+mWO+H4TJ/gd5OCNteu2YDCzHQAui\r\nmafegyowg19tSr/1n0v+acc9YBfg5XUkw0otvtPstPDQLgDqFtUKCsc6U/dF\r\nbhYpIPh9eK51LCMwIcTnUtS7JAQ6YI/5FqYwZiB2SaJ+Em+L7NCrA3jxtAtQ\r\nh5u9EYOK9XL3tceWyffbkThf0E8/jtYpGWg/9MlegQYicbh/7sUT/nZWcJ5t\r\n7thhOSdaHvKnN1gC8l6pj1SKzzcovwDGCZQ=\r\n=XPio\r\n-----END PGP SIGNATURE-----\r\n","size":24389,"noattachment":false,"key":"/modern-node-polyfills/-/modern-node-polyfills-0.1.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.1.0_1676739507445_0.4477967792530666"},"_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":1676739507660,"_cnpm_publish_time":1676739507660,"dist-tags":{"latest":"1.0.0"}}