{"_id":"degenerator@7.0.2","bugs":{"url":"https://github.com/TooTallNate/proxy-agents/issues"},"dist":{"shasum":"58c5431e5a497a249988e36ff6a6c41a7270c92b","tarball":"http://registry-npm.ywwl.com/degenerator/download/degenerator-7.0.2.tgz","fileCount":15,"integrity":"sha512-j47S7YEAqh4U3UR355ts14Ipq0Zgn+AaMRdJuoyF7Ry2eSazevFvaviLMp0iOXAq7/FiBs3/33UIkE7rWRoLWQ==","signatures":[{"sig":"MEYCIQD8IBLKMdf/cO8qrx10KrU6xc/AQ/o4iYNcYkUdbhZyAAIhANfAnK0DvFoAoS1sGdF1MV7ZIHsa2AMj7FXS3yncpov2","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCICNxcDy7qu4KTN2OfO0hkNKi3RolImii7YfrTuL2FOSOAiAxgeWGRhIgvrOgNNF8PRaOfMBBBJKZPj9L+fso/9fOsw=="}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/degenerator@7.0.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":27704,"size":8281,"noattachment":false,"key":"/degenerator/-/degenerator-7.0.2.tgz"},"name":"degenerator","type":"module","_from":"file:degenerator-7.0.2.tgz","author":{"url":"http://n8.io/","name":"Nathan Rajlich","email":"nathan@tootallnate.net"},"engines":{"node":">= 20"},"exports":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"license":"MIT","scripts":{"lint":"eslint . --ext .ts","pack":"node ../../scripts/pack.mjs","test":"vitest","build":"tsc"},"version":"7.0.2","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"9faa8b3f-d109-487e-88cb-fd86660a742e"}},"homepage":"https://github.com/TooTallNate/proxy-agents#readme","_resolved":"/tmp/b280966019355e1c7d93744b7475261f/degenerator-7.0.2.tgz","_integrity":"sha512-j47S7YEAqh4U3UR355ts14Ipq0Zgn+AaMRdJuoyF7Ry2eSazevFvaviLMp0iOXAq7/FiBs3/33UIkE7rWRoLWQ==","repository":{"url":"git+https://github.com/TooTallNate/proxy-agents.git","type":"git","directory":"packages/degenerator"},"_npmVersion":"12.2.2","description":"Compiles sync functions into async generator functions","directories":{},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"_nodeVersion":"24.22.2","dependencies":{"esprima":"^4.0.1","ast-types":"^0.13.4","escodegen":"^2.1.0"},"_hasShrinkwrap":false,"devDependencies":{"tsconfig":"0.0.0","typescript":"^5.1.6","@types/node":"^22.13.0","quickjs-wasi":"^3.0.0","@types/esprima":"^4.0.3","@types/escodegen":"^0.0.7"},"peerDependencies":{"quickjs-wasi":"^3.0.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/degenerator_7.0.2_1794854178245_0.9613461937401284"},"readme":"degenerator\n===========\n### Compiles sync functions into async functions\n\nSometimes you need to write sync looking code that's really async under the hood.\nThis module takes a String to one or more synchronous JavaScript functions, and\nreturns a new String that with those JS functions transpiled into `async`\nfunctions.\n\nSo this:\n\n```js\nfunction foo() {\n  return a('bar') || b();\n}\n```\n\nGets compiled into:\n\n```js\nasync function foo() {\n    return await a('bar') || await b();\n}\n```\n\nWith the compiled output code, you can evaluate the code using the `vm` module\nin Node.js, or save the code to a file and require it, or whatever.\n\nExample\n-------\n\nYou must explicitly specify the names of the functions that should be\n\"asyncified\". So say we wanted to expose a `get(url)` function that did\nand HTTP request and returned the response body.\n\nThe user has provided us with this implementation:\n\n``` js\nfunction myFn() {\n  const one = get('https://google.com');\n  const two = get('http://nodejs.org');\n  const three = JSON.parse(get('http://jsonip.org'));\n  return [one, two, three];\n}\n```\n\nNow we can compile this into an asynchronous function, implement the\nasync `get()` function, and finally evaluate it into a real JavaScript function\ninstance with the `vm` module:\n\n\n```typescript\nimport vm from 'vm';\nimport { degenerator } from 'degenerator';\n\n// The `get()` function is Promise-based (error handling omitted for brevity)\nfunction get(endpoint: string) {\n  return new Promise((resolve, reject) => {\n    var mod = 0 == endpoint.indexOf('https:') ? require('https') : require('http');\n    var req = mod.get(endpoint);\n    req.on('response', function (res) {\n      var data = '';\n      res.setEncoding('utf8');\n      res.on('data', function (b) { data += b; });\n      res.on('end', function () {\n        resolve(data);\n      });\n    });\n  });\n}\n\n// Convert the JavaScript string provided from the user (assumed to be `str` var)\nstr = degenerator(str, [ 'get' ]);\n\n// Turn the JS String into a real async function instance\nconst asyncFn = vm.runInNewContext(`(${str})`, { get });\n\n// Now we can invoke the function asynchronously\nasyncFn().then((res) => {\n  // Do something with `res`...\n});\n```\n\n\nAPI\n---\n\n### degenerator(code: string, names: Array<string|RegExp>): String\n\nReturns a \"degeneratorified\" JavaScript string, with `async`/`await` transplanted.\n","publish_time":1794854178359,"_cnpm_publish_time":1794854178359,"dist-tags":{"latest":"7.0.2"}}