lacspace-json 0.1.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/lib.d.cts ADDED
@@ -0,0 +1,151 @@
1
+ /** Compile a query string into a reusable evaluator (throws on parse error). */
2
+ declare function compileQuery(expr: string): (data: unknown) => unknown[];
3
+ /**
4
+ * Run `expr` against `data`. Returns the single result when the query yields
5
+ * exactly one value, otherwise an array of all results (jq's stream semantics).
6
+ */
7
+ declare function query(data: unknown, expr: string): unknown;
8
+ /** Run `expr` and always return the full result stream as an array. */
9
+ declare function queryAll(data: unknown, expr: string): unknown[];
10
+ /** True if `expr` parses. */
11
+ declare function isValidQuery(expr: string): boolean;
12
+
13
+ /**
14
+ * Shared helpers: JSON value types, deep equality, safe object construction
15
+ * (prototype-pollution guarded) and type classification.
16
+ */
17
+ type JsonPrimitive = string | number | boolean | null;
18
+ type JsonValue = JsonPrimitive | JsonValue[] | {
19
+ [key: string]: JsonValue;
20
+ };
21
+ type JsonObject = {
22
+ [key: string]: JsonValue;
23
+ };
24
+ /** True for a non-null, non-array object. */
25
+ declare function isPlainObject(v: unknown): v is Record<string, unknown>;
26
+ /** jq-style type name for a JSON value. */
27
+ declare function typeOf(v: unknown): "null" | "boolean" | "number" | "string" | "array" | "object";
28
+ /** Structural deep equality for JSON values. */
29
+ declare function deepEqual(a: unknown, b: unknown): boolean;
30
+ /** Deep clone of a JSON value (safe against prototype pollution). */
31
+ declare function deepClone<T>(v: T): T;
32
+ /**
33
+ * A stable ordering for JSON values, used by `sort_by`, `unique`, `min`/`max`.
34
+ * Ordering mirrors jq: null < false < true < numbers < strings < arrays < objects.
35
+ */
36
+ declare function compareValues(a: unknown, b: unknown): number;
37
+ /** Recursively sort object keys (used by `--sort-keys`). */
38
+ declare function sortKeysDeep(v: unknown): unknown;
39
+ /** A rendering-safe error carrying an optional path for CLI display. */
40
+ declare class JsonToolError extends Error {
41
+ path?: string;
42
+ constructor(message: string, path?: string);
43
+ }
44
+
45
+ type Format = "json" | "yaml" | "toml" | "csv" | "ndjson";
46
+ /** Guess a format from a filename extension, else undefined. */
47
+ declare function formatFromExt(filename: string): Format | undefined;
48
+ /** Best-effort format detection from the content itself. */
49
+ declare function detectFormat(src: string): Format;
50
+ /** Parse `src` in the given format into a JSON value. */
51
+ declare function parseFormat(src: string, format: Format): JsonValue;
52
+ /** Serialize a JSON value into the given format. */
53
+ declare function stringifyFormat(value: JsonValue, format: Format, opts?: {
54
+ indent?: number;
55
+ sortKeys?: boolean;
56
+ minify?: boolean;
57
+ }): string;
58
+ /** Convert text from one format to another. */
59
+ declare function convert(src: string, from: Format, to: Format, opts?: {
60
+ indent?: number;
61
+ minify?: boolean;
62
+ }): string;
63
+ /**
64
+ * Recursively rebuild a parsed JSON value dropping prototype-pollution keys.
65
+ * `JSON.parse` itself is safe, but downstream merges/writes should never carry a
66
+ * literal `__proto__` own key, so we strip them at the boundary.
67
+ */
68
+ declare function sanitizeJson(v: unknown): JsonValue;
69
+
70
+ /** Parse a YAML document into a JSON value. */
71
+ declare function parseYaml(src: string): JsonValue;
72
+ /** Serialize a JSON value to YAML. */
73
+ declare function stringifyYaml(value: JsonValue): string;
74
+
75
+ /** Parse a TOML document into a JSON value (object). */
76
+ declare function parseToml(src: string): JsonValue;
77
+ /** Serialize a JSON object to TOML. Throws if the top level is not an object. */
78
+ declare function stringifyToml(value: JsonValue): string;
79
+
80
+ interface CsvParseOptions {
81
+ delimiter?: string;
82
+ parseTypes?: boolean;
83
+ }
84
+ /** Parse CSV text into an array of objects (or arrays if no header wanted). */
85
+ declare function parseCsv(src: string, opts?: CsvParseOptions): JsonValue;
86
+ interface CsvStringifyOptions {
87
+ delimiter?: string;
88
+ columns?: string[];
89
+ }
90
+ /** Serialize an array of flat objects to CSV. */
91
+ declare function stringifyCsv(value: JsonValue, opts?: CsvStringifyOptions): string;
92
+ /** Parse NDJSON (one JSON value per line) into an array. */
93
+ declare function parseNdjson(src: string): JsonValue;
94
+ /** Serialize an array to NDJSON (one compact JSON value per line). */
95
+ declare function stringifyNdjson(value: JsonValue): string;
96
+
97
+ interface ValidationError {
98
+ path: string;
99
+ message: string;
100
+ }
101
+ interface ValidationResult {
102
+ valid: boolean;
103
+ errors: ValidationError[];
104
+ }
105
+ /** Validate `data` against a JSON Schema. Returns `{ valid, errors[] }`. */
106
+ declare function validateSchema(data: JsonValue, schema: JsonValue): ValidationResult;
107
+
108
+ type DiffKind = "added" | "removed" | "changed";
109
+ interface DiffEntry {
110
+ kind: DiffKind;
111
+ path: string;
112
+ before?: JsonValue;
113
+ after?: JsonValue;
114
+ }
115
+ /** Compute a flat list of differences turning `a` into `b`. */
116
+ declare function diff(a: JsonValue, b: JsonValue): DiffEntry[];
117
+ /** True if the two values are structurally identical. */
118
+ declare function isEqual(a: JsonValue, b: JsonValue): boolean;
119
+
120
+ type ArrayStrategy = {
121
+ mode: "concat";
122
+ } | {
123
+ mode: "replace";
124
+ } | {
125
+ mode: "by-key";
126
+ key: string;
127
+ };
128
+ interface MergeOptions {
129
+ array?: ArrayStrategy;
130
+ }
131
+ /** Deep-merge two or more JSON values left-to-right. */
132
+ declare function merge(values: JsonValue[], opts?: MergeOptions): JsonValue;
133
+ /** Parse a CLI `--array` flag into a strategy. */
134
+ declare function parseArrayStrategy(spec: string | undefined, byKey?: string): ArrayStrategy;
135
+
136
+ interface FormatOptions {
137
+ indent?: number;
138
+ sortKeys?: boolean;
139
+ minify?: boolean;
140
+ }
141
+ /** Pretty-print (or minify) a JSON value. */
142
+ declare function formatJson(value: JsonValue, opts?: FormatOptions): string;
143
+ /**
144
+ * Resolve a dotted / bracketed path (`.a.b[0].c`, `a.b`, `users[2].name`) to a
145
+ * single value. Returns `undefined` if any segment is missing.
146
+ */
147
+ declare function getPath(data: JsonValue, path: string): JsonValue | undefined;
148
+ /** Tokenize a path string into key/index segments. */
149
+ declare function parsePath(path: string): Array<string | number>;
150
+
151
+ export { type ArrayStrategy, type CsvParseOptions, type CsvStringifyOptions, type DiffEntry, type DiffKind, type Format, type FormatOptions, type JsonObject, type JsonPrimitive, JsonToolError, type JsonValue, type MergeOptions, type ValidationError, type ValidationResult, compareValues, compileQuery, convert, deepClone, deepEqual, detectFormat, diff, formatFromExt, formatJson, getPath, isEqual, isPlainObject, isValidQuery, merge, parseArrayStrategy, parseCsv, parseFormat, parseNdjson, parsePath, parseToml, parseYaml, query, queryAll, sanitizeJson, sortKeysDeep, stringifyCsv, stringifyFormat, stringifyNdjson, stringifyToml, stringifyYaml, typeOf, validateSchema };
package/dist/lib.d.ts ADDED
@@ -0,0 +1,151 @@
1
+ /** Compile a query string into a reusable evaluator (throws on parse error). */
2
+ declare function compileQuery(expr: string): (data: unknown) => unknown[];
3
+ /**
4
+ * Run `expr` against `data`. Returns the single result when the query yields
5
+ * exactly one value, otherwise an array of all results (jq's stream semantics).
6
+ */
7
+ declare function query(data: unknown, expr: string): unknown;
8
+ /** Run `expr` and always return the full result stream as an array. */
9
+ declare function queryAll(data: unknown, expr: string): unknown[];
10
+ /** True if `expr` parses. */
11
+ declare function isValidQuery(expr: string): boolean;
12
+
13
+ /**
14
+ * Shared helpers: JSON value types, deep equality, safe object construction
15
+ * (prototype-pollution guarded) and type classification.
16
+ */
17
+ type JsonPrimitive = string | number | boolean | null;
18
+ type JsonValue = JsonPrimitive | JsonValue[] | {
19
+ [key: string]: JsonValue;
20
+ };
21
+ type JsonObject = {
22
+ [key: string]: JsonValue;
23
+ };
24
+ /** True for a non-null, non-array object. */
25
+ declare function isPlainObject(v: unknown): v is Record<string, unknown>;
26
+ /** jq-style type name for a JSON value. */
27
+ declare function typeOf(v: unknown): "null" | "boolean" | "number" | "string" | "array" | "object";
28
+ /** Structural deep equality for JSON values. */
29
+ declare function deepEqual(a: unknown, b: unknown): boolean;
30
+ /** Deep clone of a JSON value (safe against prototype pollution). */
31
+ declare function deepClone<T>(v: T): T;
32
+ /**
33
+ * A stable ordering for JSON values, used by `sort_by`, `unique`, `min`/`max`.
34
+ * Ordering mirrors jq: null < false < true < numbers < strings < arrays < objects.
35
+ */
36
+ declare function compareValues(a: unknown, b: unknown): number;
37
+ /** Recursively sort object keys (used by `--sort-keys`). */
38
+ declare function sortKeysDeep(v: unknown): unknown;
39
+ /** A rendering-safe error carrying an optional path for CLI display. */
40
+ declare class JsonToolError extends Error {
41
+ path?: string;
42
+ constructor(message: string, path?: string);
43
+ }
44
+
45
+ type Format = "json" | "yaml" | "toml" | "csv" | "ndjson";
46
+ /** Guess a format from a filename extension, else undefined. */
47
+ declare function formatFromExt(filename: string): Format | undefined;
48
+ /** Best-effort format detection from the content itself. */
49
+ declare function detectFormat(src: string): Format;
50
+ /** Parse `src` in the given format into a JSON value. */
51
+ declare function parseFormat(src: string, format: Format): JsonValue;
52
+ /** Serialize a JSON value into the given format. */
53
+ declare function stringifyFormat(value: JsonValue, format: Format, opts?: {
54
+ indent?: number;
55
+ sortKeys?: boolean;
56
+ minify?: boolean;
57
+ }): string;
58
+ /** Convert text from one format to another. */
59
+ declare function convert(src: string, from: Format, to: Format, opts?: {
60
+ indent?: number;
61
+ minify?: boolean;
62
+ }): string;
63
+ /**
64
+ * Recursively rebuild a parsed JSON value dropping prototype-pollution keys.
65
+ * `JSON.parse` itself is safe, but downstream merges/writes should never carry a
66
+ * literal `__proto__` own key, so we strip them at the boundary.
67
+ */
68
+ declare function sanitizeJson(v: unknown): JsonValue;
69
+
70
+ /** Parse a YAML document into a JSON value. */
71
+ declare function parseYaml(src: string): JsonValue;
72
+ /** Serialize a JSON value to YAML. */
73
+ declare function stringifyYaml(value: JsonValue): string;
74
+
75
+ /** Parse a TOML document into a JSON value (object). */
76
+ declare function parseToml(src: string): JsonValue;
77
+ /** Serialize a JSON object to TOML. Throws if the top level is not an object. */
78
+ declare function stringifyToml(value: JsonValue): string;
79
+
80
+ interface CsvParseOptions {
81
+ delimiter?: string;
82
+ parseTypes?: boolean;
83
+ }
84
+ /** Parse CSV text into an array of objects (or arrays if no header wanted). */
85
+ declare function parseCsv(src: string, opts?: CsvParseOptions): JsonValue;
86
+ interface CsvStringifyOptions {
87
+ delimiter?: string;
88
+ columns?: string[];
89
+ }
90
+ /** Serialize an array of flat objects to CSV. */
91
+ declare function stringifyCsv(value: JsonValue, opts?: CsvStringifyOptions): string;
92
+ /** Parse NDJSON (one JSON value per line) into an array. */
93
+ declare function parseNdjson(src: string): JsonValue;
94
+ /** Serialize an array to NDJSON (one compact JSON value per line). */
95
+ declare function stringifyNdjson(value: JsonValue): string;
96
+
97
+ interface ValidationError {
98
+ path: string;
99
+ message: string;
100
+ }
101
+ interface ValidationResult {
102
+ valid: boolean;
103
+ errors: ValidationError[];
104
+ }
105
+ /** Validate `data` against a JSON Schema. Returns `{ valid, errors[] }`. */
106
+ declare function validateSchema(data: JsonValue, schema: JsonValue): ValidationResult;
107
+
108
+ type DiffKind = "added" | "removed" | "changed";
109
+ interface DiffEntry {
110
+ kind: DiffKind;
111
+ path: string;
112
+ before?: JsonValue;
113
+ after?: JsonValue;
114
+ }
115
+ /** Compute a flat list of differences turning `a` into `b`. */
116
+ declare function diff(a: JsonValue, b: JsonValue): DiffEntry[];
117
+ /** True if the two values are structurally identical. */
118
+ declare function isEqual(a: JsonValue, b: JsonValue): boolean;
119
+
120
+ type ArrayStrategy = {
121
+ mode: "concat";
122
+ } | {
123
+ mode: "replace";
124
+ } | {
125
+ mode: "by-key";
126
+ key: string;
127
+ };
128
+ interface MergeOptions {
129
+ array?: ArrayStrategy;
130
+ }
131
+ /** Deep-merge two or more JSON values left-to-right. */
132
+ declare function merge(values: JsonValue[], opts?: MergeOptions): JsonValue;
133
+ /** Parse a CLI `--array` flag into a strategy. */
134
+ declare function parseArrayStrategy(spec: string | undefined, byKey?: string): ArrayStrategy;
135
+
136
+ interface FormatOptions {
137
+ indent?: number;
138
+ sortKeys?: boolean;
139
+ minify?: boolean;
140
+ }
141
+ /** Pretty-print (or minify) a JSON value. */
142
+ declare function formatJson(value: JsonValue, opts?: FormatOptions): string;
143
+ /**
144
+ * Resolve a dotted / bracketed path (`.a.b[0].c`, `a.b`, `users[2].name`) to a
145
+ * single value. Returns `undefined` if any segment is missing.
146
+ */
147
+ declare function getPath(data: JsonValue, path: string): JsonValue | undefined;
148
+ /** Tokenize a path string into key/index segments. */
149
+ declare function parsePath(path: string): Array<string | number>;
150
+
151
+ export { type ArrayStrategy, type CsvParseOptions, type CsvStringifyOptions, type DiffEntry, type DiffKind, type Format, type FormatOptions, type JsonObject, type JsonPrimitive, JsonToolError, type JsonValue, type MergeOptions, type ValidationError, type ValidationResult, compareValues, compileQuery, convert, deepClone, deepEqual, detectFormat, diff, formatFromExt, formatJson, getPath, isEqual, isPlainObject, isValidQuery, merge, parseArrayStrategy, parseCsv, parseFormat, parseNdjson, parsePath, parseToml, parseYaml, query, queryAll, sanitizeJson, sortKeysDeep, stringifyCsv, stringifyFormat, stringifyNdjson, stringifyToml, stringifyYaml, typeOf, validateSchema };