modelfusion 0.47.0 → 0.47.1

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.
@@ -1,186 +1,188 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const node_assert_1 = __importDefault(require("node:assert"));
3
7
  const vitest_1 = require("vitest");
4
- const fixJson_1 = require("./fixJson");
5
- (0, vitest_1.describe)("fixJson", () => {
6
- (0, vitest_1.test)("should handle empty input", () => {
7
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("")).toBe("");
8
- });
9
- (0, vitest_1.describe)("literals", () => {
10
- (0, vitest_1.test)("should handle incomplete null", () => {
11
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("nul")).toBe("null");
12
- });
13
- (0, vitest_1.test)("should handle incomplete true", () => {
14
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("t")).toBe("true");
15
- });
16
- (0, vitest_1.test)("should handle incomplete false", () => {
17
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("fals")).toBe("false");
18
- });
19
- });
20
- (0, vitest_1.describe)("number", () => {
21
- (0, vitest_1.test)("should handle incomplete numbers", () => {
22
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("12.")).toBe("12");
23
- });
24
- (0, vitest_1.test)("should handle numbers with dot", () => {
25
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("12.2")).toBe("12.2");
26
- });
27
- (0, vitest_1.test)("should handle negative numbers", () => {
28
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("-12")).toBe("-12");
29
- });
30
- (0, vitest_1.test)("should handle incomplete negative numbers", () => {
31
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("-")).toBe("");
32
- });
33
- (0, vitest_1.test)("should handle e-notation numbers", () => {
34
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("2.5e")).toBe("2.5");
35
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("2.5e-")).toBe("2.5");
36
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("2.5e3")).toBe("2.5e3");
37
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("-2.5e3")).toBe("-2.5e3");
38
- });
39
- (0, vitest_1.test)("should handle uppercase e-notation numbers", () => {
40
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("2.5E")).toBe("2.5");
41
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("2.5E-")).toBe("2.5");
42
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("2.5E3")).toBe("2.5E3");
43
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("-2.5E3")).toBe("-2.5E3");
44
- });
45
- (0, vitest_1.test)("should handle incomplete numbers", () => {
46
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("12.e")).toBe("12");
47
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("12.34e")).toBe("12.34");
48
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("5e")).toBe("5");
49
- });
50
- });
51
- (0, vitest_1.describe)("string", () => {
52
- (0, vitest_1.test)("should handle incomplete strings", () => {
53
- (0, vitest_1.expect)((0, fixJson_1.fixJson)('"abc')).toBe('"abc"');
54
- });
55
- (0, vitest_1.test)("should handle escape sequences", () => {
56
- (0, vitest_1.expect)((0, fixJson_1.fixJson)('"value with \\"quoted\\" text and \\\\ escape')).toBe('"value with \\"quoted\\" text and \\\\ escape"');
57
- });
58
- (0, vitest_1.test)("should handle incomplete escape sequences", () => {
59
- (0, vitest_1.expect)((0, fixJson_1.fixJson)('"value with \\')).toBe('"value with "');
60
- });
61
- (0, vitest_1.test)("should handle unicode characters", () => {
62
- (0, vitest_1.expect)((0, fixJson_1.fixJson)('"value with unicode \u003C"')).toBe('"value with unicode \u003C"');
63
- });
64
- });
65
- (0, vitest_1.describe)("array", () => {
66
- (0, vitest_1.test)("should handle incomplete array", () => {
67
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("[")).toBe("[]");
68
- });
69
- (0, vitest_1.test)("should handle closing bracket after number in array", () => {
70
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("[[1], [2")).toBe("[[1], [2]]");
71
- });
72
- (0, vitest_1.test)("should handle closing bracket after string in array", () => {
73
- (0, vitest_1.expect)((0, fixJson_1.fixJson)(`[["1"], ["2`)).toBe(`[["1"], ["2"]]`);
74
- });
75
- (0, vitest_1.test)("should handle closing bracket after literal in array", () => {
76
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("[[false], [nu")).toBe("[[false], [null]]");
77
- });
78
- (0, vitest_1.test)("should handle closing bracket after array in array", () => {
79
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("[[[]], [[]")).toBe("[[[]], [[]]]");
80
- });
81
- (0, vitest_1.test)("should handle closing bracket after object in array", () => {
82
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("[[{}], [{")).toBe("[[{}], [{}]]");
83
- });
84
- (0, vitest_1.test)("should handle trailing comma", () => {
85
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("[1, ")).toBe("[1]");
86
- });
87
- (0, vitest_1.test)("should handle closing array", () => {
88
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("[[], 123")).toBe("[[], 123]");
89
- });
90
- });
91
- (0, vitest_1.describe)("object", () => {
92
- (0, vitest_1.test)("should handle keys without values", () => {
93
- (0, vitest_1.expect)((0, fixJson_1.fixJson)('{"key":')).toBe("{}");
94
- });
95
- (0, vitest_1.test)("should handle closing brace after number in object", () => {
96
- (0, vitest_1.expect)((0, fixJson_1.fixJson)('{"a": {"b": 1}, "c": {"d": 2')).toBe('{"a": {"b": 1}, "c": {"d": 2}}');
97
- });
98
- (0, vitest_1.test)("should handle closing brace after string in object", () => {
99
- (0, vitest_1.expect)((0, fixJson_1.fixJson)('{"a": {"b": "1"}, "c": {"d": 2')).toBe('{"a": {"b": "1"}, "c": {"d": 2}}');
100
- });
101
- (0, vitest_1.test)("should handle closing brace after literal in object", () => {
102
- (0, vitest_1.expect)((0, fixJson_1.fixJson)('{"a": {"b": false}, "c": {"d": 2')).toBe('{"a": {"b": false}, "c": {"d": 2}}');
103
- });
104
- (0, vitest_1.test)("should handle closing brace after array in object", () => {
105
- (0, vitest_1.expect)((0, fixJson_1.fixJson)('{"a": {"b": []}, "c": {"d": 2')).toBe('{"a": {"b": []}, "c": {"d": 2}}');
106
- });
107
- (0, vitest_1.test)("should handle closing brace after object in object", () => {
108
- (0, vitest_1.expect)((0, fixJson_1.fixJson)('{"a": {"b": {}}, "c": {"d": 2')).toBe('{"a": {"b": {}}, "c": {"d": 2}}');
109
- });
110
- (0, vitest_1.test)("should handle partial keys (first key)", () => {
111
- (0, vitest_1.expect)((0, fixJson_1.fixJson)('{"ke')).toBe("{}");
112
- });
113
- (0, vitest_1.test)("should handle partial keys (second key)", () => {
114
- (0, vitest_1.expect)((0, fixJson_1.fixJson)('{"k1": 1, "k2')).toBe('{"k1": 1}');
115
- });
116
- (0, vitest_1.test)("should handle partial keys with colon (second key)", () => {
117
- (0, vitest_1.expect)((0, fixJson_1.fixJson)('{"k1": 1, "k2":')).toBe('{"k1": 1}');
118
- });
119
- (0, vitest_1.test)("should handle trailing whitespaces", () => {
120
- (0, vitest_1.expect)((0, fixJson_1.fixJson)('{"key": "value" ')).toBe('{"key": "value"}');
121
- });
122
- });
123
- (0, vitest_1.describe)("nesting", () => {
124
- (0, vitest_1.test)("should handle nested arrays with numbers", () => {
125
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("[1, [2, 3, [")).toBe("[1, [2, 3, []]]");
126
- });
127
- (0, vitest_1.test)("should handle nested arrays with literals", () => {
128
- (0, vitest_1.expect)((0, fixJson_1.fixJson)("[false, [true, [")).toBe("[false, [true, []]]");
129
- });
130
- (0, vitest_1.test)("should handle nested objects", () => {
131
- (0, vitest_1.expect)((0, fixJson_1.fixJson)('{"key": {"subKey":')).toBe('{"key": {}}');
132
- });
133
- (0, vitest_1.test)("should handle nested objects with numbers", () => {
134
- (0, vitest_1.expect)((0, fixJson_1.fixJson)('{"key": 123, "key2": {"subKey":')).toBe('{"key": 123, "key2": {}}');
135
- });
136
- (0, vitest_1.test)("should handle nested objects with literals", () => {
137
- (0, vitest_1.expect)((0, fixJson_1.fixJson)('{"key": null, "key2": {"subKey":')).toBe('{"key": null, "key2": {}}');
138
- });
139
- (0, vitest_1.test)("should handle arrays within objects", () => {
140
- (0, vitest_1.expect)((0, fixJson_1.fixJson)('{"key": [1, 2, {')).toBe('{"key": [1, 2, {}]}');
141
- });
142
- (0, vitest_1.test)("should handle objects within arrays", () => {
143
- (0, vitest_1.expect)((0, fixJson_1.fixJson)('[1, 2, {"key": "value",')).toBe('[1, 2, {"key": "value"}]');
144
- });
145
- (0, vitest_1.test)("should handle nested arrays and objects", () => {
146
- (0, vitest_1.expect)((0, fixJson_1.fixJson)('{"a": {"b": ["c", {"d": "e",')).toBe('{"a": {"b": ["c", {"d": "e"}]}}');
147
- });
148
- (0, vitest_1.test)("should handle deeply nested structures", () => {
149
- (0, vitest_1.expect)((0, fixJson_1.fixJson)('{"a": {"b": {"c": {"d":')).toBe('{"a": {"b": {"c": {}}}}');
150
- });
151
- (0, vitest_1.test)("should handle potential nested arrays or objects", () => {
152
- (0, vitest_1.expect)((0, fixJson_1.fixJson)('{"a": 1, "b": [')).toBe('{"a": 1, "b": []}');
153
- (0, vitest_1.expect)((0, fixJson_1.fixJson)('{"a": 1, "b": {')).toBe('{"a": 1, "b": {}}');
154
- (0, vitest_1.expect)((0, fixJson_1.fixJson)('{"a": 1, "b": "')).toBe('{"a": 1, "b": ""}');
155
- });
156
- });
157
- (0, vitest_1.describe)("regression", () => {
158
- (0, vitest_1.test)("should handle complex nesting 1", () => {
159
- (0, vitest_1.expect)((0, fixJson_1.fixJson)([
160
- "{",
161
- ' "a": [',
162
- " {",
163
- ' "a1": "v1",',
164
- ' "a2": "v2",',
165
- ` "a3": "v3"`,
166
- " }",
167
- " ],",
168
- ' "b": [',
169
- " {",
170
- ' "b1": "n',
171
- ].join("\n"))).toBe([
172
- "{",
173
- ' "a": [',
174
- " {",
175
- ' "a1": "v1",',
176
- ' "a2": "v2",',
177
- ` "a3": "v3"`,
178
- " }",
179
- " ],",
180
- ' "b": [',
181
- " {",
182
- ' "b1": "n"}]}',
183
- ].join("\n"));
184
- });
8
+ const fixJson_js_1 = require("./fixJson.cjs");
9
+ (0, vitest_1.test)("should handle empty input", () => {
10
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)(""), "");
11
+ });
12
+ (0, vitest_1.describe)("literals", () => {
13
+ (0, vitest_1.test)("should handle incomplete null", () => {
14
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)("nul"), "null");
15
+ });
16
+ (0, vitest_1.test)("should handle incomplete true", () => {
17
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)("t"), "true");
18
+ });
19
+ (0, vitest_1.test)("should handle incomplete false", () => {
20
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)("fals"), "false");
21
+ });
22
+ });
23
+ (0, vitest_1.describe)("number", () => {
24
+ (0, vitest_1.test)("should handle incomplete numbers", () => {
25
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)("12."), "12");
26
+ });
27
+ (0, vitest_1.test)("should handle numbers with dot", () => {
28
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)("12.2"), "12.2");
29
+ });
30
+ (0, vitest_1.test)("should handle negative numbers", () => {
31
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)("-12"), "-12");
32
+ });
33
+ (0, vitest_1.test)("should handle incomplete negative numbers", () => {
34
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)("-"), "");
35
+ });
36
+ (0, vitest_1.test)("should handle e-notation numbers", () => {
37
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)("2.5e"), "2.5");
38
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)("2.5e-"), "2.5");
39
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)("2.5e3"), "2.5e3");
40
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)("-2.5e3"), "-2.5e3");
41
+ });
42
+ (0, vitest_1.test)("should handle uppercase e-notation numbers", () => {
43
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)("2.5E"), "2.5");
44
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)("2.5E-"), "2.5");
45
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)("2.5E3"), "2.5E3");
46
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)("-2.5E3"), "-2.5E3");
47
+ });
48
+ (0, vitest_1.test)("should handle incomplete numbers", () => {
49
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)("12.e"), "12");
50
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)("12.34e"), "12.34");
51
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)("5e"), "5");
52
+ });
53
+ });
54
+ (0, vitest_1.describe)("string", () => {
55
+ (0, vitest_1.test)("should handle incomplete strings", () => {
56
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)('"abc'), '"abc"');
57
+ });
58
+ (0, vitest_1.test)("should handle escape sequences", () => {
59
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)('"value with \\"quoted\\" text and \\\\ escape'), '"value with \\"quoted\\" text and \\\\ escape"');
60
+ });
61
+ (0, vitest_1.test)("should handle incomplete escape sequences", () => {
62
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)('"value with \\'), '"value with "');
63
+ });
64
+ (0, vitest_1.test)("should handle unicode characters", () => {
65
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)('"value with unicode \u003C"'), '"value with unicode \u003C"');
66
+ });
67
+ });
68
+ (0, vitest_1.describe)("array", () => {
69
+ (0, vitest_1.test)("should handle incomplete array", () => {
70
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)("["), "[]");
71
+ });
72
+ (0, vitest_1.test)("should handle closing bracket after number in array", () => {
73
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)("[[1], [2"), "[[1], [2]]");
74
+ });
75
+ (0, vitest_1.test)("should handle closing bracket after string in array", () => {
76
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)(`[["1"], ["2`), `[["1"], ["2"]]`);
77
+ });
78
+ (0, vitest_1.test)("should handle closing bracket after literal in array", () => {
79
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)("[[false], [nu"), "[[false], [null]]");
80
+ });
81
+ (0, vitest_1.test)("should handle closing bracket after array in array", () => {
82
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)("[[[]], [[]"), "[[[]], [[]]]");
83
+ });
84
+ (0, vitest_1.test)("should handle closing bracket after object in array", () => {
85
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)("[[{}], [{"), "[[{}], [{}]]");
86
+ });
87
+ (0, vitest_1.test)("should handle trailing comma", () => {
88
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)("[1, "), "[1]");
89
+ });
90
+ (0, vitest_1.test)("should handle closing array", () => {
91
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)("[[], 123"), "[[], 123]");
92
+ });
93
+ });
94
+ (0, vitest_1.describe)("object", () => {
95
+ (0, vitest_1.test)("should handle keys without values", () => {
96
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)('{"key":'), "{}");
97
+ });
98
+ (0, vitest_1.test)("should handle closing brace after number in object", () => {
99
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)('{"a": {"b": 1}, "c": {"d": 2'), '{"a": {"b": 1}, "c": {"d": 2}}');
100
+ });
101
+ (0, vitest_1.test)("should handle closing brace after string in object", () => {
102
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)('{"a": {"b": "1"}, "c": {"d": 2'), '{"a": {"b": "1"}, "c": {"d": 2}}');
103
+ });
104
+ (0, vitest_1.test)("should handle closing brace after literal in object", () => {
105
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)('{"a": {"b": false}, "c": {"d": 2'), '{"a": {"b": false}, "c": {"d": 2}}');
106
+ });
107
+ (0, vitest_1.test)("should handle closing brace after array in object", () => {
108
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)('{"a": {"b": []}, "c": {"d": 2'), '{"a": {"b": []}, "c": {"d": 2}}');
109
+ });
110
+ (0, vitest_1.test)("should handle closing brace after object in object", () => {
111
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)('{"a": {"b": {}}, "c": {"d": 2'), '{"a": {"b": {}}, "c": {"d": 2}}');
112
+ });
113
+ (0, vitest_1.test)("should handle partial keys (first key)", () => {
114
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)('{"ke'), "{}");
115
+ });
116
+ (0, vitest_1.test)("should handle partial keys (second key)", () => {
117
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)('{"k1": 1, "k2'), '{"k1": 1}');
118
+ });
119
+ (0, vitest_1.test)("should handle partial keys with colon (second key)", () => {
120
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)('{"k1": 1, "k2":'), '{"k1": 1}');
121
+ });
122
+ (0, vitest_1.test)("should handle trailing whitespaces", () => {
123
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)('{"key": "value" '), '{"key": "value"}');
124
+ });
125
+ });
126
+ (0, vitest_1.describe)("nesting", () => {
127
+ (0, vitest_1.test)("should handle nested arrays with numbers", () => {
128
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)("[1, [2, 3, ["), "[1, [2, 3, []]]");
129
+ });
130
+ (0, vitest_1.test)("should handle nested arrays with literals", () => {
131
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)("[false, [true, ["), "[false, [true, []]]");
132
+ });
133
+ (0, vitest_1.test)("should handle nested objects", () => {
134
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)('{"key": {"subKey":'), '{"key": {}}');
135
+ });
136
+ (0, vitest_1.test)("should handle nested objects with numbers", () => {
137
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)('{"key": 123, "key2": {"subKey":'), '{"key": 123, "key2": {}}');
138
+ });
139
+ (0, vitest_1.test)("should handle nested objects with literals", () => {
140
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)('{"key": null, "key2": {"subKey":'), '{"key": null, "key2": {}}');
141
+ });
142
+ (0, vitest_1.test)("should handle arrays within objects", () => {
143
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)('{"key": [1, 2, {'), '{"key": [1, 2, {}]}');
144
+ });
145
+ (0, vitest_1.test)("should handle objects within arrays", () => {
146
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)('[1, 2, {"key": "value",'), '[1, 2, {"key": "value"}]');
147
+ });
148
+ (0, vitest_1.test)("should handle nested arrays and objects", () => {
149
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)('{"a": {"b": ["c", {"d": "e",'), '{"a": {"b": ["c", {"d": "e"}]}}');
150
+ });
151
+ (0, vitest_1.test)("should handle deeply nested structures", () => {
152
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)('{"a": {"b": {"c": {"d":'), '{"a": {"b": {"c": {}}}}');
153
+ });
154
+ (0, vitest_1.test)("should handle potential nested arrays or objects", () => {
155
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)('{"a": 1, "b": ['), '{"a": 1, "b": []}');
156
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)('{"a": 1, "b": {'), '{"a": 1, "b": {}}');
157
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)('{"a": 1, "b": "'), '{"a": 1, "b": ""}');
158
+ });
159
+ });
160
+ (0, vitest_1.describe)("regression", () => {
161
+ (0, vitest_1.test)("should handle complex nesting 1", () => {
162
+ node_assert_1.default.strictEqual((0, fixJson_js_1.fixJson)([
163
+ "{",
164
+ ' "a": [',
165
+ " {",
166
+ ' "a1": "v1",',
167
+ ' "a2": "v2",',
168
+ ` "a3": "v3"`,
169
+ " }",
170
+ " ],",
171
+ ' "b": [',
172
+ " {",
173
+ ' "b1": "n',
174
+ ].join("\n")), [
175
+ "{",
176
+ ' "a": [',
177
+ " {",
178
+ ' "a1": "v1",',
179
+ ' "a2": "v2",',
180
+ ` "a3": "v3"`,
181
+ " }",
182
+ " ],",
183
+ ' "b": [',
184
+ " {",
185
+ ' "b1": "n"}]}',
186
+ ].join("\n"));
185
187
  });
186
188
  });
@@ -1,184 +1,183 @@
1
- import { expect, test, describe } from "vitest";
2
- import { fixJson } from "./fixJson";
3
- describe("fixJson", () => {
4
- test("should handle empty input", () => {
5
- expect(fixJson("")).toBe("");
6
- });
7
- describe("literals", () => {
8
- test("should handle incomplete null", () => {
9
- expect(fixJson("nul")).toBe("null");
10
- });
11
- test("should handle incomplete true", () => {
12
- expect(fixJson("t")).toBe("true");
13
- });
14
- test("should handle incomplete false", () => {
15
- expect(fixJson("fals")).toBe("false");
16
- });
17
- });
18
- describe("number", () => {
19
- test("should handle incomplete numbers", () => {
20
- expect(fixJson("12.")).toBe("12");
21
- });
22
- test("should handle numbers with dot", () => {
23
- expect(fixJson("12.2")).toBe("12.2");
24
- });
25
- test("should handle negative numbers", () => {
26
- expect(fixJson("-12")).toBe("-12");
27
- });
28
- test("should handle incomplete negative numbers", () => {
29
- expect(fixJson("-")).toBe("");
30
- });
31
- test("should handle e-notation numbers", () => {
32
- expect(fixJson("2.5e")).toBe("2.5");
33
- expect(fixJson("2.5e-")).toBe("2.5");
34
- expect(fixJson("2.5e3")).toBe("2.5e3");
35
- expect(fixJson("-2.5e3")).toBe("-2.5e3");
36
- });
37
- test("should handle uppercase e-notation numbers", () => {
38
- expect(fixJson("2.5E")).toBe("2.5");
39
- expect(fixJson("2.5E-")).toBe("2.5");
40
- expect(fixJson("2.5E3")).toBe("2.5E3");
41
- expect(fixJson("-2.5E3")).toBe("-2.5E3");
42
- });
43
- test("should handle incomplete numbers", () => {
44
- expect(fixJson("12.e")).toBe("12");
45
- expect(fixJson("12.34e")).toBe("12.34");
46
- expect(fixJson("5e")).toBe("5");
47
- });
48
- });
49
- describe("string", () => {
50
- test("should handle incomplete strings", () => {
51
- expect(fixJson('"abc')).toBe('"abc"');
52
- });
53
- test("should handle escape sequences", () => {
54
- expect(fixJson('"value with \\"quoted\\" text and \\\\ escape')).toBe('"value with \\"quoted\\" text and \\\\ escape"');
55
- });
56
- test("should handle incomplete escape sequences", () => {
57
- expect(fixJson('"value with \\')).toBe('"value with "');
58
- });
59
- test("should handle unicode characters", () => {
60
- expect(fixJson('"value with unicode \u003C"')).toBe('"value with unicode \u003C"');
61
- });
62
- });
63
- describe("array", () => {
64
- test("should handle incomplete array", () => {
65
- expect(fixJson("[")).toBe("[]");
66
- });
67
- test("should handle closing bracket after number in array", () => {
68
- expect(fixJson("[[1], [2")).toBe("[[1], [2]]");
69
- });
70
- test("should handle closing bracket after string in array", () => {
71
- expect(fixJson(`[["1"], ["2`)).toBe(`[["1"], ["2"]]`);
72
- });
73
- test("should handle closing bracket after literal in array", () => {
74
- expect(fixJson("[[false], [nu")).toBe("[[false], [null]]");
75
- });
76
- test("should handle closing bracket after array in array", () => {
77
- expect(fixJson("[[[]], [[]")).toBe("[[[]], [[]]]");
78
- });
79
- test("should handle closing bracket after object in array", () => {
80
- expect(fixJson("[[{}], [{")).toBe("[[{}], [{}]]");
81
- });
82
- test("should handle trailing comma", () => {
83
- expect(fixJson("[1, ")).toBe("[1]");
84
- });
85
- test("should handle closing array", () => {
86
- expect(fixJson("[[], 123")).toBe("[[], 123]");
87
- });
88
- });
89
- describe("object", () => {
90
- test("should handle keys without values", () => {
91
- expect(fixJson('{"key":')).toBe("{}");
92
- });
93
- test("should handle closing brace after number in object", () => {
94
- expect(fixJson('{"a": {"b": 1}, "c": {"d": 2')).toBe('{"a": {"b": 1}, "c": {"d": 2}}');
95
- });
96
- test("should handle closing brace after string in object", () => {
97
- expect(fixJson('{"a": {"b": "1"}, "c": {"d": 2')).toBe('{"a": {"b": "1"}, "c": {"d": 2}}');
98
- });
99
- test("should handle closing brace after literal in object", () => {
100
- expect(fixJson('{"a": {"b": false}, "c": {"d": 2')).toBe('{"a": {"b": false}, "c": {"d": 2}}');
101
- });
102
- test("should handle closing brace after array in object", () => {
103
- expect(fixJson('{"a": {"b": []}, "c": {"d": 2')).toBe('{"a": {"b": []}, "c": {"d": 2}}');
104
- });
105
- test("should handle closing brace after object in object", () => {
106
- expect(fixJson('{"a": {"b": {}}, "c": {"d": 2')).toBe('{"a": {"b": {}}, "c": {"d": 2}}');
107
- });
108
- test("should handle partial keys (first key)", () => {
109
- expect(fixJson('{"ke')).toBe("{}");
110
- });
111
- test("should handle partial keys (second key)", () => {
112
- expect(fixJson('{"k1": 1, "k2')).toBe('{"k1": 1}');
113
- });
114
- test("should handle partial keys with colon (second key)", () => {
115
- expect(fixJson('{"k1": 1, "k2":')).toBe('{"k1": 1}');
116
- });
117
- test("should handle trailing whitespaces", () => {
118
- expect(fixJson('{"key": "value" ')).toBe('{"key": "value"}');
119
- });
120
- });
121
- describe("nesting", () => {
122
- test("should handle nested arrays with numbers", () => {
123
- expect(fixJson("[1, [2, 3, [")).toBe("[1, [2, 3, []]]");
124
- });
125
- test("should handle nested arrays with literals", () => {
126
- expect(fixJson("[false, [true, [")).toBe("[false, [true, []]]");
127
- });
128
- test("should handle nested objects", () => {
129
- expect(fixJson('{"key": {"subKey":')).toBe('{"key": {}}');
130
- });
131
- test("should handle nested objects with numbers", () => {
132
- expect(fixJson('{"key": 123, "key2": {"subKey":')).toBe('{"key": 123, "key2": {}}');
133
- });
134
- test("should handle nested objects with literals", () => {
135
- expect(fixJson('{"key": null, "key2": {"subKey":')).toBe('{"key": null, "key2": {}}');
136
- });
137
- test("should handle arrays within objects", () => {
138
- expect(fixJson('{"key": [1, 2, {')).toBe('{"key": [1, 2, {}]}');
139
- });
140
- test("should handle objects within arrays", () => {
141
- expect(fixJson('[1, 2, {"key": "value",')).toBe('[1, 2, {"key": "value"}]');
142
- });
143
- test("should handle nested arrays and objects", () => {
144
- expect(fixJson('{"a": {"b": ["c", {"d": "e",')).toBe('{"a": {"b": ["c", {"d": "e"}]}}');
145
- });
146
- test("should handle deeply nested structures", () => {
147
- expect(fixJson('{"a": {"b": {"c": {"d":')).toBe('{"a": {"b": {"c": {}}}}');
148
- });
149
- test("should handle potential nested arrays or objects", () => {
150
- expect(fixJson('{"a": 1, "b": [')).toBe('{"a": 1, "b": []}');
151
- expect(fixJson('{"a": 1, "b": {')).toBe('{"a": 1, "b": {}}');
152
- expect(fixJson('{"a": 1, "b": "')).toBe('{"a": 1, "b": ""}');
153
- });
154
- });
155
- describe("regression", () => {
156
- test("should handle complex nesting 1", () => {
157
- expect(fixJson([
158
- "{",
159
- ' "a": [',
160
- " {",
161
- ' "a1": "v1",',
162
- ' "a2": "v2",',
163
- ` "a3": "v3"`,
164
- " }",
165
- " ],",
166
- ' "b": [',
167
- " {",
168
- ' "b1": "n',
169
- ].join("\n"))).toBe([
170
- "{",
171
- ' "a": [',
172
- " {",
173
- ' "a1": "v1",',
174
- ' "a2": "v2",',
175
- ` "a3": "v3"`,
176
- " }",
177
- " ],",
178
- ' "b": [',
179
- " {",
180
- ' "b1": "n"}]}',
181
- ].join("\n"));
182
- });
1
+ import assert from "node:assert";
2
+ import { test, describe } from "vitest";
3
+ import { fixJson } from "./fixJson.js";
4
+ test("should handle empty input", () => {
5
+ assert.strictEqual(fixJson(""), "");
6
+ });
7
+ describe("literals", () => {
8
+ test("should handle incomplete null", () => {
9
+ assert.strictEqual(fixJson("nul"), "null");
10
+ });
11
+ test("should handle incomplete true", () => {
12
+ assert.strictEqual(fixJson("t"), "true");
13
+ });
14
+ test("should handle incomplete false", () => {
15
+ assert.strictEqual(fixJson("fals"), "false");
16
+ });
17
+ });
18
+ describe("number", () => {
19
+ test("should handle incomplete numbers", () => {
20
+ assert.strictEqual(fixJson("12."), "12");
21
+ });
22
+ test("should handle numbers with dot", () => {
23
+ assert.strictEqual(fixJson("12.2"), "12.2");
24
+ });
25
+ test("should handle negative numbers", () => {
26
+ assert.strictEqual(fixJson("-12"), "-12");
27
+ });
28
+ test("should handle incomplete negative numbers", () => {
29
+ assert.strictEqual(fixJson("-"), "");
30
+ });
31
+ test("should handle e-notation numbers", () => {
32
+ assert.strictEqual(fixJson("2.5e"), "2.5");
33
+ assert.strictEqual(fixJson("2.5e-"), "2.5");
34
+ assert.strictEqual(fixJson("2.5e3"), "2.5e3");
35
+ assert.strictEqual(fixJson("-2.5e3"), "-2.5e3");
36
+ });
37
+ test("should handle uppercase e-notation numbers", () => {
38
+ assert.strictEqual(fixJson("2.5E"), "2.5");
39
+ assert.strictEqual(fixJson("2.5E-"), "2.5");
40
+ assert.strictEqual(fixJson("2.5E3"), "2.5E3");
41
+ assert.strictEqual(fixJson("-2.5E3"), "-2.5E3");
42
+ });
43
+ test("should handle incomplete numbers", () => {
44
+ assert.strictEqual(fixJson("12.e"), "12");
45
+ assert.strictEqual(fixJson("12.34e"), "12.34");
46
+ assert.strictEqual(fixJson("5e"), "5");
47
+ });
48
+ });
49
+ describe("string", () => {
50
+ test("should handle incomplete strings", () => {
51
+ assert.strictEqual(fixJson('"abc'), '"abc"');
52
+ });
53
+ test("should handle escape sequences", () => {
54
+ assert.strictEqual(fixJson('"value with \\"quoted\\" text and \\\\ escape'), '"value with \\"quoted\\" text and \\\\ escape"');
55
+ });
56
+ test("should handle incomplete escape sequences", () => {
57
+ assert.strictEqual(fixJson('"value with \\'), '"value with "');
58
+ });
59
+ test("should handle unicode characters", () => {
60
+ assert.strictEqual(fixJson('"value with unicode \u003C"'), '"value with unicode \u003C"');
61
+ });
62
+ });
63
+ describe("array", () => {
64
+ test("should handle incomplete array", () => {
65
+ assert.strictEqual(fixJson("["), "[]");
66
+ });
67
+ test("should handle closing bracket after number in array", () => {
68
+ assert.strictEqual(fixJson("[[1], [2"), "[[1], [2]]");
69
+ });
70
+ test("should handle closing bracket after string in array", () => {
71
+ assert.strictEqual(fixJson(`[["1"], ["2`), `[["1"], ["2"]]`);
72
+ });
73
+ test("should handle closing bracket after literal in array", () => {
74
+ assert.strictEqual(fixJson("[[false], [nu"), "[[false], [null]]");
75
+ });
76
+ test("should handle closing bracket after array in array", () => {
77
+ assert.strictEqual(fixJson("[[[]], [[]"), "[[[]], [[]]]");
78
+ });
79
+ test("should handle closing bracket after object in array", () => {
80
+ assert.strictEqual(fixJson("[[{}], [{"), "[[{}], [{}]]");
81
+ });
82
+ test("should handle trailing comma", () => {
83
+ assert.strictEqual(fixJson("[1, "), "[1]");
84
+ });
85
+ test("should handle closing array", () => {
86
+ assert.strictEqual(fixJson("[[], 123"), "[[], 123]");
87
+ });
88
+ });
89
+ describe("object", () => {
90
+ test("should handle keys without values", () => {
91
+ assert.strictEqual(fixJson('{"key":'), "{}");
92
+ });
93
+ test("should handle closing brace after number in object", () => {
94
+ assert.strictEqual(fixJson('{"a": {"b": 1}, "c": {"d": 2'), '{"a": {"b": 1}, "c": {"d": 2}}');
95
+ });
96
+ test("should handle closing brace after string in object", () => {
97
+ assert.strictEqual(fixJson('{"a": {"b": "1"}, "c": {"d": 2'), '{"a": {"b": "1"}, "c": {"d": 2}}');
98
+ });
99
+ test("should handle closing brace after literal in object", () => {
100
+ assert.strictEqual(fixJson('{"a": {"b": false}, "c": {"d": 2'), '{"a": {"b": false}, "c": {"d": 2}}');
101
+ });
102
+ test("should handle closing brace after array in object", () => {
103
+ assert.strictEqual(fixJson('{"a": {"b": []}, "c": {"d": 2'), '{"a": {"b": []}, "c": {"d": 2}}');
104
+ });
105
+ test("should handle closing brace after object in object", () => {
106
+ assert.strictEqual(fixJson('{"a": {"b": {}}, "c": {"d": 2'), '{"a": {"b": {}}, "c": {"d": 2}}');
107
+ });
108
+ test("should handle partial keys (first key)", () => {
109
+ assert.strictEqual(fixJson('{"ke'), "{}");
110
+ });
111
+ test("should handle partial keys (second key)", () => {
112
+ assert.strictEqual(fixJson('{"k1": 1, "k2'), '{"k1": 1}');
113
+ });
114
+ test("should handle partial keys with colon (second key)", () => {
115
+ assert.strictEqual(fixJson('{"k1": 1, "k2":'), '{"k1": 1}');
116
+ });
117
+ test("should handle trailing whitespaces", () => {
118
+ assert.strictEqual(fixJson('{"key": "value" '), '{"key": "value"}');
119
+ });
120
+ });
121
+ describe("nesting", () => {
122
+ test("should handle nested arrays with numbers", () => {
123
+ assert.strictEqual(fixJson("[1, [2, 3, ["), "[1, [2, 3, []]]");
124
+ });
125
+ test("should handle nested arrays with literals", () => {
126
+ assert.strictEqual(fixJson("[false, [true, ["), "[false, [true, []]]");
127
+ });
128
+ test("should handle nested objects", () => {
129
+ assert.strictEqual(fixJson('{"key": {"subKey":'), '{"key": {}}');
130
+ });
131
+ test("should handle nested objects with numbers", () => {
132
+ assert.strictEqual(fixJson('{"key": 123, "key2": {"subKey":'), '{"key": 123, "key2": {}}');
133
+ });
134
+ test("should handle nested objects with literals", () => {
135
+ assert.strictEqual(fixJson('{"key": null, "key2": {"subKey":'), '{"key": null, "key2": {}}');
136
+ });
137
+ test("should handle arrays within objects", () => {
138
+ assert.strictEqual(fixJson('{"key": [1, 2, {'), '{"key": [1, 2, {}]}');
139
+ });
140
+ test("should handle objects within arrays", () => {
141
+ assert.strictEqual(fixJson('[1, 2, {"key": "value",'), '[1, 2, {"key": "value"}]');
142
+ });
143
+ test("should handle nested arrays and objects", () => {
144
+ assert.strictEqual(fixJson('{"a": {"b": ["c", {"d": "e",'), '{"a": {"b": ["c", {"d": "e"}]}}');
145
+ });
146
+ test("should handle deeply nested structures", () => {
147
+ assert.strictEqual(fixJson('{"a": {"b": {"c": {"d":'), '{"a": {"b": {"c": {}}}}');
148
+ });
149
+ test("should handle potential nested arrays or objects", () => {
150
+ assert.strictEqual(fixJson('{"a": 1, "b": ['), '{"a": 1, "b": []}');
151
+ assert.strictEqual(fixJson('{"a": 1, "b": {'), '{"a": 1, "b": {}}');
152
+ assert.strictEqual(fixJson('{"a": 1, "b": "'), '{"a": 1, "b": ""}');
153
+ });
154
+ });
155
+ describe("regression", () => {
156
+ test("should handle complex nesting 1", () => {
157
+ assert.strictEqual(fixJson([
158
+ "{",
159
+ ' "a": [',
160
+ " {",
161
+ ' "a1": "v1",',
162
+ ' "a2": "v2",',
163
+ ` "a3": "v3"`,
164
+ " }",
165
+ " ],",
166
+ ' "b": [',
167
+ " {",
168
+ ' "b1": "n',
169
+ ].join("\n")), [
170
+ "{",
171
+ ' "a": [',
172
+ " {",
173
+ ' "a1": "v1",',
174
+ ' "a2": "v2",',
175
+ ` "a3": "v3"`,
176
+ " }",
177
+ " ],",
178
+ ' "b": [',
179
+ " {",
180
+ ' "b1": "n"}]}',
181
+ ].join("\n"));
183
182
  });
184
183
  });
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.streamStructure = void 0;
7
- const deep_equal_1 = __importDefault(require("deep-equal"));
8
4
  const nanoid_1 = require("nanoid");
9
5
  const FunctionEventSource_js_1 = require("../../core/FunctionEventSource.cjs");
10
6
  const GlobalFunctionLogging_js_1 = require("../../core/GlobalFunctionLogging.cjs");
@@ -13,6 +9,7 @@ const AbortError_js_1 = require("../../core/api/AbortError.cjs");
13
9
  const getFunctionCallLogger_js_1 = require("../../core/getFunctionCallLogger.cjs");
14
10
  const getRun_js_1 = require("../../core/getRun.cjs");
15
11
  const DurationMeasurement_js_1 = require("../../util/DurationMeasurement.cjs");
12
+ const isDeepEqualData_js_1 = require("../../util/isDeepEqualData.cjs");
16
13
  const runSafe_js_1 = require("../../util/runSafe.cjs");
17
14
  const AsyncIterableResultPromise_js_1 = require("../AsyncIterableResultPromise.cjs");
18
15
  function streamStructure(model, structureDefinition, prompt, options) {
@@ -91,9 +88,7 @@ async function doStreamStructure(model, structureDefinition, prompt, options) {
91
88
  const latestFullDelta = event.fullDelta;
92
89
  const latestStructure = event.valueDelta;
93
90
  // only send a new part into the stream when the partial structure has changed:
94
- if (!(0, deep_equal_1.default)(lastStructure, latestStructure, {
95
- strict: true,
96
- })) {
91
+ if (!(0, isDeepEqualData_js_1.isDeepEqualData)(lastStructure, latestStructure)) {
97
92
  lastFullDelta = latestFullDelta;
98
93
  lastStructure = latestStructure;
99
94
  yield {
@@ -1,4 +1,3 @@
1
- import deepEqual from "deep-equal";
2
1
  import { nanoid as createId } from "nanoid";
3
2
  import { FunctionEventSource } from "../../core/FunctionEventSource.js";
4
3
  import { getGlobalFunctionLogging } from "../../core/GlobalFunctionLogging.js";
@@ -7,6 +6,7 @@ import { AbortError } from "../../core/api/AbortError.js";
7
6
  import { getFunctionCallLogger } from "../../core/getFunctionCallLogger.js";
8
7
  import { getRun } from "../../core/getRun.js";
9
8
  import { startDurationMeasurement } from "../../util/DurationMeasurement.js";
9
+ import { isDeepEqualData } from "../../util/isDeepEqualData.js";
10
10
  import { runSafe } from "../../util/runSafe.js";
11
11
  import { AsyncIterableResultPromise } from "../AsyncIterableResultPromise.js";
12
12
  export function streamStructure(model, structureDefinition, prompt, options) {
@@ -84,9 +84,7 @@ async function doStreamStructure(model, structureDefinition, prompt, options) {
84
84
  const latestFullDelta = event.fullDelta;
85
85
  const latestStructure = event.valueDelta;
86
86
  // only send a new part into the stream when the partial structure has changed:
87
- if (!deepEqual(lastStructure, latestStructure, {
88
- strict: true,
89
- })) {
87
+ if (!isDeepEqualData(lastStructure, latestStructure)) {
90
88
  lastFullDelta = latestFullDelta;
91
89
  lastStructure = latestStructure;
92
90
  yield {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modelfusion",
3
3
  "description": "Build multimodal applications, chatbots, and agents with JavaScript and TypeScript.",
4
- "version": "0.47.0",
4
+ "version": "0.47.1",
5
5
  "author": "Lars Grammel",
6
6
  "license": "MIT",
7
7
  "keywords": [
@@ -47,12 +47,12 @@
47
47
  "build": "npm run build:esm && npm run build:cjs",
48
48
  "build:esm": "tsc --outDir dist/",
49
49
  "build:cjs": "tsc --outDir build/cjs/ -p tsconfig.cjs.json && node bin/prepare-cjs.js",
50
- "test": "vitest",
51
- "dist": "npm run clean && npm run lint && npm run build && npm run dist:copy-files",
50
+ "test": "vitest run src",
51
+ "test-interactive": "vitest run",
52
+ "dist": "npm run clean && npm run lint && npm run test && npm run build && npm run dist:copy-files",
52
53
  "dist:copy-files": "copyfiles package.json README.md LICENSE dist"
53
54
  },
54
55
  "dependencies": {
55
- "deep-equal": "2.2.2",
56
56
  "eventsource-parser": "1.1.1",
57
57
  "js-tiktoken": "1.0.7",
58
58
  "nanoid": "3.3.6",
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isDeepEqualData = void 0;
4
+ /* eslint-disable @typescript-eslint/no-explicit-any */
5
+ /**
6
+ * Performs a deep-equal comparison of two parsed JSON structures.
7
+ *
8
+ * @param {any} obj1 - The first object to compare.
9
+ * @param {any} obj2 - The second object to compare.
10
+ * @returns {boolean} - Returns true if the two objects are deeply equal, false otherwise.
11
+ */
12
+ function isDeepEqualData(obj1, obj2) {
13
+ // Check for strict equality first
14
+ if (obj1 === obj2)
15
+ return true;
16
+ // Check if either is null or undefined
17
+ if (obj1 == null || obj2 == null)
18
+ return false;
19
+ // Check if both are objects
20
+ if (typeof obj1 !== "object" && typeof obj2 !== "object")
21
+ return obj1 === obj2;
22
+ // If they are not strictly equal, they both need to be Objects
23
+ if (obj1.constructor !== obj2.constructor)
24
+ return false;
25
+ // Special handling for Date objects
26
+ if (obj1 instanceof Date && obj2 instanceof Date) {
27
+ return obj1.getTime() === obj2.getTime();
28
+ }
29
+ // Handle arrays: compare length and then perform a recursive deep comparison on each item
30
+ if (Array.isArray(obj1)) {
31
+ if (obj1.length !== obj2.length)
32
+ return false;
33
+ for (let i = 0; i < obj1.length; i++) {
34
+ if (!isDeepEqualData(obj1[i], obj2[i]))
35
+ return false;
36
+ }
37
+ return true; // All array elements matched
38
+ }
39
+ // Compare the set of keys in each object
40
+ const keys1 = Object.keys(obj1);
41
+ const keys2 = Object.keys(obj2);
42
+ if (keys1.length !== keys2.length)
43
+ return false;
44
+ // Check each key-value pair recursively
45
+ for (const key of keys1) {
46
+ if (!keys2.includes(key))
47
+ return false;
48
+ if (!isDeepEqualData(obj1[key], obj2[key]))
49
+ return false;
50
+ }
51
+ return true; // All keys and values matched
52
+ }
53
+ exports.isDeepEqualData = isDeepEqualData;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Performs a deep-equal comparison of two parsed JSON structures.
3
+ *
4
+ * @param {any} obj1 - The first object to compare.
5
+ * @param {any} obj2 - The second object to compare.
6
+ * @returns {boolean} - Returns true if the two objects are deeply equal, false otherwise.
7
+ */
8
+ export declare function isDeepEqualData(obj1: any, obj2: any): boolean;
@@ -0,0 +1,49 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /**
3
+ * Performs a deep-equal comparison of two parsed JSON structures.
4
+ *
5
+ * @param {any} obj1 - The first object to compare.
6
+ * @param {any} obj2 - The second object to compare.
7
+ * @returns {boolean} - Returns true if the two objects are deeply equal, false otherwise.
8
+ */
9
+ export function isDeepEqualData(obj1, obj2) {
10
+ // Check for strict equality first
11
+ if (obj1 === obj2)
12
+ return true;
13
+ // Check if either is null or undefined
14
+ if (obj1 == null || obj2 == null)
15
+ return false;
16
+ // Check if both are objects
17
+ if (typeof obj1 !== "object" && typeof obj2 !== "object")
18
+ return obj1 === obj2;
19
+ // If they are not strictly equal, they both need to be Objects
20
+ if (obj1.constructor !== obj2.constructor)
21
+ return false;
22
+ // Special handling for Date objects
23
+ if (obj1 instanceof Date && obj2 instanceof Date) {
24
+ return obj1.getTime() === obj2.getTime();
25
+ }
26
+ // Handle arrays: compare length and then perform a recursive deep comparison on each item
27
+ if (Array.isArray(obj1)) {
28
+ if (obj1.length !== obj2.length)
29
+ return false;
30
+ for (let i = 0; i < obj1.length; i++) {
31
+ if (!isDeepEqualData(obj1[i], obj2[i]))
32
+ return false;
33
+ }
34
+ return true; // All array elements matched
35
+ }
36
+ // Compare the set of keys in each object
37
+ const keys1 = Object.keys(obj1);
38
+ const keys2 = Object.keys(obj2);
39
+ if (keys1.length !== keys2.length)
40
+ return false;
41
+ // Check each key-value pair recursively
42
+ for (const key of keys1) {
43
+ if (!keys2.includes(key))
44
+ return false;
45
+ if (!isDeepEqualData(obj1[key], obj2[key]))
46
+ return false;
47
+ }
48
+ return true; // All keys and values matched
49
+ }
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const node_assert_1 = __importDefault(require("node:assert"));
7
+ const vitest_1 = require("vitest");
8
+ const isDeepEqualData_js_1 = require("./isDeepEqualData.cjs");
9
+ (0, vitest_1.test)("checks if two primitives are equal", async () => {
10
+ let x = 1;
11
+ let y = 1;
12
+ let result = (0, isDeepEqualData_js_1.isDeepEqualData)(x, y);
13
+ node_assert_1.default.equal(result, true);
14
+ x = 1;
15
+ y = 2;
16
+ result = (0, isDeepEqualData_js_1.isDeepEqualData)(x, y);
17
+ node_assert_1.default.equal(result, false);
18
+ });
19
+ (0, vitest_1.test)("returns false for different types", async () => {
20
+ const obj = { a: 1 };
21
+ const num = 1;
22
+ const result = (0, isDeepEqualData_js_1.isDeepEqualData)(obj, num);
23
+ node_assert_1.default.equal(result, false);
24
+ });
25
+ (0, vitest_1.test)("returns false for null values compared with objects", async () => {
26
+ const obj = { a: 1 };
27
+ const result = (0, isDeepEqualData_js_1.isDeepEqualData)(obj, null);
28
+ node_assert_1.default.equal(result, false);
29
+ });
30
+ (0, vitest_1.test)("identifies two equal objects", async () => {
31
+ const obj1 = { a: 1, b: 2 };
32
+ const obj2 = { a: 1, b: 2 };
33
+ const result = (0, isDeepEqualData_js_1.isDeepEqualData)(obj1, obj2);
34
+ node_assert_1.default.equal(result, true);
35
+ });
36
+ (0, vitest_1.test)("identifies two objects with different values", async () => {
37
+ const obj1 = { a: 1, b: 2 };
38
+ const obj2 = { a: 1, b: 3 };
39
+ const result = (0, isDeepEqualData_js_1.isDeepEqualData)(obj1, obj2);
40
+ node_assert_1.default.equal(result, false);
41
+ });
42
+ (0, vitest_1.test)("identifies two objects with different number of keys", async () => {
43
+ const obj1 = { a: 1, b: 2 };
44
+ const obj2 = { a: 1, b: 2, c: 3 };
45
+ const result = (0, isDeepEqualData_js_1.isDeepEqualData)(obj1, obj2);
46
+ node_assert_1.default.equal(result, false);
47
+ });
48
+ (0, vitest_1.test)("handles nested objects", async () => {
49
+ const obj1 = { a: { c: 1 }, b: 2 };
50
+ const obj2 = { a: { c: 1 }, b: 2 };
51
+ const result = (0, isDeepEqualData_js_1.isDeepEqualData)(obj1, obj2);
52
+ node_assert_1.default.equal(result, true);
53
+ });
54
+ (0, vitest_1.test)("detects inequality in nested objects", async () => {
55
+ const obj1 = { a: { c: 1 }, b: 2 };
56
+ const obj2 = { a: { c: 2 }, b: 2 };
57
+ const result = (0, isDeepEqualData_js_1.isDeepEqualData)(obj1, obj2);
58
+ node_assert_1.default.equal(result, false);
59
+ });
60
+ (0, vitest_1.test)("compares arrays correctly", async () => {
61
+ const arr1 = [1, 2, 3];
62
+ const arr2 = [1, 2, 3];
63
+ const result = (0, isDeepEqualData_js_1.isDeepEqualData)(arr1, arr2);
64
+ node_assert_1.default.equal(result, true);
65
+ const arr3 = [1, 2, 3];
66
+ const arr4 = [1, 2, 4];
67
+ const result2 = (0, isDeepEqualData_js_1.isDeepEqualData)(arr3, arr4);
68
+ node_assert_1.default.equal(result2, false);
69
+ });
70
+ (0, vitest_1.test)("returns false for null comparison with object", () => {
71
+ const obj = { a: 1 };
72
+ const result = (0, isDeepEqualData_js_1.isDeepEqualData)(obj, null);
73
+ node_assert_1.default.equal(result, false);
74
+ });
75
+ (0, vitest_1.test)("distinguishes between array and object with same enumerable properties", () => {
76
+ const obj = { 0: "one", 1: "two", length: 2 };
77
+ const arr = ["one", "two"];
78
+ const result = (0, isDeepEqualData_js_1.isDeepEqualData)(obj, arr);
79
+ node_assert_1.default.equal(result, false);
80
+ });
81
+ (0, vitest_1.test)("returns false when comparing objects with different prototypes", () => {
82
+ const obj1 = Object.create({ a: 1 });
83
+ const obj2 = Object.create(null);
84
+ obj1.b = 2;
85
+ obj2.b = 2;
86
+ const result = (0, isDeepEqualData_js_1.isDeepEqualData)(obj1, obj2);
87
+ node_assert_1.default.equal(result, false);
88
+ });
89
+ (0, vitest_1.test)("handles date object comparisons correctly", () => {
90
+ const date1 = new Date(2000, 0, 1);
91
+ const date2 = new Date(2000, 0, 1);
92
+ const date3 = new Date(2000, 0, 2);
93
+ node_assert_1.default.equal((0, isDeepEqualData_js_1.isDeepEqualData)(date1, date2), true);
94
+ node_assert_1.default.equal((0, isDeepEqualData_js_1.isDeepEqualData)(date1, date3), false);
95
+ });
96
+ (0, vitest_1.test)("handles function comparisons", () => {
97
+ const func1 = () => {
98
+ console.log("hello");
99
+ };
100
+ const func2 = () => {
101
+ console.log("hello");
102
+ };
103
+ const func3 = () => {
104
+ console.log("world");
105
+ };
106
+ node_assert_1.default.equal((0, isDeepEqualData_js_1.isDeepEqualData)(func1, func2), false);
107
+ node_assert_1.default.equal((0, isDeepEqualData_js_1.isDeepEqualData)(func1, func3), false);
108
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,103 @@
1
+ import assert from "node:assert";
2
+ import { test } from "vitest";
3
+ import { isDeepEqualData } from "./isDeepEqualData.js";
4
+ test("checks if two primitives are equal", async () => {
5
+ let x = 1;
6
+ let y = 1;
7
+ let result = isDeepEqualData(x, y);
8
+ assert.equal(result, true);
9
+ x = 1;
10
+ y = 2;
11
+ result = isDeepEqualData(x, y);
12
+ assert.equal(result, false);
13
+ });
14
+ test("returns false for different types", async () => {
15
+ const obj = { a: 1 };
16
+ const num = 1;
17
+ const result = isDeepEqualData(obj, num);
18
+ assert.equal(result, false);
19
+ });
20
+ test("returns false for null values compared with objects", async () => {
21
+ const obj = { a: 1 };
22
+ const result = isDeepEqualData(obj, null);
23
+ assert.equal(result, false);
24
+ });
25
+ test("identifies two equal objects", async () => {
26
+ const obj1 = { a: 1, b: 2 };
27
+ const obj2 = { a: 1, b: 2 };
28
+ const result = isDeepEqualData(obj1, obj2);
29
+ assert.equal(result, true);
30
+ });
31
+ test("identifies two objects with different values", async () => {
32
+ const obj1 = { a: 1, b: 2 };
33
+ const obj2 = { a: 1, b: 3 };
34
+ const result = isDeepEqualData(obj1, obj2);
35
+ assert.equal(result, false);
36
+ });
37
+ test("identifies two objects with different number of keys", async () => {
38
+ const obj1 = { a: 1, b: 2 };
39
+ const obj2 = { a: 1, b: 2, c: 3 };
40
+ const result = isDeepEqualData(obj1, obj2);
41
+ assert.equal(result, false);
42
+ });
43
+ test("handles nested objects", async () => {
44
+ const obj1 = { a: { c: 1 }, b: 2 };
45
+ const obj2 = { a: { c: 1 }, b: 2 };
46
+ const result = isDeepEqualData(obj1, obj2);
47
+ assert.equal(result, true);
48
+ });
49
+ test("detects inequality in nested objects", async () => {
50
+ const obj1 = { a: { c: 1 }, b: 2 };
51
+ const obj2 = { a: { c: 2 }, b: 2 };
52
+ const result = isDeepEqualData(obj1, obj2);
53
+ assert.equal(result, false);
54
+ });
55
+ test("compares arrays correctly", async () => {
56
+ const arr1 = [1, 2, 3];
57
+ const arr2 = [1, 2, 3];
58
+ const result = isDeepEqualData(arr1, arr2);
59
+ assert.equal(result, true);
60
+ const arr3 = [1, 2, 3];
61
+ const arr4 = [1, 2, 4];
62
+ const result2 = isDeepEqualData(arr3, arr4);
63
+ assert.equal(result2, false);
64
+ });
65
+ test("returns false for null comparison with object", () => {
66
+ const obj = { a: 1 };
67
+ const result = isDeepEqualData(obj, null);
68
+ assert.equal(result, false);
69
+ });
70
+ test("distinguishes between array and object with same enumerable properties", () => {
71
+ const obj = { 0: "one", 1: "two", length: 2 };
72
+ const arr = ["one", "two"];
73
+ const result = isDeepEqualData(obj, arr);
74
+ assert.equal(result, false);
75
+ });
76
+ test("returns false when comparing objects with different prototypes", () => {
77
+ const obj1 = Object.create({ a: 1 });
78
+ const obj2 = Object.create(null);
79
+ obj1.b = 2;
80
+ obj2.b = 2;
81
+ const result = isDeepEqualData(obj1, obj2);
82
+ assert.equal(result, false);
83
+ });
84
+ test("handles date object comparisons correctly", () => {
85
+ const date1 = new Date(2000, 0, 1);
86
+ const date2 = new Date(2000, 0, 1);
87
+ const date3 = new Date(2000, 0, 2);
88
+ assert.equal(isDeepEqualData(date1, date2), true);
89
+ assert.equal(isDeepEqualData(date1, date3), false);
90
+ });
91
+ test("handles function comparisons", () => {
92
+ const func1 = () => {
93
+ console.log("hello");
94
+ };
95
+ const func2 = () => {
96
+ console.log("hello");
97
+ };
98
+ const func3 = () => {
99
+ console.log("world");
100
+ };
101
+ assert.equal(isDeepEqualData(func1, func2), false);
102
+ assert.equal(isDeepEqualData(func1, func3), false);
103
+ });