@mintjamsinc/ichigojs 0.1.75 → 0.1.76

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/ichigo.cjs CHANGED
@@ -9176,6 +9176,83 @@
9176
9176
  }
9177
9177
  }
9178
9178
 
9179
+ // Copyright (c) 2025 MintJams Inc. Licensed under MIT License.
9180
+ /**
9181
+ * The default Object.prototype.toString, used to detect plain objects that
9182
+ * have not overridden their string representation.
9183
+ */
9184
+ const objectToString = Object.prototype.toString;
9185
+ /**
9186
+ * Checks if the value is a non-null object.
9187
+ */
9188
+ function isObject(value) {
9189
+ return value !== null && typeof value === 'object';
9190
+ }
9191
+ /**
9192
+ * Checks if the value is a plain object (i.e. `[object Object]`).
9193
+ */
9194
+ function isPlainObject(value) {
9195
+ return objectToString.call(value) === '[object Object]';
9196
+ }
9197
+ /**
9198
+ * Converts a symbol to a readable string, leaving other values untouched.
9199
+ * Used when rendering Map keys and Set entries.
9200
+ */
9201
+ function stringifySymbol(value, index = '') {
9202
+ return typeof value === 'symbol' ? `Symbol(${value.description ?? index})` : value;
9203
+ }
9204
+ /**
9205
+ * JSON.stringify replacer that renders values JSON cannot represent natively
9206
+ * (Map, Set, Symbol, and non-plain objects) in a readable form.
9207
+ */
9208
+ function replacer(_key, value) {
9209
+ if (value instanceof Map) {
9210
+ return {
9211
+ [`Map(${value.size})`]: [...value.entries()].reduce((entries, [key, val], i) => {
9212
+ entries[`${stringifySymbol(key, i)} =>`] = val;
9213
+ return entries;
9214
+ }, {}),
9215
+ };
9216
+ }
9217
+ if (value instanceof Set) {
9218
+ return {
9219
+ [`Set(${value.size})`]: [...value.values()].map(v => stringifySymbol(v)),
9220
+ };
9221
+ }
9222
+ if (typeof value === 'symbol') {
9223
+ return stringifySymbol(value);
9224
+ }
9225
+ if (isObject(value) && !Array.isArray(value) && !isPlainObject(value)) {
9226
+ // Non-plain objects (Date, RegExp, DOM nodes, ...) render via their own toString
9227
+ return String(value);
9228
+ }
9229
+ return value;
9230
+ }
9231
+ /**
9232
+ * Converts a value to a string suitable for display in rendered output,
9233
+ * following Vue's `toDisplayString` semantics:
9234
+ * - strings are returned as-is
9235
+ * - null and undefined become an empty string
9236
+ * - arrays and plain objects (without a custom toString) are rendered as
9237
+ * pretty-printed JSON, with Map/Set/Symbol entries made readable
9238
+ * - everything else is converted with String()
9239
+ * @param value The value to convert.
9240
+ * @returns The display string for the value.
9241
+ */
9242
+ function toDisplayString(value) {
9243
+ if (typeof value === 'string') {
9244
+ return value;
9245
+ }
9246
+ if (value === null || value === undefined) {
9247
+ return '';
9248
+ }
9249
+ if (Array.isArray(value) ||
9250
+ (isObject(value) && (value.toString === objectToString || typeof value.toString !== 'function'))) {
9251
+ return JSON.stringify(value, replacer, 2);
9252
+ }
9253
+ return String(value);
9254
+ }
9255
+
9179
9256
  // Copyright (c) 2025 MintJams Inc. Licensed under MIT License.
9180
9257
  /**
9181
9258
  * List of standard JavaScript global objects that should be available in expressions.
@@ -9296,8 +9373,9 @@
9296
9373
  return GLOBAL_OBJECTS[name];
9297
9374
  return undefined;
9298
9375
  });
9299
- // Evaluate the expression and replace {{...}} in the text
9300
- result = result.replace(matches[i][0], String(evaluator.func(...values)));
9376
+ // Evaluate the expression and replace {{...}} in the text.
9377
+ // A function replacement keeps `$`-patterns in the value literal.
9378
+ result = result.replace(matches[i][0], () => toDisplayString(evaluator.func(...values)));
9301
9379
  });
9302
9380
  return result;
9303
9381
  };
@@ -13058,8 +13136,7 @@
13058
13136
  },
13059
13137
  applyToDOM() {
13060
13138
  const element = vNode.node;
13061
- const textContent = evaluator.evaluate();
13062
- element.textContent = textContent ?? '';
13139
+ element.textContent = toDisplayString(evaluator.evaluate());
13063
13140
  }
13064
13141
  };
13065
13142
  return updater;
@@ -15046,6 +15123,7 @@
15046
15123
  exports.VComponentRegistry = VComponentRegistry;
15047
15124
  exports.VDOM = VDOM;
15048
15125
  exports.defineComponent = defineComponent;
15126
+ exports.toDisplayString = toDisplayString;
15049
15127
 
15050
15128
  }));
15051
15129
  //# sourceMappingURL=ichigo.cjs.map