Skip to content

Commit

Permalink
docs: đź“ť update readme for missing pkgs; add JS/TS notes
Browse files Browse the repository at this point in the history
  • Loading branch information
TomKopp authored Sep 13, 2024
1 parent 80b0bd8 commit 4fc64c6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
30 changes: 30 additions & 0 deletions JavaScript-TypeScript-Notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# JavaScript and TypeScript Notes

The following is a type definition for a conversion roundtrip from obj to json to obj.\
@see {@link https://effectivetypescript.com/2020/04/09/jsonify/}

```ts
// export type JsonifySimple<T> = T extends { toJSON(): infer U }
// ? U
// : T extends object
// ? { [k in keyof T]: Jsonify<T[k]> }
// : T;

export type Jsonify<T> = T extends { toJSON: (...args: any) => infer R }
? Jsonify<R>
: T extends Array<infer I>
? Array<Jsonify<I>>
: T extends (...args: any) => any
? never
: T extends object
? { [K in keyof T]: K extends string | number ? Jsonify<T[K]> : never }
: T;
```

---

Get the single type of an array type e.g: User[] -> User

```ts
type GetElementType<T extends any[]> = T extends (infer U)[] ? U : never;
```
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ be triggered. The function will be called after it stops being called for
N milliseconds. If `immediate` is passed, trigger the function on the
leading edge, instead of the trailing.

## FetchHelper

Extracts the content from the body of a Response object either\
as json (if Content-Type=application/json),\
as text (if Content-Type=text/*),\
or as a Blob if all else fails.

## JsonParse

Wrapper around Json.parse() to catch any errors and return a Promise.\
The synchronous version returns an Object with data and error properties.\
If the parsing failed the error is set. Otherwise it is undefined.

## MapValueRange

Maps a value in an input range to an output range.
Expand Down
6 changes: 1 addition & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4fc64c6

Please sign in to comment.