From f0ce6ff7dd3fb037fd2845ed1c4df38c0e9d4b0c Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Sat, 30 Nov 2024 12:24:22 +0100 Subject: [PATCH] Try to avoid scroll in readme table (#49) --- README.md | 188 +++++++++++++++++++++++++++++------------------------- 1 file changed, 101 insertions(+), 87 deletions(-) diff --git a/README.md b/README.md index 86f474d..3f79fff 100644 --- a/README.md +++ b/README.md @@ -178,15 +178,14 @@ Here’s a summary of all codecs (with slightly simplified type annotations) and 1, 2, true -]) => - Codec< - "string1" - | "string2" - | "stringN" - | 1 - | 2 - | true - > +]) => Codec< + "string1" + | "string2" + | "stringN" + | 1 + | 2 + | true +> string, number, boolean, null
"string1"
 | "string2"
@@ -198,157 +197,172 @@ Here’s a summary of all codecs (with slightly simplified type annotations) and
 
 array
 
(decoder: Codec<T>) =>
-  Codec<Array<T>>
+ Codec<Array<T>>
array Array<T> record
(decoder: Codec<T>) =>
-  Codec<Record<string, T>>
+ Codec<Record<string, T>> object Record<string, T> fields
(mapping: {
-  field1: Codec<T1>,
-  field2: Field<T2, {optional: true}>,
-  field3: Field<T3, {renameFrom: "field_3"}>,
-  fieldN: Codec<TN>
-}) =>
-  Codec<{
-    field1: T1,
-    field2?: T2,
-    field3: T3,
-    fieldN: TN
-  }>
+ field1: Codec<T1>, + field2: Field< + T2, + { optional: true } + >, + field3: Field< + T3, + { renameFrom: "field_3" } + >, + fieldN: Codec<TN> +}) => Codec<{ + field1: T1, + field2?: T2, + field3: T3, + fieldN: TN +}>
{
-  "field1": ...,
-  "field2": ...,
-  "field_3": ...,
-  "fieldN": ...
+ "field1": ...,
+ "field2": ...,
+ "field_3": ...,
+ "fieldN": ...
 }
or:
{
-  "field1": ...,
-  "field_3": ...,
-  "fieldN": ...
+ "field1": ...,
+ "field_3": ...,
+ "fieldN": ...
 }
{
-  field1: T1,
-  field2?: T2,
-  field3: T3,
-  fieldN: TN
+ field1: T1,
+ field2?: T2,
+ field3: T3,
+ fieldN: TN
 }
field
(
-  codec: Codec<Decoded>,
-  meta: Meta,
-) => Field<Decoded, Meta>
+ codec: Codec<Decoded>, + meta: Meta, +) => Field<Decoded, Meta> n/a n/a, only used with fields taggedUnion
(
-  decodedCommonField: string,
-  variants: Array<
-    Parameters<typeof fields>[0]
-  >,
-) =>
-  Codec<T1 | T2 | TN>
+ decodedCommonField: string, + variants: Array< + Parameters<typeof fields>[0] + >, +) => Codec<T1 | T2 | TN> object T1 | T2 | TN tag
(
-  decoded: "string literal",
-  options?: Options,
-) => Field<"string literal", Meta>
+ decoded: "string literal", + options?: Options, +) => + Field<"string literal", Meta> string "string literal" tuple
(codecs: [
-  Codec<T1>,
-  Codec<T2>,
-  Codec<TN>
-]) =>
-  Codec<[T1, T2, TN]>
+ Codec<T1>, + Codec<T2>, + Codec<TN> +]) => Codec<[T1, T2, TN]> array [T1, T2, TN] multi
(types: [
-  "type1",
-  "type2",
-  "type10"
-]) =>
-  Codec<
-    { type: "type1", value: type1 }
-    | { type: "type2", value: type2 }
-    | { type: "type10", value: type10 }
-  >
+ "type1", + "type2", + "type10" +]) => Codec< + { type: "type1", + value: type1 } + | { type: "type2", + value: type2 } + | { type: "type10", + value: type10 } +> you decide -A subset of:
{ type: "undefined"; value: undefined }
-| { type: "null"; value: null }
-| { type: "boolean"; value: boolean }
-| { type: "number"; value: number }
-| { type: "bigint"; value: bigint }
-| { type: "string"; value: string }
-| { type: "symbol"; value: symbol }
-| { type: "function"; value: Function }
-| { type: "array"; value: Array }
-| { type: "object"; value: Record }
+A subset of:
  { type: "undefined";
+    value: undefined }
+| { type: "null";
+    value: null }
+| { type: "boolean";
+    value: boolean }
+| { type: "number";
+    value: number }
+| { type: "bigint";
+    value: bigint }
+| { type: "string";
+    value: string }
+| { type: "symbol";
+    value: symbol }
+| { type: "function";
+    value: Function }
+| { type: "array";
+    value: Array }
+| { type: "object";
+    value: Record }
recursive -
(callback: () => Codec<T>) =>
-  Codec<T>
+
(callback: () => Codec<T>) =>
+ Codec<T>
n/a T undefinedOr
(codec: Codec<T>) =>
-  Codec<T | undefined>
+ Codec<T | undefined> undefined or … T | undefined nullOr
(codec: Codec<T>) =>
-  Codec<T | null>
+ Codec<T | null> null or … T | null map
(
-  codec: Codec<T>,
-  transform: {
-    decoder: (value: T) => U;
-    encoder: (value: U) => T;
-  },
-) =>
-  Codec<U>
+ codec: Codec<T>, + transform: { + decoder: (value: T) => U; + encoder: (value: U) => T; + }, +) => Codec<U> n/a U flatMap
(
-  decoder: Codec<T>,
-  transform: {
-    decoder: (value: T) => DecoderResult<U>;
-    encoder: (value: U) => T;
-  },
-) =>
-  Codec<U>
+ decoder: Codec<T>, + transform: { + decoder: (value: T) => + DecoderResult<U>; + encoder: (value: U) => T; + }, +) => Codec<U> n/a U