Skip to content

Commit 8ba402a

Browse files
committed
docs(README): update api
1 parent 4353bc2 commit 8ba402a

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

README.md

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
[![Codecov branch](https://img.shields.io/codecov/c/gh/exuanbo/module-from-string/main?token=B66P1ZSBLD)](https://codecov.io/gh/exuanbo/module-from-string)
88
[![libera manifesto](https://img.shields.io/badge/libera-manifesto-lightgrey.svg)](https://liberamanifesto.com)
99

10-
1110
## Install
1211

1312
```sh
@@ -23,8 +22,8 @@ requireFromString("module.exports = 'hi'") // => 'hi'
2322
requireFromString("exports.salute = 'hi'") // => { salute: 'hi' }
2423

2524
;(async () => {
26-
await importFromString({ code: "export default 'hi'" }) // => { default: 'hi' }
27-
await importFromString({ code: "export const salute = 'hi'" }) // => { salute: 'hi' }
25+
await importFromString("export default 'hi'" ) // => { default: 'hi' }
26+
await importFromString("export const salute = 'hi'") // => { salute: 'hi' }
2827
})()
2928
```
3029

@@ -33,26 +32,19 @@ requireFromString("exports.salute = 'hi'") // => { salute: 'hi' }
3332
```ts
3433
import { TransformOptions } from 'esbuild'
3534

36-
declare const requireFromString: (
37-
code: string,
35+
interface Options {
36+
code: string
3837
globals?: Record<string, unknown>
39-
) => any
38+
}
39+
declare const requireFromString: (options: string | Options) => any
4040

41-
interface ImprotOptions {
42-
code: string
41+
interface ImportOptions extends Options {
4342
transformOptions?: TransformOptions
44-
globals?: Record<string, unknown>
4543
}
46-
declare const importFromString: ({
47-
code,
48-
transformOptions,
49-
globals
50-
}: ImprotOptions) => Promise<any>
51-
declare const importFromStringSync: ({
52-
code,
53-
transformOptions,
54-
globals
55-
}: ImprotOptions) => any
44+
declare const importFromString: (
45+
options: string | ImportOptions
46+
) => Promise<any>
47+
declare const importFromStringSync: (options: string | ImportOptions) => any
5648

5749
export { importFromString, importFromStringSync, requireFromString }
5850
```
@@ -87,11 +79,11 @@ importFromStringSync({
8779

8880
### transformOptions
8981

90-
As bundled `index.d.ts` above, `importFromString` uses esbuild to transform ES Module syntax to CommonJS. So it can do much more by providing transform options to esbuild. See [esbuild Transform API](https://esbuild.github.io/api/#transform-api) for documentation.
82+
Function `importFromString` and `importFromStringSync` use esbuild to transform ES Module syntax to CommonJS. So it can do much more by providing transform options to esbuild. See [esbuild Transform API](https://esbuild.github.io/api/#transform-api) for documentation.
9183

9284
```js
9385
const { salute } = importFromStringSync({
94-
code: "export const salute: string = () => 'hi'",
86+
code: "export const salute: () => string = () => 'hi'",
9587
transformOptions: { loader: 'ts' }
9688
})
9789

0 commit comments

Comments
 (0)