@dxos/util 0.8.2-main.fbd8ed0 → 0.8.2-staging.42af850
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 +169 -149
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +154 -131
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +169 -149
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/bitfield.d.ts +1 -1
- package/dist/types/src/bitfield.d.ts.map +1 -1
- package/dist/types/src/callback-collection.d.ts.map +1 -1
- package/dist/types/src/callback.d.ts.map +1 -1
- package/dist/types/src/complex.d.ts.map +1 -1
- package/dist/types/src/deep.d.ts +3 -2
- package/dist/types/src/deep.d.ts.map +1 -1
- package/dist/types/src/di-key.d.ts.map +1 -1
- package/dist/types/src/human-hash.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +12 -11
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/map-values.d.ts +5 -0
- package/dist/types/src/map-values.d.ts.map +1 -1
- package/dist/types/src/object.d.ts +3 -0
- package/dist/types/src/object.d.ts.map +1 -0
- package/dist/types/src/sliding-window-summary.d.ts.map +1 -1
- package/dist/types/src/tracer.d.ts.map +1 -1
- package/package.json +10 -6
- package/src/bitfield.ts +2 -2
- package/src/callback-collection.ts +3 -3
- package/src/callback.ts +2 -2
- package/src/complex.ts +6 -6
- package/src/deep.ts +6 -2
- package/src/defer.ts +2 -2
- package/src/di-key.ts +2 -2
- package/src/human-hash.ts +2 -2
- package/src/index.ts +12 -11
- package/src/map-values.ts +14 -0
- package/src/object.ts +7 -0
- package/src/sliding-window-summary.ts +3 -3
- package/src/tracer.ts +6 -6
- package/src/weak.ts +2 -2
package/src/map-values.ts
CHANGED
|
@@ -124,3 +124,17 @@ class DeepMapperAsync {
|
|
|
124
124
|
}
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Visits all values on an object or every item in an array.
|
|
130
|
+
* No-op if the value is not an object or array.
|
|
131
|
+
*/
|
|
132
|
+
export const visitValues = (object: unknown, visitor: (value: unknown, key: string | number) => void) => {
|
|
133
|
+
if (Array.isArray(object)) {
|
|
134
|
+
object.forEach((item, index) => visitor(item, index));
|
|
135
|
+
} else if (typeof object === 'object' && object !== null) {
|
|
136
|
+
for (const [key, value] of Object.entries(object)) {
|
|
137
|
+
visitor(value, key);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
};
|
package/src/object.ts
ADDED
|
@@ -28,12 +28,12 @@ export class SlidingWindowSummary {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
public record(value: number) {
|
|
31
|
+
public record(value: number): void {
|
|
32
32
|
const evicted = this._buffer.push(value);
|
|
33
33
|
this._sum += value - (evicted ?? 0);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
public average() {
|
|
36
|
+
public average(): number {
|
|
37
37
|
return this._buffer.elementCount === 0 ? 0 : this._withPrecision(this._sum / this._buffer.elementCount);
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -58,7 +58,7 @@ export class SlidingWindowSummary {
|
|
|
58
58
|
return { mean, median, p90, stdDev, histogram };
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
private _withPrecision(value: number) {
|
|
61
|
+
private _withPrecision(value: number): number {
|
|
62
62
|
if (this._precision == null) {
|
|
63
63
|
return value;
|
|
64
64
|
}
|
package/src/tracer.ts
CHANGED
|
@@ -32,7 +32,7 @@ export class Tracer {
|
|
|
32
32
|
return this._recording;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
keys() {
|
|
35
|
+
keys(): string[] {
|
|
36
36
|
return Array.from(this._events.keys());
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -45,21 +45,21 @@ export class Tracer {
|
|
|
45
45
|
return events;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
clear() {
|
|
48
|
+
clear(): void {
|
|
49
49
|
this._events.clear();
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
start() {
|
|
52
|
+
start(): this {
|
|
53
53
|
this._recording = true;
|
|
54
54
|
return this;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
stop() {
|
|
57
|
+
stop(): this {
|
|
58
58
|
this._recording = false;
|
|
59
59
|
return this;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
emit(id: string, value?: any) {
|
|
62
|
+
emit(id: string, value?: any): void {
|
|
63
63
|
this._post(this._createEvent(id, value));
|
|
64
64
|
}
|
|
65
65
|
|
|
@@ -84,7 +84,7 @@ export class Tracer {
|
|
|
84
84
|
return event;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
private _post(event: Event) {
|
|
87
|
+
private _post(event: Event): void {
|
|
88
88
|
if (this._recording) {
|
|
89
89
|
defaultMap(this._events, event.id, []).push(event);
|
|
90
90
|
}
|
package/src/weak.ts
CHANGED
|
@@ -96,7 +96,7 @@ export class WeakDictionary<K, V extends object> implements Map<K, V> {
|
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
private _register(key: K, value: V) {
|
|
99
|
+
private _register(key: K, value: V): void {
|
|
100
100
|
this._finalization.register(
|
|
101
101
|
value,
|
|
102
102
|
() => {
|
|
@@ -106,7 +106,7 @@ export class WeakDictionary<K, V extends object> implements Map<K, V> {
|
|
|
106
106
|
);
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
private _unregister(value: V) {
|
|
109
|
+
private _unregister(value: V): void {
|
|
110
110
|
this._finalization.unregister(value);
|
|
111
111
|
}
|
|
112
112
|
}
|