@zocomputer/system-api 0.3.0 → 0.3.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.
@@ -74,7 +74,7 @@ export declare function checkJsonValue(value: JsonValue, options?: {
74
74
  }): void;
75
75
  /** Return `[nodes, depth]` of a JSON tree without copying it. */
76
76
  export declare function measureJson(value: JsonValue, maxDepth?: number): [number, number];
77
- /** Serialize deterministically: sorted keys (code-unit order), no whitespace. */
77
+ /** Serialize deterministically: sorted keys (code-point order), no whitespace. */
78
78
  export declare function canonicalJsonString(value: JsonValue): string;
79
79
  /** Serialize keeping key order (the wire form the validator returns on success). */
80
80
  export declare function dumpsJson(value: JsonValue): string;
@@ -336,6 +336,19 @@ function measure(value, path, depth, walk) {
336
336
  function encodeString(value) {
337
337
  return JSON.stringify(value);
338
338
  }
339
+ function compareCodePoints(left, right) {
340
+ let a = 0;
341
+ let b = 0;
342
+ while (a < left.length && b < right.length) {
343
+ const pointA = left.codePointAt(a);
344
+ const pointB = right.codePointAt(b);
345
+ if (pointA !== pointB)
346
+ return pointA - pointB;
347
+ a += pointA > 0xffff ? 2 : 1;
348
+ b += pointB > 0xffff ? 2 : 1;
349
+ }
350
+ return left.length - a - (right.length - b);
351
+ }
339
352
  function writeValue(value, parts, sortKeys) {
340
353
  if (value === null)
341
354
  parts.push("null");
@@ -367,7 +380,7 @@ function writeValue(value, parts, sortKeys) {
367
380
  return;
368
381
  }
369
382
  if (sortKeys)
370
- keys.sort();
383
+ keys.sort(compareCodePoints);
371
384
  parts.push("{");
372
385
  keys.forEach((key, index) => {
373
386
  if (index)
@@ -379,7 +392,7 @@ function writeValue(value, parts, sortKeys) {
379
392
  parts.push("}");
380
393
  }
381
394
  }
382
- /** Serialize deterministically: sorted keys (code-unit order), no whitespace. */
395
+ /** Serialize deterministically: sorted keys (code-point order), no whitespace. */
383
396
  export function canonicalJsonString(value) {
384
397
  const canonical = canonicalizeJson(value, {
385
398
  maxNodes: null,