Skip to content

Commit 499d6a4

Browse files
authored
Add Section on Setting up Type Declarations for Deno in README.md (#127)
* docs: Add section on setting up type declarations for Deno * docs: put Add Type Declarations for Deno in a collapsible * docs: optimize instructions on specifying lib version on deno
1 parent bd0f9af commit 499d6a4

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

README.md

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,37 @@ import { Fido2Lib } from "fido2-lib";
5656
### Deno
5757

5858
Import `dist/main.js` from a trusted source. Below is only an example, using the official deno.land repository.
59-
It is recommended to [enable integrity checking](https://deno.land/manual/linking_to_external_code/integrity_checking).
60-
61-
Get url to the latest version by going to [deno.land/x/fido2/dist/main.js](https://deno.land/x/fido2/dist/main.js).
59+
It is recommended to [enable integrity checking](https://deno.land/manual/linking_to_external_code/integrity_checking).
6260

6361
```js
64-
// Example url will always redirect to the latest version
65-
// It is recommended that you use the method mentioned above to get a fixed url
66-
import { Fido2Lib } from "https://deno.land/x/fido2/dist/main.js";
62+
import { Fido2Lib } from "https://deno.land/x/fido2@$VERSION/dist/main.js";
6763
```
6864

65+
<details>
66+
<summary>Add Type Declarations</summary>
67+
68+
Firstly, you need to set up a [import map](https://deno.land/manual/basics/import_maps).
69+
Put the following lines into your import map.
70+
71+
```json
72+
{
73+
"imports": {
74+
"fido2-lib": "https://deno.land/x/fido2@$VERSION/dist/main.js"
75+
}
76+
}
77+
```
78+
79+
Then you can import the library like this:
80+
81+
```ts
82+
// @deno-types="https://deno.land/x/fido2@$VERSION/types/main.d.ts"
83+
import { Fido2Lib } from "fido2-lib";
84+
```
85+
86+
</details>
87+
88+
Don't forget to replace `$VERSION` with the specific version. You can find the latest version by checking the redirection of [deno.land/x/fido2/dist/main.js](https://deno.land/x/fido2/dist/main.js) and [deno.land/x/fido2/types/main.d.ts](https://deno.land/x/fido2/types/main.d.ts).
89+
6990
## Examples
7091

7192
**Instantiate Library (Complex):**

0 commit comments

Comments
 (0)