@dxos/util 0.5.3-main.2800199 → 0.5.3-main.2ad0afc
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/lib/browser/index.mjs +0 -25
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +0 -25
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/index.d.ts +0 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/index.ts +0 -1
- package/dist/types/src/array.d.ts +0 -15
- package/dist/types/src/array.d.ts.map +0 -1
- package/dist/types/src/array.test.d.ts +0 -2
- package/dist/types/src/array.test.d.ts.map +0 -1
- package/src/array.test.ts +0 -42
- package/src/array.ts +0 -48
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,OAAO,CAAC;AACtB,cAAc,kBAAkB,CAAC;AACjC,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/util",
|
|
3
|
-
"version": "0.5.3-main.
|
|
3
|
+
"version": "0.5.3-main.2ad0afc",
|
|
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",
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
"src"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@dxos/debug": "0.5.3-main.
|
|
20
|
-
"@dxos/invariant": "0.5.3-main.
|
|
21
|
-
"@dxos/keys": "0.5.3-main.
|
|
22
|
-
"@dxos/node-std": "0.5.3-main.
|
|
19
|
+
"@dxos/debug": "0.5.3-main.2ad0afc",
|
|
20
|
+
"@dxos/invariant": "0.5.3-main.2ad0afc",
|
|
21
|
+
"@dxos/keys": "0.5.3-main.2ad0afc",
|
|
22
|
+
"@dxos/node-std": "0.5.3-main.2ad0afc"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@dxos/crypto": "0.5.3-main.
|
|
25
|
+
"@dxos/crypto": "0.5.3-main.2ad0afc"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
package/src/index.ts
CHANGED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export type Comparator<A, B = A> = (a: A, b: B) => boolean;
|
|
2
|
-
export type DiffResult<A, B = A> = {
|
|
3
|
-
added: B[];
|
|
4
|
-
updated: B[];
|
|
5
|
-
removed: A[];
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Compute diff between two arrays.
|
|
9
|
-
* @param previous
|
|
10
|
-
* @param next
|
|
11
|
-
* @param comparator
|
|
12
|
-
*/
|
|
13
|
-
export declare const diff: <A, B = A>(previous: readonly A[], next: readonly B[], comparator: Comparator<A, B>) => DiffResult<A, B>;
|
|
14
|
-
export declare const intersection: <A, B = A>(a: A[], b: B[], comparator: Comparator<A, B>) => A[];
|
|
15
|
-
//# sourceMappingURL=array.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../../src/array.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC;AAE3D,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI;IACjC,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,OAAO,EAAE,CAAC,EAAE,CAAC;IACb,OAAO,EAAE,CAAC,EAAE,CAAC;CACd,CAAC;AAEF;;;;;GAKG;AAEH,eAAO,MAAM,IAAI,0GAwBhB,CAAC;AAGF,eAAO,MAAM,YAAY,iEACuC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"array.test.d.ts","sourceRoot":"","sources":["../../../src/array.test.ts"],"names":[],"mappings":""}
|
package/src/array.test.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { expect } from 'chai';
|
|
6
|
-
import { describe, test } from 'vitest';
|
|
7
|
-
|
|
8
|
-
import { diff, intersection } from './array';
|
|
9
|
-
|
|
10
|
-
describe('diff', () => {
|
|
11
|
-
test('returns the difference between two sets', () => {
|
|
12
|
-
{
|
|
13
|
-
const { added, updated, removed } = diff<number>([], [], (a, b) => a === b);
|
|
14
|
-
expect(added).to.deep.eq([]);
|
|
15
|
-
expect(updated).to.deep.eq([]);
|
|
16
|
-
expect(removed).to.deep.eq([]);
|
|
17
|
-
}
|
|
18
|
-
{
|
|
19
|
-
const previous = [1, 2, 3];
|
|
20
|
-
const next = [2, 3, 4];
|
|
21
|
-
const { added, updated, removed } = diff(previous, next, (a, b) => a === b);
|
|
22
|
-
expect(added).to.deep.eq([4]);
|
|
23
|
-
expect(updated).to.deep.eq([2, 3]);
|
|
24
|
-
expect(removed).to.deep.eq([1]);
|
|
25
|
-
}
|
|
26
|
-
{
|
|
27
|
-
const previous = [{ x: 1 }, { x: 2 }, { x: 3 }];
|
|
28
|
-
const next = [{ x: 2 }, { x: 3 }, { x: 4 }];
|
|
29
|
-
const { added, updated, removed } = diff(previous, next, (a, b) => a.x === b.x);
|
|
30
|
-
expect(added).to.deep.eq([{ x: 4 }]);
|
|
31
|
-
expect(updated).to.deep.eq([{ x: 2 }, { x: 3 }]);
|
|
32
|
-
expect(removed).to.deep.eq([{ x: 1 }]);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('intersection', () => {
|
|
37
|
-
expect(intersection([1, 2, 3], [2, 3, 4], (a, b) => a === b)).to.deep.eq([2, 3]);
|
|
38
|
-
expect(
|
|
39
|
-
intersection([{ x: 1 }, { x: 2 }, { x: 3 }], [{ x: 2 }, { x: 3 }, { x: 4 }], (a, b) => a.x === b.x),
|
|
40
|
-
).to.deep.eq([{ x: 2 }, { x: 3 }]);
|
|
41
|
-
});
|
|
42
|
-
});
|
package/src/array.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
export type Comparator<A, B = A> = (a: A, b: B) => boolean;
|
|
6
|
-
|
|
7
|
-
export type DiffResult<A, B = A> = {
|
|
8
|
-
added: B[];
|
|
9
|
-
updated: B[];
|
|
10
|
-
removed: A[];
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Compute diff between two arrays.
|
|
15
|
-
* @param previous
|
|
16
|
-
* @param next
|
|
17
|
-
* @param comparator
|
|
18
|
-
*/
|
|
19
|
-
// TODO(burdon): Factor out.
|
|
20
|
-
export const diff = <A, B = A>(
|
|
21
|
-
previous: readonly A[],
|
|
22
|
-
next: readonly B[],
|
|
23
|
-
comparator: Comparator<A, B>,
|
|
24
|
-
): DiffResult<A, B> => {
|
|
25
|
-
const remaining = [...previous];
|
|
26
|
-
const result: DiffResult<A, B> = {
|
|
27
|
-
added: [],
|
|
28
|
-
updated: [],
|
|
29
|
-
removed: remaining,
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
// TODO(burdon): Mark and sweep.
|
|
33
|
-
for (const object of next) {
|
|
34
|
-
const index = remaining.findIndex((item) => comparator(item, object));
|
|
35
|
-
if (index === -1) {
|
|
36
|
-
result.added.push(object);
|
|
37
|
-
} else {
|
|
38
|
-
result.updated.push(object);
|
|
39
|
-
remaining.splice(index, 1);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return result;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// TODO(burdon): Factor out.
|
|
47
|
-
export const intersection = <A, B = A>(a: A[], b: B[], comparator: Comparator<A, B>): A[] =>
|
|
48
|
-
a.filter((a) => b.find((b) => comparator(a, b)) !== undefined);
|