@ztimson/utils 0.27.7 → 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 +24 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +24 -20
- package/dist/index.mjs.map +1 -1
- package/dist/json.d.ts +23 -0
- package/dist/objects.d.ts +5 -20
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -121,6 +121,27 @@ ${opts.message || this.desc}`;
|
|
|
121
121
|
`;
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
|
+
function JSONAttemptParse(json, fallback) {
|
|
125
|
+
try {
|
|
126
|
+
return JSON.parse(json);
|
|
127
|
+
} catch {
|
|
128
|
+
return fallback ?? json;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function JSONSerialize(obj) {
|
|
132
|
+
if (typeof obj == "object" && obj != null) return JSONSanitize(obj);
|
|
133
|
+
return obj;
|
|
134
|
+
}
|
|
135
|
+
function JSONSanitize(obj, space) {
|
|
136
|
+
const cache = [];
|
|
137
|
+
return JSON.stringify(obj, (key, value) => {
|
|
138
|
+
if (typeof value === "object" && value !== null) {
|
|
139
|
+
if (cache.includes(value)) return "[Circular]";
|
|
140
|
+
cache.push(value);
|
|
141
|
+
}
|
|
142
|
+
return value;
|
|
143
|
+
}, space);
|
|
144
|
+
}
|
|
124
145
|
function applyDeltas(base, ...deltas) {
|
|
125
146
|
function applyDelta(base2, delta) {
|
|
126
147
|
if (delta === null) return null;
|
|
@@ -271,26 +292,8 @@ ${opts.message || this.desc}`;
|
|
|
271
292
|
});
|
|
272
293
|
});
|
|
273
294
|
}
|
|
274
|
-
function
|
|
275
|
-
|
|
276
|
-
return JSON.parse(json);
|
|
277
|
-
} catch {
|
|
278
|
-
return json;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
function JSONSerialize(obj) {
|
|
282
|
-
if (typeof obj == "object" && obj != null) return JSONSanitize(obj);
|
|
283
|
-
return obj;
|
|
284
|
-
}
|
|
285
|
-
function JSONSanitize(obj, space) {
|
|
286
|
-
const cache = [];
|
|
287
|
-
return JSON.stringify(obj, (key, value) => {
|
|
288
|
-
if (typeof value === "object" && value !== null) {
|
|
289
|
-
if (cache.includes(value)) return "[Circular]";
|
|
290
|
-
cache.push(value);
|
|
291
|
-
}
|
|
292
|
-
return value;
|
|
293
|
-
}, space);
|
|
295
|
+
function objectMap(obj, fn2) {
|
|
296
|
+
return Object.entries(obj).map(([key, value]) => [key, fn2(key, value)]).reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {});
|
|
294
297
|
}
|
|
295
298
|
class ASet extends Array {
|
|
296
299
|
/** Number of elements in set */
|
|
@@ -2534,6 +2537,7 @@ ${opts.message || this.desc}`;
|
|
|
2534
2537
|
exports2.mixin = mixin;
|
|
2535
2538
|
exports2.month = month;
|
|
2536
2539
|
exports2.numSuffix = numSuffix;
|
|
2540
|
+
exports2.objectMap = objectMap;
|
|
2537
2541
|
exports2.pad = pad;
|
|
2538
2542
|
exports2.parseUrl = parseUrl;
|
|
2539
2543
|
exports2.pascalCase = pascalCase;
|