@ztimson/utils 0.27.8 → 0.27.9
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.cjs +21 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +21 -21
- package/dist/index.mjs.map +1 -1
- package/dist/json.d.ts +23 -0
- package/dist/objects.d.ts +0 -22
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -117,6 +117,27 @@ ${opts.message || this.desc}`;
|
|
|
117
117
|
`;
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
+
function JSONAttemptParse(json, fallback) {
|
|
121
|
+
try {
|
|
122
|
+
return JSON.parse(json);
|
|
123
|
+
} catch {
|
|
124
|
+
return fallback ?? json;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function JSONSerialize(obj) {
|
|
128
|
+
if (typeof obj == "object" && obj != null) return JSONSanitize(obj);
|
|
129
|
+
return obj;
|
|
130
|
+
}
|
|
131
|
+
function JSONSanitize(obj, space) {
|
|
132
|
+
const cache = [];
|
|
133
|
+
return JSON.stringify(obj, (key, value) => {
|
|
134
|
+
if (typeof value === "object" && value !== null) {
|
|
135
|
+
if (cache.includes(value)) return "[Circular]";
|
|
136
|
+
cache.push(value);
|
|
137
|
+
}
|
|
138
|
+
return value;
|
|
139
|
+
}, space);
|
|
140
|
+
}
|
|
120
141
|
function applyDeltas(base, ...deltas) {
|
|
121
142
|
function applyDelta(base2, delta) {
|
|
122
143
|
if (delta === null) return null;
|
|
@@ -270,27 +291,6 @@ function mixin(target, constructors) {
|
|
|
270
291
|
function objectMap(obj, fn2) {
|
|
271
292
|
return Object.entries(obj).map(([key, value]) => [key, fn2(key, value)]).reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {});
|
|
272
293
|
}
|
|
273
|
-
function JSONAttemptParse(json) {
|
|
274
|
-
try {
|
|
275
|
-
return JSON.parse(json);
|
|
276
|
-
} catch {
|
|
277
|
-
return json;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
function JSONSerialize(obj) {
|
|
281
|
-
if (typeof obj == "object" && obj != null) return JSONSanitize(obj);
|
|
282
|
-
return obj;
|
|
283
|
-
}
|
|
284
|
-
function JSONSanitize(obj, space) {
|
|
285
|
-
const cache = [];
|
|
286
|
-
return JSON.stringify(obj, (key, value) => {
|
|
287
|
-
if (typeof value === "object" && value !== null) {
|
|
288
|
-
if (cache.includes(value)) return "[Circular]";
|
|
289
|
-
cache.push(value);
|
|
290
|
-
}
|
|
291
|
-
return value;
|
|
292
|
-
}, space);
|
|
293
|
-
}
|
|
294
294
|
class ASet extends Array {
|
|
295
295
|
/** Number of elements in set */
|
|
296
296
|
get size() {
|