From 801f3d77ba075bb3ae603562cafdd5f04f1b55dd Mon Sep 17 00:00:00 2001 From: Ikwue Inalegwu Date: Mon, 16 Sep 2024 01:19:42 +0100 Subject: [PATCH] added readme.md --- README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..8e60416 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +## MakeSafeFunc +Finally be sure your functions don't throw + + + +MakeSafeFunc was created to wrap functions I'm not sure +can throw and returning a simple Result type by utilizing +neverthrow under the hood + + + + +### Examples + +```ts +import {makeSafeFunc} from "make-safe-func"; + +function unsafeDivide(a:number,b:number){ + if(b===0) throw new Error("Divide by Zero Error"); + return a/b +} + +const safeDivide=makeSafeFunc(unsafeDivide); + +safeDivide(1/2).match(console.log,console.error); +const result=safeDivide._unsafeUnwrap(); + +console.log(result); +```