@dxos/util 0.8.3 → 0.8.4-main.2e9d522
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 +78 -61
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +78 -61
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/array.d.ts.map +1 -1
- package/dist/types/src/assume.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +2 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/json.d.ts +1 -1
- package/dist/types/src/json.d.ts.map +1 -1
- package/dist/types/src/object.d.ts +3 -0
- package/dist/types/src/object.d.ts.map +1 -1
- package/dist/types/src/safe-parse.d.ts.map +1 -1
- package/dist/types/src/string.d.ts +4 -0
- package/dist/types/src/string.d.ts.map +1 -1
- package/dist/types/src/string.test.d.ts +2 -0
- package/dist/types/src/string.test.d.ts.map +1 -0
- package/dist/types/src/url.d.ts +5 -0
- package/dist/types/src/url.d.ts.map +1 -0
- package/dist/types/src/url.test.d.ts +2 -0
- package/dist/types/src/url.test.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/src/array.ts +0 -2
- package/src/assume.ts +0 -1
- package/src/index.ts +2 -2
- package/src/json.ts +2 -7
- package/src/object.ts +3 -0
- package/src/safe-parse.ts +3 -1
- package/src/string.test.ts +19 -0
- package/src/string.ts +10 -0
- package/src/url.test.ts +22 -0
- package/src/url.ts +15 -0
- package/dist/lib/node/index.cjs +0 -2309
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/util",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4-main.2e9d522",
|
|
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",
|
|
@@ -29,15 +29,15 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"lodash.get": "^4.4.2",
|
|
31
31
|
"lodash.set": "^4.3.2",
|
|
32
|
-
"@dxos/
|
|
33
|
-
"@dxos/
|
|
34
|
-
"@dxos/
|
|
35
|
-
"@dxos/
|
|
32
|
+
"@dxos/debug": "0.8.4-main.2e9d522",
|
|
33
|
+
"@dxos/invariant": "0.8.4-main.2e9d522",
|
|
34
|
+
"@dxos/keys": "0.8.4-main.2e9d522",
|
|
35
|
+
"@dxos/node-std": "0.8.4-main.2e9d522"
|
|
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.
|
|
40
|
+
"@dxos/crypto": "0.8.4-main.2e9d522"
|
|
41
41
|
},
|
|
42
42
|
"publishConfig": {
|
|
43
43
|
"access": "public"
|
package/src/array.ts
CHANGED
|
@@ -16,7 +16,6 @@ export type DiffResult<A, B = A> = {
|
|
|
16
16
|
* @param next
|
|
17
17
|
* @param comparator
|
|
18
18
|
*/
|
|
19
|
-
// TODO(burdon): Factor out.
|
|
20
19
|
export const diff = <A, B = A>(
|
|
21
20
|
previous: readonly A[],
|
|
22
21
|
next: readonly B[],
|
|
@@ -43,7 +42,6 @@ export const diff = <A, B = A>(
|
|
|
43
42
|
return result;
|
|
44
43
|
};
|
|
45
44
|
|
|
46
|
-
// TODO(burdon): Factor out.
|
|
47
45
|
export const intersection = <A, B = A>(a: A[], b: B[], comparator: Comparator<A, B>): A[] =>
|
|
48
46
|
a.filter((a) => b.find((b) => comparator(a, b)) !== undefined);
|
|
49
47
|
|
package/src/assume.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
export * from './array-to-hex';
|
|
6
6
|
export * from './array';
|
|
7
|
+
export * from './assume';
|
|
7
8
|
export * from './binder';
|
|
8
9
|
export * from './bitfield';
|
|
9
10
|
export * from './callback-collection';
|
|
@@ -41,7 +42,6 @@ export * from './safe-await';
|
|
|
41
42
|
export * from './safe-instanceof';
|
|
42
43
|
export * from './safe-parse';
|
|
43
44
|
export * from './sliding-window-summary';
|
|
44
|
-
export * from './sliding-window-summary';
|
|
45
45
|
export * from './sort';
|
|
46
46
|
export * from './string';
|
|
47
47
|
export * from './sum';
|
|
@@ -51,5 +51,5 @@ export * from './tracer';
|
|
|
51
51
|
export * from './tree';
|
|
52
52
|
export * from './types';
|
|
53
53
|
export * from './uint8array';
|
|
54
|
+
export * from './url';
|
|
54
55
|
export * from './weak';
|
|
55
|
-
export * from './assume';
|
package/src/json.ts
CHANGED
|
@@ -17,7 +17,7 @@ const LOG_MAX_DEPTH = 7;
|
|
|
17
17
|
/**
|
|
18
18
|
* JSON.stringify replacer.
|
|
19
19
|
*/
|
|
20
|
-
export
|
|
20
|
+
export const jsonReplacer = (key: string, value: any): any => {
|
|
21
21
|
// TODO(burdon): Why is this represented as `{ type: 'Buffer', data }`.
|
|
22
22
|
if (value !== null && typeof value === 'object' && typeof value[inspect.custom] === 'function') {
|
|
23
23
|
return value[inspect.custom]();
|
|
@@ -32,13 +32,8 @@ export function jsonReplacer(this: any, key: string, value: any): any {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
// TODO(burdon): Option.
|
|
36
|
-
// code if (Array.isArray(value)) {
|
|
37
|
-
// code return value.length;
|
|
38
|
-
// code } else {
|
|
39
35
|
return value;
|
|
40
|
-
|
|
41
|
-
}
|
|
36
|
+
};
|
|
42
37
|
|
|
43
38
|
/**
|
|
44
39
|
* Recursively converts an object into a JSON-compatible object.
|
package/src/object.ts
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated Use `Struct.keys` from effect.
|
|
7
|
+
*/
|
|
5
8
|
export const keys = <R>(obj: R): (keyof R)[] => Object.keys(obj as any) as (keyof R)[];
|
|
6
9
|
|
|
7
10
|
export const entries = <R>(obj: R): [keyof R, R[keyof R]][] => Object.entries(obj as any) as [keyof R, any][];
|
package/src/safe-parse.ts
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { describe, test } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { trim } from './string';
|
|
8
|
+
|
|
9
|
+
describe('string', () => {
|
|
10
|
+
test('dedent', async ({ expect }) => {
|
|
11
|
+
const text = trim`
|
|
12
|
+
- 1
|
|
13
|
+
- 2
|
|
14
|
+
- 3
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
expect(text).to.eq('- 1\n- 2\n - 3\n');
|
|
18
|
+
});
|
|
19
|
+
});
|
package/src/string.ts
CHANGED
|
@@ -12,3 +12,13 @@ export const capitalize = (str: string): string => {
|
|
|
12
12
|
|
|
13
13
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
14
14
|
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Remove leading space from multi-line strings.
|
|
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
|
+
};
|
package/src/url.test.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { describe, it } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { createUrl } from './url';
|
|
8
|
+
|
|
9
|
+
describe('url', () => {
|
|
10
|
+
it('should create a url', ({ expect }) => {
|
|
11
|
+
const url = createUrl('https://example.com', {
|
|
12
|
+
i1: undefined,
|
|
13
|
+
i2: null,
|
|
14
|
+
p1: true,
|
|
15
|
+
p2: false,
|
|
16
|
+
p3: 'dxos',
|
|
17
|
+
p4: 100,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
expect(url.toString()).toBe('https://example.com/?p1=true&p2=false&p3=dxos&p4=100');
|
|
21
|
+
});
|
|
22
|
+
});
|
package/src/url.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Normalize construction of URLs.
|
|
7
|
+
*/
|
|
8
|
+
export const createUrl = (url: URL | string, search?: Record<string, any | undefined>): URL => {
|
|
9
|
+
const base = typeof url === 'string' ? new URL(url) : url;
|
|
10
|
+
if (search) {
|
|
11
|
+
base.search = new URLSearchParams(Object.entries(search).filter(([_, value]) => value != null)).toString();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return base;
|
|
15
|
+
};
|