{"name":"degenerator","version":"7.0.0","author":{"url":"http://n8.io/","name":"Nathan Rajlich","email":"nathan@tootallnate.net"},"license":"MIT","_id":"degenerator@7.0.0","maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"homepage":"https://github.com/TooTallNate/proxy-agents#readme","bugs":{"url":"https://github.com/TooTallNate/proxy-agents/issues"},"dist":{"shasum":"b269074f2c96d3f8239e1b9f9e992f52a067ef42","tarball":"http://registry-npm.ywwl.com/degenerator/download/degenerator-7.0.0.tgz","fileCount":15,"integrity":"sha512-YIz9P5gRq4qThp4X5E7O0i/K3w4Jd9akZUt5wUPk6+6zZrSudknhi/IlDn4JJ281XcfSpcEz1lFD4C+tf0ymmQ==","signatures":[{"sig":"MEYCIQD4IVrNzn2PzT47FuFG7qI5iCQlRhI3LMHUab4cBg08KwIhANvJMjhTZ4xcsiutvROhq8SeiVU3c6QEJQBSppAqS2ZM","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/degenerator@7.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":26143,"size":7867,"noattachment":false,"key":"/degenerator/-/degenerator-7.0.0.tgz"},"type":"module","_from":"file:degenerator-7.0.0.tgz","engines":{"node":">= 20"},"exports":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"scripts":{"lint":"eslint . --ext .ts","pack":"node ../../scripts/pack.mjs","test":"vitest","build":"tsc"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:9faa8b3f-d109-487e-88cb-fd86660a742e"}},"_resolved":"/tmp/ca53145ec2522692f4a63f19df64d7b5/degenerator-7.0.0.tgz","_integrity":"sha512-YIz9P5gRq4qThp4X5E7O0i/K3w4Jd9akZUt5wUPk6+6zZrSudknhi/IlDn4JJ281XcfSpcEz1lFD4C+tf0ymmQ==","repository":{"url":"git+https://github.com/TooTallNate/proxy-agents.git","type":"git","directory":"packages/degenerator"},"_npmVersion":"11.12.1","description":"Compiles sync functions into async generator functions","directories":{},"_nodeVersion":"20.20.1","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":"^0.0.1","@types/esprima":"^4.0.3","@types/escodegen":"^0.0.7"},"peerDependencies":{"quickjs-wasi":"^0.0.1"},"_npmOperationalInternal":{"tmp":"tmp/degenerator_7.0.0_1775026659811_0.08872762345379237","host":"s3://npm-registry-packages-npm-production"},"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":1775026660004,"_cnpm_publish_time":1775026660004,"dist-tags":{"latest":"7.0.2"}}