Skip to content

Commit ecf2029

Browse files
committedJun 12, 2023
chore: update readme
1 parent 2a4383f commit ecf2029

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed
 

‎README.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# destr
22

3-
A faster, secure and convenient alternative for [`JSON.parse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse):
4-
53
[![npm version][npm-version-src]][npm-version-href]
64
[![npm downloads][npm-downloads-src]][npm-downloads-href]
75
[![bundle][bundle-src]][bundle-href]
86
[![License][license-src]][license-href]
97

8+
A faster, secure and convenient alternative for [`JSON.parse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).
9+
1010
## Usage
1111

1212
### Node.js
1313

14-
Install using npm or yarn:
14+
Install dependency:
1515

1616
```bash
1717
# npm
@@ -27,11 +27,11 @@ pnpm i destr
2727
Import into your Node.js project:
2828

2929
```js
30-
// CommonJS
31-
const { destr, safeDestr } = require("destr");
32-
3330
// ESM
3431
import { destr, safeDestr } from "destr";
32+
33+
// CommonJS
34+
const { destr, safeDestr } = require("destr");
3535
```
3636

3737
### Deno
@@ -44,7 +44,7 @@ console.log(destr('{ "deno": "yay" }'));
4444

4545
## Why?
4646

47-
**Type safe:**
47+
### Type Safe
4848

4949
```js
5050
const obj = JSON.parse("..."); // obj type is any
@@ -54,7 +54,7 @@ const obj = destr("..."); // obj type is unknown by default
5454
const obj = destr < MyInterface > "..."; // obj is well-typed
5555
```
5656

57-
**Fast fallback to input if is not string:**
57+
### Fast fallback to input if is not string
5858

5959
```js
6060
// Uncaught SyntaxError: Unexpected token u in JSON at position 0
@@ -64,7 +64,7 @@ JSON.parse();
6464
destr();
6565
```
6666

67-
**Fast lookup for known string values:**
67+
### Fast lookup for known string values
6868

6969
```js
7070
// Uncaught SyntaxError: Unexpected token T in JSON at position 0
@@ -74,7 +74,7 @@ JSON.parse("TRUE");
7474
destr("TRUE");
7575
```
7676

77-
**Fallback to original value if parse fails (empty or any plain string):**
77+
### Fallback to original value if parse fails (empty or any plain string)
7878

7979
```js
8080
// Uncaught SyntaxError: Unexpected token s in JSON at position 0
@@ -84,7 +84,7 @@ JSON.parse("salam");
8484
destr("salam");
8585
```
8686

87-
**Avoid prototype pollution:**
87+
### Avoid prototype pollution
8888

8989
```js
9090
const input = '{ "user": { "__proto__": { "isAdmin": true } } }';
@@ -96,7 +96,7 @@ JSON.parse(input);
9696
destr(input);
9797
```
9898

99-
### Strict Mode
99+
### Strict Mode
100100

101101
When using `safeDestr` it will throw an error if the input is not a valid JSON string or parsing fails. (non string values and built-ins will be still returned as-is)
102102

0 commit comments

Comments
 (0)
Please sign in to comment.