Skip to content

Commit

Permalink
improving readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Inalegwu committed Sep 16, 2024
1 parent 9cc9b45 commit 125a57b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,33 @@ neverthrow under the hood
</i>


## Why MakeSafeFunc ?

MakeSafeFunc is designed to bring make the Result Types and functional
Principles that [neverthrow](https://github.com/supermacro/neverthrow)
is working to make available to Typescript Developers, To legacy projects.

MakeSafeFunc is targetted at developers working in systems where code has been
defined from a long time ago and it wouldn't be worth it to convert it all to
neverthrow. You can simply work from where you are now and integrate with MakeSafeFunc
instead

```ts
import {functionFromLegacy} from "@acme/legacy";
import {makeSafeFunc} from "@disgruntleddevs/make-safe-func";

const result=makeSafeFunc(functionFromLegacy)(params,from,legacyCode)

// all the niceties... none of the refactoring work
result.match();
result.unwrapOr();
result.isOk();
result.value;
result.error;
result.map()

```


## Examples

Expand All @@ -30,7 +57,7 @@ safeDivide(1/2).match(console.log,console.error);
```ts
import {makeSafeFunc} from "make-safe-func";

function unsafeFetch(url:string){
async function unsafeFetch(url:string){
const result=await fetch(url);

return result
Expand Down Expand Up @@ -110,4 +137,10 @@ const increment=(v:number)=>v+1;
// result that might fail. You must return a new Result
// Value
const res=safeDivide(1/2).andThen()
```
```

<i>The MakeSafeFunc docs are sparse because most of it's power is derived from
[neverthrow](https://github.com/supermacro/neverthrow) so the docs for neverthrow
will be your friend.
These are simply examples of the context makeSafeFunc is useful for
</i>
4 changes: 2 additions & 2 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@disgruntleddevs/make-safe-func",
"description": "Finally be sure your function don't throw",
"description": "Finally be sure your functions don't throw",
"license": "MIT",
"version": "0.0.8",
"version": "0.0.9",
"exports": "./src/index.ts",
"tasks": {
"dev": "deno run --watch main.ts"
Expand Down

0 comments on commit 125a57b

Please sign in to comment.