From 60b3f81c86ba43f85f922155940150a0c254cda5 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Mon, 12 Jun 2023 14:37:48 +0200 Subject: [PATCH] chore: update readme --- README.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a6c2e0c..3133807 100644 --- a/README.md +++ b/README.md @@ -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("{}"); // 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(); @@ -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"); @@ -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"); @@ -84,6 +90,8 @@ JSON.parse("salam"); destr("salam"); ``` +**Note:** This fails in safe/strict mode with `safeDestr`. + ### ✅ Avoid prototype pollution ```js