{"library":"modern-node-polyfills","title":"Modern Node Polyfills","description":"modern-node-polyfills provides polyfills for Node.js native modules (such as `fs`, `buffer`, `process`) to enable their use in non-Node environments like browsers, Cloudflare Workers, and Deno. It leverages a collection of modern, lightweight polyfills sourced directly from JSPM's `jspm-core` project. The package is currently at version 1.0.0 and while it does not specify a fixed release cadence, it is actively maintained. Its key differentiators include its focused approach on modern polyfills specifically tailored for non-Node runtime compatibility, offering a practical solution for edge environments, and providing utility functions like `polyfillPath`, `polyfillContent`, `inject`, and `polyfillGlobals` for code transformation.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install modern-node-polyfills"],"cli":null},"imports":["import { polyfillPath } from 'modern-node-polyfills'","import { inject } from 'modern-node-polyfills'","import { polyfillGlobals } from 'modern-node-polyfills'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { polyfillGlobals } from 'modern-node-polyfills';\n\nconst browserCode = `\n    console.log(global);\n    console.log(process.env.NODE_ENV);\n    const buf = Buffer.from('hello');\n    console.log(buf.toString());\n    console.log(__filename);\n    console.log(__dirname);\n`;\n\nasync function transformAndLog() {\n  try {\n    const polyfilledContent = await polyfillGlobals(\n      browserCode,\n      { \n        __filename: '/app/index.js',\n        __dirname: '/app' \n      }\n    );\n    console.log('--- Original Code ---\\n' + browserCode);\n    console.log('\\n--- Polyfilled Content ---\\n' + polyfilledContent);\n    // In a real browser/edge environment, you would now execute polyfilledContent\n  } catch (error) {\n    console.error('Error during polyfill:', error);\n  }\n}\n\ntransformAndLog();","lang":"typescript","description":"This quickstart demonstrates how to use `polyfillGlobals` to transform code containing Node.js globals (`process`, `Buffer`, `global`, `__filename`, `__dirname`) into a version suitable for non-Node environments, including custom paths for file-system specific globals.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}