{"name":"quansync","version":"0.2.8","keywords":["async","sync","generator"],"author":{"name":"Anthony Fu","email":"anthonyfu117@hotmail.com"},"license":"MIT","_id":"quansync@0.2.8","maintainers":[{"name":"antfu","email":"anthonyfu117@hotmail.com"},{"name":"sxzz","email":"sxzz@sxzz.moe"}],"contributors":[{"name":"三咲智子 Kevin Deng","email":"sxzz@sxzz.moe"}],"homepage":"https://github.com/quansync-dev/quansync#readme","bugs":{"url":"https://github.com/quansync-dev/quansync/issues"},"dist":{"shasum":"2e893d17bb754ba0988ea399ff0bc5f2a8467793","tarball":"http://registry-npm.ywwl.com/quansync/download/quansync-0.2.8.tgz","fileCount":18,"integrity":"sha512-4+saucphJMazjt7iOM27mbFCk+D9dd/zmgMDCzRZ8MEoBfYp7lAvoN38et/phRQF6wOPMy/OROBGgoWeSKyluA==","signatures":[{"sig":"MEUCIGeCxPm/B109YpoPEcSEJJ4wljLa3/gmF76TNWD5ejmYAiEAgC3v2tWjtB5fAKovCP1aHb74K3AoUewPVpjii9FotHM=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":20565,"size":4838,"noattachment":false,"key":"/quansync/-/quansync-0.2.8.tgz"},"main":"./dist/index.mjs","type":"module","_from":"file:quansync-0.2.8.tgz","types":"./dist/index.d.mts","module":"./dist/index.mjs","exports":{".":{"import":"./dist/index.mjs","require":"./dist/index.cjs"},"./macro":{"import":"./dist/macro.mjs","require":"./dist/macro.cjs"},"./types":{"import":"./dist/types.mjs","require":"./dist/types.cjs"}},"funding":[{"url":"https://github.com/sponsors/antfu","type":"individual"},{"url":"https://github.com/sponsors/sxzz","type":"individual"}],"scripts":{"dev":"unbuild --stub","lint":"eslint .","test":"vitest","build":"unbuild","start":"tsx src/index.ts","release":"bumpp && pnpm publish","benchmark":"node scripts/benchmark.js","typecheck":"tsc --noEmit"},"_npmUser":{"name":"antfu","email":"anthonyfu117@hotmail.com"},"_resolved":"/private/var/folders/30/nymxcyb909ggq2j5lwn7b_600000gn/T/a0ce9eec0151857417074e730a9291f8/quansync-0.2.8.tgz","_integrity":"sha512-4+saucphJMazjt7iOM27mbFCk+D9dd/zmgMDCzRZ8MEoBfYp7lAvoN38et/phRQF6wOPMy/OROBGgoWeSKyluA==","repository":{"url":"git+https://github.com/quansync-dev/quansync.git","type":"git"},"_npmVersion":"10.9.2","description":"Create sync/async APIs with usable logic","directories":{},"lint-staged":{"*":"eslint --fix"},"sideEffects":false,"_nodeVersion":"22.13.1","typesVersions":{"*":{"*":["./dist/*","./*"]}},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.3","vite":"^6.2.0","bumpp":"^10.0.3","eslint":"^9.21.0","mitata":"^1.0.34","vitest":"^3.0.7","gensync":"1.0.0-beta.2","unbuild":"^3.5.0","typescript":"^5.8.2","@types/node":"^22.13.8","lint-staged":"^15.4.3","simple-git-hooks":"^2.11.1","@antfu/eslint-config":"^4.4.0"},"simple-git-hooks":{"pre-commit":"pnpm lint-staged"},"_npmOperationalInternal":{"tmp":"tmp/quansync_0.2.8_1740989322005_0.1794434106901326","host":"s3://npm-registry-packages-npm-production"},"readme":"# quansync\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![bundle][bundle-src]][bundle-href]\n[![JSDocs][jsdocs-src]][jsdocs-href]\n[![License][license-src]][license-href]\n\nCreate sync/async APIs with usable logic.\n\n**Quan**tum + **Sync** - \"_Superposition_\" between `sync` and `async`.\n\n- Typesafe\n- ESM, modern JavaScript\n- Zero dependencies\n\nHeavily inspired by [`genasync`](https://github.com/loganfsmyth/gensync) by [@loganfsmyth](https://github.com/loganfsmyth).\n\n## Why & How\n\nPlease refer to Anthony's blog post: [**Async, Sync, in Between**](https://antfu.me/posts/async-sync-in-between).\n\n## Usage\n\n```bash\npnpm i quansync\n```\n\n```ts\nimport fs from 'node:fs'\nimport { quansync } from 'quansync'\n\n// Create a quansync function by providing `sync` and `async` implementations\nconst readFile = quansync({\n  sync: (path: string) => fs.readFileSync(path),\n  async: (path: string) => fs.promises.readFile(path),\n})\n\n// Create a quansync function by providing a generator function\nconst myFunction = quansync(function* (filename) {\n  // Use `yield*` to call another quansync function\n  const code = yield* readFile(filename, 'utf8')\n\n  return `// some custom prefix\\n${code}`\n})\n\n// Use it as a sync function\nconst result = myFunction.sync('./some-file.js')\n\n// Use it as an async function\nconst asyncResult = await myFunction.async('./some-file.js')\n```\n\n### `getIsAsync`\n\nReturns a boolean indicating whether the current execution is in async mode.\n\n```ts\nimport { getIsAsync, quansync } from 'quansync'\n\nconst fn = quansync(function* () {\n  const isAsync: boolean = yield* getIsAsync()\n  console.log(isAsync)\n})\n\nfn.sync() // false\nawait fn() // true\nawait fn.async() // true\n```\n\n## Build-time Macro\n\nIf you don't like the `function*` and `yield*` syntax, we also provide a build-time macro via [unplugin-quansync](https://github.com/quansync-dev/unplugin-quansync#usage) allowing you use quansync with async/await syntax, while still able to get the sync version out of that.\n\nHere is an example:\n\n```ts\nimport fs from 'node:fs'\nimport { quansync } from 'quansync/macro'\n\n// Create a quansync function by providing `sync` and `async` implementations\nconst readFile = quansync({\n  sync: (path: string) => fs.readFileSync(path),\n  async: (path: string) => fs.promises.readFile(path),\n})\n\n// Create a quansync function by providing an **async** function\nconst myFunction = quansync(async (filename) => {\n  // Use `await` to call another quansync function\n  const code = await readFile(filename, 'utf8')\n\n  return `// some custom prefix\\n${code}`\n})\n\n// Use it as a sync function\nconst result = myFunction.sync('./some-file.js')\n\n// Use it as an async function\nconst asyncResult = await myFunction.async('./some-file.js')\n```\n\nFor more details on usage, refer to [unplugin-quansync's docs](https://github.com/unplugin/unplugin-quansync#usage).\n\n## Benchmark\n\nRun the following command to benchmark the performance of `quansync`:\n\n```bash\npnpm run build && pnpm run benchmark\n```\n\nBenchmark results indicate that each `yield` incurs an overhead of\napproximately 150 ns, comparable to that of `await sync()`. (On Apple M1 Max)\n\n## Sponsors\n\n<p align=\"center\">\n  <a href=\"https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg\">\n    <img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>\n  </a>\n</p>\n\n<p align=\"center\">\n  <a href=\"https://cdn.jsdelivr.net/gh/sxzz/sponsors/sponsors.svg\">\n    <img src='https://cdn.jsdelivr.net/gh/sxzz/sponsors/sponsors.svg'/>\n  </a>\n</p>\n\n## License\n\n[MIT](./LICENSE) License © [Anthony Fu](https://github.com/antfu) and [Kevin Deng](https://github.com/sxzz)\n\n<!-- Badges -->\n\n[npm-version-src]: https://img.shields.io/npm/v/quansync?style=flat&colorA=080f12&colorB=1fa669\n[npm-version-href]: https://npmjs.com/package/quansync\n[npm-downloads-src]: https://img.shields.io/npm/dm/quansync?style=flat&colorA=080f12&colorB=1fa669\n[npm-downloads-href]: https://npmjs.com/package/quansync\n[bundle-src]: https://img.shields.io/bundlephobia/minzip/quansync?style=flat&colorA=080f12&colorB=1fa669&label=minzip\n[bundle-href]: https://bundlephobia.com/result?p=quansync\n[license-src]: https://img.shields.io/github/license/antfu/quansync.svg?style=flat&colorA=080f12&colorB=1fa669\n[license-href]: https://github.com/antfu/quansync/blob/main/LICENSE\n[jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669\n[jsdocs-href]: https://www.jsdocs.io/package/quansync\n","publish_time":1740989322208,"_cnpm_publish_time":1740989322208,"dist-tags":{"latest":"1.0.0"}}