@dxos/util 0.8.4-main.c1de068 → 0.8.4-main.fd6878d

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/util",
3
- "version": "0.8.4-main.c1de068",
3
+ "version": "0.8.4-main.fd6878d",
4
4
  "description": "Temporary bucket for misc functions, which should graduate into separate packages.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -10,12 +10,12 @@
10
10
  "type": "module",
11
11
  "exports": {
12
12
  ".": {
13
+ "types": "./dist/types/src/index.d.ts",
13
14
  "browser": "./dist/lib/browser/index.mjs",
14
15
  "node": {
15
16
  "require": "./dist/lib/node/index.cjs",
16
17
  "default": "./dist/lib/node-esm/index.mjs"
17
- },
18
- "types": "./dist/types/src/index.d.ts"
18
+ }
19
19
  }
20
20
  },
21
21
  "types": "dist/types/src/index.d.ts",
@@ -29,15 +29,15 @@
29
29
  "dependencies": {
30
30
  "lodash.get": "^4.4.2",
31
31
  "lodash.set": "^4.3.2",
32
- "@dxos/debug": "0.8.4-main.c1de068",
33
- "@dxos/invariant": "0.8.4-main.c1de068",
34
- "@dxos/keys": "0.8.4-main.c1de068",
35
- "@dxos/node-std": "0.8.4-main.c1de068"
32
+ "@dxos/debug": "0.8.4-main.fd6878d",
33
+ "@dxos/invariant": "0.8.4-main.fd6878d",
34
+ "@dxos/keys": "0.8.4-main.fd6878d",
35
+ "@dxos/node-std": "0.8.4-main.fd6878d"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/lodash.get": "^4.4.9",
39
39
  "@types/lodash.set": "^4.3.9",
40
- "@dxos/crypto": "0.8.4-main.c1de068"
40
+ "@dxos/crypto": "0.8.4-main.fd6878d"
41
41
  },
42
42
  "publishConfig": {
43
43
  "access": "public"
package/src/array.test.ts CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { describe, expect, test } from 'vitest';
6
6
 
7
- import { diff, intersection, distinctBy, partition } from './array';
7
+ import { diff, distinctBy, intersection, partition } from './array';
8
8
 
9
9
  describe('diff', () => {
10
10
  test('returns the difference between two sets', () => {
@@ -2,7 +2,7 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { describe, test, expect } from 'vitest';
5
+ import { describe, expect, test } from 'vitest';
6
6
 
7
7
  import { CircularBuffer } from './circular-buffer';
8
8
 
@@ -6,7 +6,7 @@ import { expect, test } from 'vitest';
6
6
 
7
7
  import { PublicKey } from '@dxos/keys';
8
8
 
9
- import { makeSet, makeMap } from './complex';
9
+ import { makeMap, makeSet } from './complex';
10
10
 
11
11
  const PulicKeySet = makeSet<PublicKey>(PublicKey.hash);
12
12
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { expect, test } from 'vitest';
6
6
 
7
- import { createKeyPair, createId } from '@dxos/crypto';
7
+ import { createId, createKeyPair } from '@dxos/crypto';
8
8
  import { PublicKey } from '@dxos/keys';
9
9
 
10
10
  import { humanize } from './human-hash';
@@ -2,9 +2,9 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { describe, it, expect } from 'vitest';
5
+ import { describe, expect, it } from 'vitest';
6
6
 
7
- import { byPosition, type Position } from './position';
7
+ import { type Position, byPosition } from './position';
8
8
 
9
9
  type TestItem = {
10
10
  id: number;
package/src/sort.test.ts CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { describe, expect, test } from 'vitest';
6
6
 
7
- import { compareMulti, compareScalar, compareObject, compareString } from './sort';
7
+ import { compareMulti, compareObject, compareScalar, compareString } from './sort';
8
8
 
9
9
  const data = [
10
10
  { i: 0, idx: 1, label: 'apple' },
@@ -14,6 +14,6 @@ describe('string', () => {
14
14
  - 3
15
15
  `;
16
16
 
17
- expect(text).to.eq('- 1\n- 2\n - 3\n');
17
+ expect(text).to.eq('- 1\n- 2\n - 3');
18
18
  });
19
19
  });
package/src/string.ts CHANGED
@@ -16,9 +16,28 @@ export const capitalize = (str: string): string => {
16
16
  /**
17
17
  * Remove leading space from multi-line strings.
18
18
  */
19
- export const trim = (strings: TemplateStringsArray, ...values: any[]) => {
20
- const full = String.raw(strings, ...values);
21
- const lines = full.replace(/^\n/, '').split('\n');
22
- const indent = Math.min(...lines.filter((l) => l.trim()).map((l) => l.match(/^ */)![0].length));
23
- return lines.map((l) => l.slice(indent)).join('\n');
24
- };
19
+ export function trim(strings: TemplateStringsArray, ...values: any[]) {
20
+ // First, build the raw result with relative indentation.
21
+ const raw = strings.reduce((out, str, i) => {
22
+ out += str;
23
+ if (i < values.length) {
24
+ const match = str.match(/(^|\n)([ \t]*)$/);
25
+ const baseIndent = match ? match[2] : '';
26
+ const val = String(values[i]).replace(/\r?\n/g, '\n' + baseIndent);
27
+ out += val;
28
+ }
29
+ return out;
30
+ }, '');
31
+
32
+ // Split into lines and trim leading/trailing blank lines.
33
+ const lines = raw.split('\n');
34
+
35
+ while (lines.length && !lines[0].trim()) lines.shift();
36
+ while (lines.length && !lines[lines.length - 1].trim()) lines.pop();
37
+
38
+ // Find smallest indent across all non-blank lines.
39
+ const minIndent = Math.min(...lines.filter((l) => l.trim()).map((l) => l.match(/^[ \t]*/)?.[0].length ?? 0));
40
+
41
+ // Remove that indent from all lines.
42
+ return lines.map((l) => l.slice(minIndent)).join('\n');
43
+ }
package/src/tree.test.ts CHANGED
@@ -6,7 +6,7 @@ import { describe, test } from 'vitest';
6
6
 
7
7
  import { PublicKey } from '@dxos/keys';
8
8
 
9
- import { stringifyTree, type TreeNode } from './tree';
9
+ import { type TreeNode, stringifyTree } from './tree';
10
10
 
11
11
  describe('Tree logging', () => {
12
12
  test('simple', () => {
@@ -2,7 +2,7 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { test, expect, describe } from 'vitest';
5
+ import { describe, expect, test } from 'vitest';
6
6
 
7
7
  import { arrayToBuffer, arrayToString, bufferToArray, stringToArray } from './uint8array';
8
8
 
package/src/weak.test.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { test, expect, describe } from 'vitest';
5
+ import { describe, expect, test } from 'vitest';
6
6
 
7
7
  import { WeakDictionary } from './weak';
8
8