Skip to content

Commit 90ccc06

Browse files
committed
chore: add docs
1 parent 9ddae30 commit 90ccc06

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

README.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
[![Unit Test](https://github.com/unplugin/unplugin-quansync/actions/workflows/unit-test.yml/badge.svg)](https://github.com/unplugin/unplugin-quansync/actions/workflows/unit-test.yml)
44

5-
undefined
6-
7-
5+
Write async functions, get both async and sync functions with
6+
[quansync](https://github.com/antfu/quansync) and compiler magics.
87

98
## Installation
109

@@ -98,6 +97,33 @@ export default {
9897

9998
<br></details>
10099

100+
## Usage
101+
102+
```ts
103+
import fs from 'node:fs'
104+
import { quansyncMacro } from 'quansync'
105+
106+
// Create an quansync function by providing `sync` and `async` implementations
107+
const readFile = quansyncMacro({
108+
sync: (path: string) => fs.readFileSync(path),
109+
async: (path: string) => fs.promises.readFile(path),
110+
})
111+
112+
// Create an quansync function by providing a **async** function
113+
const myFunction = quansyncMacro(async function (filename) {
114+
// Use `await` to call another quansync function
115+
const code = await readFile(filename, 'utf8')
116+
117+
return `// some custom prefix\n${code}`
118+
})
119+
120+
// Use it as a sync function
121+
const result = myFunction.sync('./some-file.js')
122+
123+
// Use it as an async function
124+
const asyncResult = await myFunction.async('./some-file.js')
125+
```
126+
101127
## Sponsors
102128

103129
<p align="center">

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "unplugin-quansync",
33
"version": "0.0.0",
44
"packageManager": "[email protected]",
5-
"description": "undefined",
5+
"description": "Write async functions, get both async and sync functions",
66
"type": "module",
77
"keywords": [
88
"unplugin",

0 commit comments

Comments
 (0)