{"name":"quansync","type":"module","version":"1.0.0","description":"Create sync/async APIs with usable logic","author":{"name":"Anthony Fu","email":"anthonyfu117@hotmail.com"},"contributors":[{"name":"Kevin Deng","email":"sxzz@sxzz.moe"}],"license":"MIT","funding":[{"type":"individual","url":"https://github.com/sponsors/antfu"},{"type":"individual","url":"https://github.com/sponsors/sxzz"}],"homepage":"https://github.com/quansync-dev/quansync#readme","repository":{"type":"git","url":"git+https://github.com/quansync-dev/quansync.git"},"bugs":{"url":"https://github.com/quansync-dev/quansync/issues"},"keywords":["async","sync","generator"],"sideEffects":false,"exports":{".":"./dist/index.js","./macro":"./dist/macro.js","./package.json":"./package.json"},"main":"./dist/index.js","module":"./dist/index.js","types":"./dist/index.d.ts","typesVersions":{"*":{"*":["./dist/*.d.mts","./*"]}},"devDependencies":{"@antfu/eslint-config":"^6.2.0","@types/node":"^24.10.1","@typescript/native-preview":"7.0.0-dev.20251202.1","bumpp":"^10.3.2","eslint":"^9.39.1","gensync":"1.0.0-beta.2","lint-staged":"^16.2.7","mitata":"^1.0.34","simple-git-hooks":"^2.13.1","tsdown":"^0.17.0-beta.5","typescript":"^5.9.3","vite":"^7.2.6","vitest":"^4.0.15"},"simple-git-hooks":{"pre-commit":"pnpm lint-staged"},"lint-staged":{"*":"eslint --fix"},"scripts":{"build":"tsdown","dev":"tsdown -w","lint":"eslint .","release":"bumpp","benchmark":"node scripts/benchmark.js","test":"vitest","typecheck":"tsgo --noEmit"},"_id":"quansync@1.0.0","_integrity":"sha512-5xZacEEufv3HSTPQuchrvV6soaiACMFnq1H8wkVioctoH3TRha9Sz66lOxRwPK/qZj7HPiSveih9yAyh98gvqA==","_resolved":"/tmp/d8cb87fdaad4d802c3273c58a3827d51/quansync-1.0.0.tgz","_from":"file:quansync-1.0.0.tgz","_nodeVersion":"24.11.1","_npmVersion":"11.6.2","dist":{"integrity":"sha512-5xZacEEufv3HSTPQuchrvV6soaiACMFnq1H8wkVioctoH3TRha9Sz66lOxRwPK/qZj7HPiSveih9yAyh98gvqA==","shasum":"1c29acccd544cd68d97a7350c5099e0a9bc7e5ee","tarball":"http://registry-npm.ywwl.com/quansync/download/quansync-1.0.0.tgz","fileCount":9,"unpackedSize":14891,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/quansync@1.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCu4DV0Z02rck7I8g48HNGdAZcokNkxPm3BRITtJMwV+wIgUNijDLUWNQMuLcnbH8RhZaO2BQ8L+j30DeEIXtYdxHo="}],"size":5071,"noattachment":false,"key":"/quansync/-/quansync-1.0.0.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:d56f37aa-b2f2-4531-9ed3-bd7f83bb7fc9"}},"directories":{},"maintainers":[{"name":"antfu","email":"anthonyfu117@hotmail.com"},{"name":"sxzz","email":"sxzz@sxzz.moe"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/quansync_1.0.0_1764874292571_0.6849216389939987"},"_hasShrinkwrap":false,"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":1764874292718,"_cnpm_publish_time":1764874292718,"dist-tags":{"latest":"1.0.0"}}