@flattype/shared 1.9.0 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.cts +30 -1
- package/dist/index.d.ts +30 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -5,6 +5,10 @@ type JsonValue = JsonPrimitive | JsonValue[] | {
|
|
|
5
5
|
};
|
|
6
6
|
/** Cell separator for inline arrays and table rows. */
|
|
7
7
|
type Delimiter = "," | "|" | "\t";
|
|
8
|
+
/** Like the `JSON.stringify` replacer: called with `this` set to the holder of each key. */
|
|
9
|
+
type Replacer = (this: any, key: string, value: any) => any;
|
|
10
|
+
/** Like the `JSON.parse` reviver: called bottom-up with `this` set to the holder of each key. */
|
|
11
|
+
type Reviver = (this: any, key: string, value: any) => any;
|
|
8
12
|
interface EncodeOptions {
|
|
9
13
|
/** Separator for inline arrays and table rows. Default `","`. */
|
|
10
14
|
delimiter?: Delimiter;
|
|
@@ -12,10 +16,35 @@ interface EncodeOptions {
|
|
|
12
16
|
indent?: number;
|
|
13
17
|
/** `"auto"` writes arrays of same-shaped objects as tables (header once, then rows). Default `"auto"`. */
|
|
14
18
|
tabular?: "auto" | "off";
|
|
19
|
+
/**
|
|
20
|
+
* A function that can change or drop (`undefined`) each value, or a list of the object keys to keep,
|
|
21
|
+
* exactly like the second argument of `JSON.stringify`.
|
|
22
|
+
*/
|
|
23
|
+
replacer?: Replacer | (string | number)[];
|
|
24
|
+
/**
|
|
25
|
+
* Write an object that appears more than once (a shared object or a cycle) only once, and
|
|
26
|
+
* `path = first.path` where it appears again. Without it, shared objects are repeated and cycles throw.
|
|
27
|
+
* Default `false`.
|
|
28
|
+
*/
|
|
29
|
+
refs?: boolean;
|
|
15
30
|
}
|
|
16
31
|
interface DecodeOptions {
|
|
17
32
|
/** Throw on malformed input (default). Set `false` to recover what it can, e.g. from LLM output. */
|
|
18
33
|
strict?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* With `strict: false`: drop any line that can't be read (prose around data, a path that conflicts) as if
|
|
36
|
+
* it weren't there, instead of throwing. That's what `fromModelOutput` uses. Default `false`.
|
|
37
|
+
*/
|
|
38
|
+
skipInvalidLines?: boolean;
|
|
39
|
+
/** Called for every value after decoding, bottom-up, exactly like the second argument of `JSON.parse`. */
|
|
40
|
+
reviver?: Reviver;
|
|
41
|
+
/**
|
|
42
|
+
* Accept `path = other.path` references and rebuild the shared objects and cycles they describe.
|
|
43
|
+
* Off by default: a few reference lines can describe a graph that is huge or endless when walked, so only
|
|
44
|
+
* turn it on for text you trust or code that handles cycles. Without it, a reference is an error
|
|
45
|
+
* (strict) or skipped (lenient).
|
|
46
|
+
*/
|
|
47
|
+
refs?: boolean;
|
|
19
48
|
}
|
|
20
49
|
/** A leaf in a flattened record: a primitive, or an empty object/array that has no leaves of its own. */
|
|
21
50
|
type FlatLeaf = JsonPrimitive | Record<string, never> | never[];
|
|
@@ -41,4 +70,4 @@ interface Decoder {
|
|
|
41
70
|
end(): JsonValue;
|
|
42
71
|
}
|
|
43
72
|
|
|
44
|
-
export type { DecodeOptions, Decoder, DecoderOptions, Delimiter, EncodeOptions, FlatLeaf, FlatRecord, JsonPrimitive, JsonValue, TableRow };
|
|
73
|
+
export type { DecodeOptions, Decoder, DecoderOptions, Delimiter, EncodeOptions, FlatLeaf, FlatRecord, JsonPrimitive, JsonValue, Replacer, Reviver, TableRow };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,10 @@ type JsonValue = JsonPrimitive | JsonValue[] | {
|
|
|
5
5
|
};
|
|
6
6
|
/** Cell separator for inline arrays and table rows. */
|
|
7
7
|
type Delimiter = "," | "|" | "\t";
|
|
8
|
+
/** Like the `JSON.stringify` replacer: called with `this` set to the holder of each key. */
|
|
9
|
+
type Replacer = (this: any, key: string, value: any) => any;
|
|
10
|
+
/** Like the `JSON.parse` reviver: called bottom-up with `this` set to the holder of each key. */
|
|
11
|
+
type Reviver = (this: any, key: string, value: any) => any;
|
|
8
12
|
interface EncodeOptions {
|
|
9
13
|
/** Separator for inline arrays and table rows. Default `","`. */
|
|
10
14
|
delimiter?: Delimiter;
|
|
@@ -12,10 +16,35 @@ interface EncodeOptions {
|
|
|
12
16
|
indent?: number;
|
|
13
17
|
/** `"auto"` writes arrays of same-shaped objects as tables (header once, then rows). Default `"auto"`. */
|
|
14
18
|
tabular?: "auto" | "off";
|
|
19
|
+
/**
|
|
20
|
+
* A function that can change or drop (`undefined`) each value, or a list of the object keys to keep,
|
|
21
|
+
* exactly like the second argument of `JSON.stringify`.
|
|
22
|
+
*/
|
|
23
|
+
replacer?: Replacer | (string | number)[];
|
|
24
|
+
/**
|
|
25
|
+
* Write an object that appears more than once (a shared object or a cycle) only once, and
|
|
26
|
+
* `path = first.path` where it appears again. Without it, shared objects are repeated and cycles throw.
|
|
27
|
+
* Default `false`.
|
|
28
|
+
*/
|
|
29
|
+
refs?: boolean;
|
|
15
30
|
}
|
|
16
31
|
interface DecodeOptions {
|
|
17
32
|
/** Throw on malformed input (default). Set `false` to recover what it can, e.g. from LLM output. */
|
|
18
33
|
strict?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* With `strict: false`: drop any line that can't be read (prose around data, a path that conflicts) as if
|
|
36
|
+
* it weren't there, instead of throwing. That's what `fromModelOutput` uses. Default `false`.
|
|
37
|
+
*/
|
|
38
|
+
skipInvalidLines?: boolean;
|
|
39
|
+
/** Called for every value after decoding, bottom-up, exactly like the second argument of `JSON.parse`. */
|
|
40
|
+
reviver?: Reviver;
|
|
41
|
+
/**
|
|
42
|
+
* Accept `path = other.path` references and rebuild the shared objects and cycles they describe.
|
|
43
|
+
* Off by default: a few reference lines can describe a graph that is huge or endless when walked, so only
|
|
44
|
+
* turn it on for text you trust or code that handles cycles. Without it, a reference is an error
|
|
45
|
+
* (strict) or skipped (lenient).
|
|
46
|
+
*/
|
|
47
|
+
refs?: boolean;
|
|
19
48
|
}
|
|
20
49
|
/** A leaf in a flattened record: a primitive, or an empty object/array that has no leaves of its own. */
|
|
21
50
|
type FlatLeaf = JsonPrimitive | Record<string, never> | never[];
|
|
@@ -41,4 +70,4 @@ interface Decoder {
|
|
|
41
70
|
end(): JsonValue;
|
|
42
71
|
}
|
|
43
72
|
|
|
44
|
-
export type { DecodeOptions, Decoder, DecoderOptions, Delimiter, EncodeOptions, FlatLeaf, FlatRecord, JsonPrimitive, JsonValue, TableRow };
|
|
73
|
+
export type { DecodeOptions, Decoder, DecoderOptions, Delimiter, EncodeOptions, FlatLeaf, FlatRecord, JsonPrimitive, JsonValue, Replacer, Reviver, TableRow };
|