@lumjs/core 1.38.3 → 1.38.4

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.
@@ -11,6 +11,17 @@ const DEF =
11
11
  MAXD: 1,
12
12
  NEWD: 0,
13
13
  }
14
+ const ANY = '{...}';
15
+
16
+ function _opts(opts) {
17
+ return (typeof opts === N
18
+ ? { maxDepth: opts }
19
+ : (isObj(opts)
20
+ ? opts
21
+ : {}
22
+ )
23
+ );
24
+ }
14
25
 
15
26
  /**
16
27
  * Stringify a Javascript value.
@@ -40,10 +51,7 @@ const DEF =
40
51
  */
41
52
  function stringify (what, opts={}, addNew=null)
42
53
  {
43
- if (typeof opts === N)
44
- {
45
- opts = {maxDepth: opts}
46
- }
54
+ opts = _opts(opts);
47
55
 
48
56
  if (typeof addNew === N)
49
57
  {
@@ -95,6 +103,8 @@ class Stringify
95
103
  */
96
104
  constructor(opts={})
97
105
  {
106
+ opts = _opts(opts);
107
+
98
108
  this.options = opts;
99
109
  this.maxDepth = opts.maxDepth ?? DEF.MAXD;
100
110
  this.newDepth = opts.newDepth ?? DEF.NEWD;
@@ -238,7 +248,37 @@ class Stringify
238
248
  }
239
249
 
240
250
  // If we reached here, it's another kind of object entirely.
241
- return container(Object.keys(what), '{', '}');
251
+ if (recurse)
252
+ {
253
+ let cstr = nameFor() + '{';
254
+ let keys = Object.keys(what);
255
+ for (let k=0; k < keys.length; k++)
256
+ {
257
+ let key = keys[k], val = what[key];
258
+ if (k > 0) cstr += ', ';
259
+ cstr += key + ':' + this.stringify(val, curd+1)
260
+ }
261
+ cstr += '}';
262
+ return cstr;
263
+ }
264
+ else
265
+ {
266
+ if (this.options.jsonObjects)
267
+ {
268
+ let json;
269
+ try {
270
+ json = JSON.stringify(what);
271
+ } catch (err) {
272
+ console.error(err);
273
+ json = ANY;
274
+ }
275
+ return nameFor() + json;
276
+ }
277
+ else
278
+ {
279
+ return nameFor() + ANY;
280
+ }
281
+ }
242
282
 
243
283
  } // if isObj
244
284
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lumjs/core",
3
- "version": "1.38.3",
3
+ "version": "1.38.4",
4
4
  "main": "lib/index.js",
5
5
  "exports":
6
6
  {