Skip to content

Commit

Permalink
chore: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jun 12, 2023
1 parent ecf2029 commit 60b3f81
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions README.md
Expand Up @@ -44,18 +44,20 @@ console.log(destr('{ "deno": "yay" }'));

## Why?

### ✅Type Safe
### Type Safe

```js
const obj = JSON.parse("..."); // obj type is any
```ts
const obj = JSON.parse("{}"); // obj type is any

const obj = destr("..."); // obj type is unknown by default
const obj = destr("{}"); // obj type is unknown by default

const obj = destr < MyInterface > "..."; // obj is well-typed
const obj = destr<MyInterface>("{}"); // obj is well-typed
```

### ✅ Fast fallback to input if is not string

> 🚀 Up to 500 faster than `JSON.parse`!
```js
// Uncaught SyntaxError: Unexpected token u in JSON at position 0
JSON.parse();
Expand All @@ -66,6 +68,8 @@ destr();

### ✅ Fast lookup for known string values

> 🚀 Up to 900 times faster than `JSON.parse`!
```js
// Uncaught SyntaxError: Unexpected token T in JSON at position 0
JSON.parse("TRUE");
Expand All @@ -76,6 +80,8 @@ destr("TRUE");

### ✅ Fallback to original value if parse fails (empty or any plain string)

> 🚀 Up to 900 times faster than `JSON.parse`!
```js
// Uncaught SyntaxError: Unexpected token s in JSON at position 0
JSON.parse("salam");
Expand All @@ -84,6 +90,8 @@ JSON.parse("salam");
destr("salam");
```

**Note:** This fails in safe/strict mode with `safeDestr`.

### ✅ Avoid prototype pollution

```js
Expand Down

0 comments on commit 60b3f81

Please sign in to comment.