{"name":"degenerator","version":"6.0.0","author":{"url":"http://n8.io/","name":"Nathan Rajlich","email":"nathan@tootallnate.net"},"license":"MIT","_id":"degenerator@6.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":"87262e7c534dc7bd2dc5d5d15f67aeb2e9b1b3e7","tarball":"http://registry-npm.ywwl.com/degenerator/download/degenerator-6.0.0.tgz","fileCount":15,"integrity":"sha512-j5MdXdefrecJeSqTpUrgZd4fBsD2IxZx0JlJD+n1Q7+aTf7/HcyXSfHsicPW6ekPurX159v1ZYla6OJgSPh2Dw==","signatures":[{"sig":"MEUCIBOqHxKw9TD2Bq9BLoSI0u6hH7Z0N3zFwQ2THok7vQIWAiEA7o67o9VRSadkx+N+PtYXbkuQAur5vyYLMBpreFos1Hw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/degenerator@6.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":26169,"size":7878,"noattachment":false,"key":"/degenerator/-/degenerator-6.0.0.tgz"},"type":"module","_from":"file:degenerator-6.0.0.tgz","engines":{"node":">= 14"},"exports":{"import":{"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/678f805bfa33469fac9b640a976c18a7/degenerator-6.0.0.tgz","_integrity":"sha512-j5MdXdefrecJeSqTpUrgZd4fBsD2IxZx0JlJD+n1Q7+aTf7/HcyXSfHsicPW6ekPurX159v1ZYla6OJgSPh2Dw==","repository":{"url":"git+https://github.com/TooTallNate/proxy-agents.git","type":"git","directory":"packages/degenerator"},"_npmVersion":"11.11.0","description":"Compiles sync functions into async generator functions","directories":{},"_nodeVersion":"20.20.0","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_6.0.0_1773248310562_0.036029451629458364","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":1773248310708,"_cnpm_publish_time":1773248310708,"dist-tags":{"latest":"7.0.2"}}