File tree Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Original file line number Diff line number Diff line change 2
2
3
3
[ ![ 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 )
4
4
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.
8
7
9
8
## Installation
10
9
@@ -98,6 +97,33 @@ export default {
98
97
99
98
<br ></details >
100
99
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
+
101
127
## Sponsors
102
128
103
129
<p align =" center " >
Original file line number Diff line number Diff line change 2
2
"name" : " unplugin-quansync" ,
3
3
"version" : " 0.0.0" ,
4
4
"packageManager" :
" [email protected] " ,
5
- "description" : " undefined " ,
5
+ "description" : " Write async functions, get both async and sync functions " ,
6
6
"type" : " module" ,
7
7
"keywords" : [
8
8
" unplugin" ,
You can’t perform that action at this time.
0 commit comments