@configura/web-utilities 2.1.0-alpha.0 → 2.1.0-alpha.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.
- package/.eslintrc.json +5 -5
- package/.gitattributes +3 -3
- package/LICENSE +201 -201
- package/README.md +1 -1
- package/__tests__/cmMips.test.ts +129 -129
- package/__tests__/convertLength.test.ts +37 -37
- package/__tests__/price.test.ts +21 -21
- package/dist/GenericCache.d.ts +14 -14
- package/dist/GenericCache.js +38 -38
- package/dist/Observable/AccumulatingObservable.d.ts +10 -10
- package/dist/Observable/AccumulatingObservable.js +25 -25
- package/dist/Observable/AggregatedLoadingObservable.d.ts +10 -10
- package/dist/Observable/AggregatedLoadingObservable.js +28 -28
- package/dist/Observable/LogObservable.d.ts +42 -42
- package/dist/Observable/LogObservable.js +104 -104
- package/dist/Observable/LogProducer.d.ts +5 -5
- package/dist/Observable/LogProducer.js +9 -9
- package/dist/Observable/Observable.d.ts +12 -12
- package/dist/Observable/Observable.js +33 -33
- package/dist/PromiseCache.d.ts +4 -4
- package/dist/PromiseCache.js +28 -28
- package/dist/assert.d.ts +12 -12
- package/dist/assert.js +20 -20
- package/dist/cmMips.d.ts +26 -26
- package/dist/cmMips.js +159 -159
- package/dist/compare.d.ts +6 -6
- package/dist/compare.js +29 -29
- package/dist/error.d.ts +7 -7
- package/dist/error.js +24 -24
- package/dist/event.d.ts +2 -2
- package/dist/event.js +1 -1
- package/dist/filter.d.ts +22 -22
- package/dist/filter.js +19 -19
- package/dist/index.d.ts +21 -21
- package/dist/index.js +21 -21
- package/dist/utilitiesArray.d.ts +4 -4
- package/dist/utilitiesArray.js +49 -49
- package/dist/utilitiesFile.d.ts +6 -6
- package/dist/utilitiesFile.js +33 -33
- package/dist/utilitiesImage.d.ts +1 -1
- package/dist/utilitiesImage.js +19 -19
- package/dist/utilitiesMath.d.ts +3 -3
- package/dist/utilitiesMath.js +9 -9
- package/dist/utilitiesPrice.d.ts +1 -1
- package/dist/utilitiesPrice.js +16 -16
- package/dist/utilitiesPromise.d.ts +1 -1
- package/dist/utilitiesPromise.js +12 -12
- package/dist/utilitiesString.d.ts +1 -1
- package/dist/utilitiesString.js +12 -12
- package/dist/utilitiesUnits.d.ts +16 -16
- package/dist/utilitiesUnits.js +72 -72
- package/dist/utilitiesWeb.d.ts +3 -3
- package/dist/utilitiesWeb.js +20 -20
- package/package.json +2 -2
package/__tests__/cmMips.test.ts
CHANGED
|
@@ -1,129 +1,129 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jest-environment node
|
|
3
|
-
*
|
|
4
|
-
* We need to use Node.js since the default "jsdom" environment results in a
|
|
5
|
-
* "ReferenceError: TextDecoder is not defined" error.
|
|
6
|
-
**/
|
|
7
|
-
|
|
8
|
-
import { readFileSync } from "fs";
|
|
9
|
-
import { CmMip, extractCmMips } from "../dist/cmMips.js";
|
|
10
|
-
import { LogObservable } from "../dist/Observable/LogObservable.js";
|
|
11
|
-
|
|
12
|
-
const logger = new LogObservable();
|
|
13
|
-
|
|
14
|
-
let onlyInternal: Uint8Array | undefined = undefined;
|
|
15
|
-
let partlyExternal: Uint8Array | undefined = undefined;
|
|
16
|
-
|
|
17
|
-
const emptyCmMips = new Uint8Array([
|
|
18
|
-
0x77, // magic
|
|
19
|
-
0xee,
|
|
20
|
-
1, // version
|
|
21
|
-
0,
|
|
22
|
-
0,
|
|
23
|
-
0,
|
|
24
|
-
1, // suffix length
|
|
25
|
-
65, // suffix string ("A")
|
|
26
|
-
3, // format length
|
|
27
|
-
82, // format string ("RGB")
|
|
28
|
-
71,
|
|
29
|
-
66,
|
|
30
|
-
1, // averageR
|
|
31
|
-
2, // averageG
|
|
32
|
-
3, // averageB
|
|
33
|
-
4, // minWidth
|
|
34
|
-
0,
|
|
35
|
-
0,
|
|
36
|
-
0,
|
|
37
|
-
5, // minHeight
|
|
38
|
-
0,
|
|
39
|
-
0,
|
|
40
|
-
0,
|
|
41
|
-
0, // mipLevels
|
|
42
|
-
0,
|
|
43
|
-
0,
|
|
44
|
-
0,
|
|
45
|
-
]);
|
|
46
|
-
|
|
47
|
-
beforeAll(() => {
|
|
48
|
-
onlyInternal = new Uint8Array(
|
|
49
|
-
readFileSync("./packages/web-utilities/__tests__/images/onlyInternal.cmmips")
|
|
50
|
-
);
|
|
51
|
-
partlyExternal = new Uint8Array(
|
|
52
|
-
readFileSync("./packages/web-utilities/__tests__/images/partlyExternal.cmmips")
|
|
53
|
-
);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
afterAll(() => {
|
|
57
|
-
onlyInternal = undefined;
|
|
58
|
-
partlyExternal = undefined;
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
function checkBasics(mip: CmMip) {
|
|
62
|
-
expect(mip).toBeDefined();
|
|
63
|
-
expect(mip.name).toBeTruthy();
|
|
64
|
-
expect(mip.suffix).toBeTruthy();
|
|
65
|
-
expect(mip.width).toBeGreaterThan(0);
|
|
66
|
-
expect(mip.height).toBeGreaterThan(0);
|
|
67
|
-
expect(mip.data?.length).toBeGreaterThan(0);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
test("Default Mip from CmMips file with only internal images", () => {
|
|
71
|
-
checkBasics(extractCmMips(onlyInternal, logger));
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test("Default Mip from CmMips file with some external images", () => {
|
|
75
|
-
checkBasics(extractCmMips(partlyExternal, logger));
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test("Requesting exact Mip size", () => {
|
|
79
|
-
const mip = extractCmMips(onlyInternal, logger, 16);
|
|
80
|
-
checkBasics(mip);
|
|
81
|
-
expect(mip.width).toEqual(16);
|
|
82
|
-
expect(mip.height).toEqual(16);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test("Requesting closest smaller Mip size", () => {
|
|
86
|
-
const mip = extractCmMips(onlyInternal, logger, 15);
|
|
87
|
-
checkBasics(mip);
|
|
88
|
-
expect(mip.width).toEqual(8);
|
|
89
|
-
expect(mip.height).toEqual(8);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test("Requesting impossible Mip size", () => {
|
|
93
|
-
// We should always get a Mip back, if there are any internal at all in the file.
|
|
94
|
-
const mip = extractCmMips(onlyInternal, logger, 0);
|
|
95
|
-
checkBasics(mip);
|
|
96
|
-
expect(mip.width).toEqual(1);
|
|
97
|
-
expect(mip.height).toEqual(1);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test("Undefined array", () => {
|
|
101
|
-
expect(extractCmMips(undefined, logger, 0)).toBeUndefined();
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
test("Wrong magic", () => {
|
|
105
|
-
expect(extractCmMips(new Uint8Array([0x39, 0x30, 0, 0, 0, 0]), logger)).toBeUndefined();
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
test("Only header", () => {
|
|
109
|
-
expect(extractCmMips(emptyCmMips, logger)).toBeUndefined();
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
test("Truncated data", () => {
|
|
113
|
-
// Slice and Subarray will give internal buffers of different sizes.
|
|
114
|
-
// Slice is safest and can therefor be considered the reference if the tests differ.
|
|
115
|
-
const mip = extractCmMips(onlyInternal.subarray(0, 15), logger);
|
|
116
|
-
expect(mip).toBeUndefined();
|
|
117
|
-
expect(extractCmMips(onlyInternal.slice(0, 15), logger)).toEqual(mip);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
test("Subarray with non-zero offset", () => {
|
|
121
|
-
// Slice and Subarray will give internal buffers of different sizes and offsets.
|
|
122
|
-
// Slice is safest and can therefor be considered the reference if the tests differ.
|
|
123
|
-
const array = new Uint8Array(onlyInternal.length + 1);
|
|
124
|
-
array.set(onlyInternal, 1);
|
|
125
|
-
array[0] = 42;
|
|
126
|
-
const mip = extractCmMips(array.subarray(1, array.length), logger);
|
|
127
|
-
checkBasics(mip);
|
|
128
|
-
expect(extractCmMips(array.slice(1, array.length), logger)).toEqual(mip);
|
|
129
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment node
|
|
3
|
+
*
|
|
4
|
+
* We need to use Node.js since the default "jsdom" environment results in a
|
|
5
|
+
* "ReferenceError: TextDecoder is not defined" error.
|
|
6
|
+
**/
|
|
7
|
+
|
|
8
|
+
import { readFileSync } from "fs";
|
|
9
|
+
import { CmMip, extractCmMips } from "../dist/cmMips.js";
|
|
10
|
+
import { LogObservable } from "../dist/Observable/LogObservable.js";
|
|
11
|
+
|
|
12
|
+
const logger = new LogObservable();
|
|
13
|
+
|
|
14
|
+
let onlyInternal: Uint8Array | undefined = undefined;
|
|
15
|
+
let partlyExternal: Uint8Array | undefined = undefined;
|
|
16
|
+
|
|
17
|
+
const emptyCmMips = new Uint8Array([
|
|
18
|
+
0x77, // magic
|
|
19
|
+
0xee,
|
|
20
|
+
1, // version
|
|
21
|
+
0,
|
|
22
|
+
0,
|
|
23
|
+
0,
|
|
24
|
+
1, // suffix length
|
|
25
|
+
65, // suffix string ("A")
|
|
26
|
+
3, // format length
|
|
27
|
+
82, // format string ("RGB")
|
|
28
|
+
71,
|
|
29
|
+
66,
|
|
30
|
+
1, // averageR
|
|
31
|
+
2, // averageG
|
|
32
|
+
3, // averageB
|
|
33
|
+
4, // minWidth
|
|
34
|
+
0,
|
|
35
|
+
0,
|
|
36
|
+
0,
|
|
37
|
+
5, // minHeight
|
|
38
|
+
0,
|
|
39
|
+
0,
|
|
40
|
+
0,
|
|
41
|
+
0, // mipLevels
|
|
42
|
+
0,
|
|
43
|
+
0,
|
|
44
|
+
0,
|
|
45
|
+
]);
|
|
46
|
+
|
|
47
|
+
beforeAll(() => {
|
|
48
|
+
onlyInternal = new Uint8Array(
|
|
49
|
+
readFileSync("./packages/web-utilities/__tests__/images/onlyInternal.cmmips")
|
|
50
|
+
);
|
|
51
|
+
partlyExternal = new Uint8Array(
|
|
52
|
+
readFileSync("./packages/web-utilities/__tests__/images/partlyExternal.cmmips")
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
afterAll(() => {
|
|
57
|
+
onlyInternal = undefined;
|
|
58
|
+
partlyExternal = undefined;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
function checkBasics(mip: CmMip) {
|
|
62
|
+
expect(mip).toBeDefined();
|
|
63
|
+
expect(mip.name).toBeTruthy();
|
|
64
|
+
expect(mip.suffix).toBeTruthy();
|
|
65
|
+
expect(mip.width).toBeGreaterThan(0);
|
|
66
|
+
expect(mip.height).toBeGreaterThan(0);
|
|
67
|
+
expect(mip.data?.length).toBeGreaterThan(0);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
test("Default Mip from CmMips file with only internal images", () => {
|
|
71
|
+
checkBasics(extractCmMips(onlyInternal, logger));
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("Default Mip from CmMips file with some external images", () => {
|
|
75
|
+
checkBasics(extractCmMips(partlyExternal, logger));
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("Requesting exact Mip size", () => {
|
|
79
|
+
const mip = extractCmMips(onlyInternal, logger, 16);
|
|
80
|
+
checkBasics(mip);
|
|
81
|
+
expect(mip.width).toEqual(16);
|
|
82
|
+
expect(mip.height).toEqual(16);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("Requesting closest smaller Mip size", () => {
|
|
86
|
+
const mip = extractCmMips(onlyInternal, logger, 15);
|
|
87
|
+
checkBasics(mip);
|
|
88
|
+
expect(mip.width).toEqual(8);
|
|
89
|
+
expect(mip.height).toEqual(8);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("Requesting impossible Mip size", () => {
|
|
93
|
+
// We should always get a Mip back, if there are any internal at all in the file.
|
|
94
|
+
const mip = extractCmMips(onlyInternal, logger, 0);
|
|
95
|
+
checkBasics(mip);
|
|
96
|
+
expect(mip.width).toEqual(1);
|
|
97
|
+
expect(mip.height).toEqual(1);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("Undefined array", () => {
|
|
101
|
+
expect(extractCmMips(undefined, logger, 0)).toBeUndefined();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("Wrong magic", () => {
|
|
105
|
+
expect(extractCmMips(new Uint8Array([0x39, 0x30, 0, 0, 0, 0]), logger)).toBeUndefined();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("Only header", () => {
|
|
109
|
+
expect(extractCmMips(emptyCmMips, logger)).toBeUndefined();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("Truncated data", () => {
|
|
113
|
+
// Slice and Subarray will give internal buffers of different sizes.
|
|
114
|
+
// Slice is safest and can therefor be considered the reference if the tests differ.
|
|
115
|
+
const mip = extractCmMips(onlyInternal.subarray(0, 15), logger);
|
|
116
|
+
expect(mip).toBeUndefined();
|
|
117
|
+
expect(extractCmMips(onlyInternal.slice(0, 15), logger)).toEqual(mip);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("Subarray with non-zero offset", () => {
|
|
121
|
+
// Slice and Subarray will give internal buffers of different sizes and offsets.
|
|
122
|
+
// Slice is safest and can therefor be considered the reference if the tests differ.
|
|
123
|
+
const array = new Uint8Array(onlyInternal.length + 1);
|
|
124
|
+
array.set(onlyInternal, 1);
|
|
125
|
+
array[0] = 42;
|
|
126
|
+
const mip = extractCmMips(array.subarray(1, array.length), logger);
|
|
127
|
+
checkBasics(mip);
|
|
128
|
+
expect(extractCmMips(array.slice(1, array.length), logger)).toEqual(mip);
|
|
129
|
+
});
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import { convertLength, toLengthUnit } from "../dist/utilitiesUnits";
|
|
2
|
-
|
|
3
|
-
test("to m", () => {
|
|
4
|
-
expect(toLengthUnit("M")).toBe("m");
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
test("to in", () => {
|
|
8
|
-
expect(toLengthUnit("Inch")).toBe("in");
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
test("ft to ft", () => {
|
|
12
|
-
expect(convertLength(2, "ft", "ft")).toBe(2);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
test("cm to m", () => {
|
|
16
|
-
expect(convertLength(2, "cm", "m")).toBe(0.02);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test("dm to mm", () => {
|
|
20
|
-
expect(convertLength(12.34, "dm", "mm")).toBe(1234);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test("ft to mm", () => {
|
|
24
|
-
expect(convertLength(12.34, "ft", "mm")).toBeCloseTo(3761.232, 3);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test("cm to inch", () => {
|
|
28
|
-
expect(convertLength(5, "cm", "in")).toBeCloseTo(1.96850394, 3);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test("feet to inch", () => {
|
|
32
|
-
expect(convertLength(1, "ft", "in")).toBe(12);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test("inch to feet", () => {
|
|
36
|
-
expect(convertLength(12, "in", "ft")).toBe(1);
|
|
37
|
-
});
|
|
1
|
+
import { convertLength, toLengthUnit } from "../dist/utilitiesUnits";
|
|
2
|
+
|
|
3
|
+
test("to m", () => {
|
|
4
|
+
expect(toLengthUnit("M")).toBe("m");
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
test("to in", () => {
|
|
8
|
+
expect(toLengthUnit("Inch")).toBe("in");
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test("ft to ft", () => {
|
|
12
|
+
expect(convertLength(2, "ft", "ft")).toBe(2);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test("cm to m", () => {
|
|
16
|
+
expect(convertLength(2, "cm", "m")).toBe(0.02);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("dm to mm", () => {
|
|
20
|
+
expect(convertLength(12.34, "dm", "mm")).toBe(1234);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("ft to mm", () => {
|
|
24
|
+
expect(convertLength(12.34, "ft", "mm")).toBeCloseTo(3761.232, 3);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("cm to inch", () => {
|
|
28
|
+
expect(convertLength(5, "cm", "in")).toBeCloseTo(1.96850394, 3);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("feet to inch", () => {
|
|
32
|
+
expect(convertLength(1, "ft", "in")).toBe(12);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("inch to feet", () => {
|
|
36
|
+
expect(convertLength(12, "in", "ft")).toBe(1);
|
|
37
|
+
});
|
package/__tests__/price.test.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { formatPrice } from "../src/utilitiesPrice";
|
|
2
|
-
|
|
3
|
-
const price = 123456.789012;
|
|
4
|
-
const lang = "en-US";
|
|
5
|
-
const currency = "SEK";
|
|
6
|
-
|
|
7
|
-
test("price rounding 0", () => {
|
|
8
|
-
expect(formatPrice(price, 0, lang, currency)).toBe("SEK\u00A0123,457");
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
test("price rounding 2", () => {
|
|
12
|
-
expect(formatPrice(price, 2, lang, currency)).toBe("SEK\u00A0123,456.79");
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
test("price rounding -1", () => {
|
|
16
|
-
expect(formatPrice(price, -1, lang, currency)).toBe("SEK\u00A0123,460");
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test("price rounding -2", () => {
|
|
20
|
-
expect(formatPrice(price, -2, lang, currency)).toBe("SEK\u00A0123,500");
|
|
21
|
-
});
|
|
1
|
+
import { formatPrice } from "../src/utilitiesPrice";
|
|
2
|
+
|
|
3
|
+
const price = 123456.789012;
|
|
4
|
+
const lang = "en-US";
|
|
5
|
+
const currency = "SEK";
|
|
6
|
+
|
|
7
|
+
test("price rounding 0", () => {
|
|
8
|
+
expect(formatPrice(price, 0, lang, currency)).toBe("SEK\u00A0123,457");
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test("price rounding 2", () => {
|
|
12
|
+
expect(formatPrice(price, 2, lang, currency)).toBe("SEK\u00A0123,456.79");
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test("price rounding -1", () => {
|
|
16
|
+
expect(formatPrice(price, -1, lang, currency)).toBe("SEK\u00A0123,460");
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("price rounding -2", () => {
|
|
20
|
+
expect(formatPrice(price, -2, lang, currency)).toBe("SEK\u00A0123,500");
|
|
21
|
+
});
|
package/dist/GenericCache.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export declare class GenericCache<Key, Item> {
|
|
2
|
-
private _keyLookupFunction?;
|
|
3
|
-
/** @remarks Using a keyLoopupFunction makes the cache much much slower! */
|
|
4
|
-
constructor(_keyLookupFunction?: ((key1: Key, key2: Key) => boolean) | undefined);
|
|
5
|
-
_cache: Map<Key, Item>;
|
|
6
|
-
get(key: Key, createMissing: () => Item): Item;
|
|
7
|
-
delete: (key: Key) => boolean;
|
|
8
|
-
clear: () => void;
|
|
9
|
-
/**
|
|
10
|
-
* This might seem unnecessary, but for non-primitive datatypes equality is compared on
|
|
11
|
-
* reference, not value, so finding the right key is a thing that must be done.
|
|
12
|
-
*/
|
|
13
|
-
findExistingKeyOrReturnInput(key: Key, keyLookupFunction: (key1: Key, key2: Key) => boolean): Key;
|
|
14
|
-
}
|
|
1
|
+
export declare class GenericCache<Key, Item> {
|
|
2
|
+
private _keyLookupFunction?;
|
|
3
|
+
/** @remarks Using a keyLoopupFunction makes the cache much much slower! */
|
|
4
|
+
constructor(_keyLookupFunction?: ((key1: Key, key2: Key) => boolean) | undefined);
|
|
5
|
+
_cache: Map<Key, Item>;
|
|
6
|
+
get(key: Key, createMissing: () => Item): Item;
|
|
7
|
+
delete: (key: Key) => boolean;
|
|
8
|
+
clear: () => void;
|
|
9
|
+
/**
|
|
10
|
+
* This might seem unnecessary, but for non-primitive datatypes equality is compared on
|
|
11
|
+
* reference, not value, so finding the right key is a thing that must be done.
|
|
12
|
+
*/
|
|
13
|
+
findExistingKeyOrReturnInput(key: Key, keyLookupFunction: (key1: Key, key2: Key) => boolean): Key;
|
|
14
|
+
}
|
|
15
15
|
//# sourceMappingURL=GenericCache.d.ts.map
|
package/dist/GenericCache.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
export class GenericCache {
|
|
2
|
-
/** @remarks Using a keyLoopupFunction makes the cache much much slower! */
|
|
3
|
-
constructor(_keyLookupFunction) {
|
|
4
|
-
this._keyLookupFunction = _keyLookupFunction;
|
|
5
|
-
this._cache = new Map();
|
|
6
|
-
this.delete = (key) => {
|
|
7
|
-
return this._cache.delete(key);
|
|
8
|
-
};
|
|
9
|
-
this.clear = () => {
|
|
10
|
-
this._cache.clear();
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
get(key, createMissing) {
|
|
14
|
-
key =
|
|
15
|
-
this._keyLookupFunction === undefined
|
|
16
|
-
? key
|
|
17
|
-
: this.findExistingKeyOrReturnInput(key, this._keyLookupFunction);
|
|
18
|
-
let item = this._cache.get(key);
|
|
19
|
-
if (item !== undefined) {
|
|
20
|
-
return item;
|
|
21
|
-
}
|
|
22
|
-
item = createMissing();
|
|
23
|
-
this._cache.set(key, item);
|
|
24
|
-
return item;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* This might seem unnecessary, but for non-primitive datatypes equality is compared on
|
|
28
|
-
* reference, not value, so finding the right key is a thing that must be done.
|
|
29
|
-
*/
|
|
30
|
-
findExistingKeyOrReturnInput(key, keyLookupFunction) {
|
|
31
|
-
for (const otherKey of this._cache.keys()) {
|
|
32
|
-
if (keyLookupFunction(key, otherKey)) {
|
|
33
|
-
return otherKey;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return key;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
1
|
+
export class GenericCache {
|
|
2
|
+
/** @remarks Using a keyLoopupFunction makes the cache much much slower! */
|
|
3
|
+
constructor(_keyLookupFunction) {
|
|
4
|
+
this._keyLookupFunction = _keyLookupFunction;
|
|
5
|
+
this._cache = new Map();
|
|
6
|
+
this.delete = (key) => {
|
|
7
|
+
return this._cache.delete(key);
|
|
8
|
+
};
|
|
9
|
+
this.clear = () => {
|
|
10
|
+
this._cache.clear();
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
get(key, createMissing) {
|
|
14
|
+
key =
|
|
15
|
+
this._keyLookupFunction === undefined
|
|
16
|
+
? key
|
|
17
|
+
: this.findExistingKeyOrReturnInput(key, this._keyLookupFunction);
|
|
18
|
+
let item = this._cache.get(key);
|
|
19
|
+
if (item !== undefined) {
|
|
20
|
+
return item;
|
|
21
|
+
}
|
|
22
|
+
item = createMissing();
|
|
23
|
+
this._cache.set(key, item);
|
|
24
|
+
return item;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* This might seem unnecessary, but for non-primitive datatypes equality is compared on
|
|
28
|
+
* reference, not value, so finding the right key is a thing that must be done.
|
|
29
|
+
*/
|
|
30
|
+
findExistingKeyOrReturnInput(key, keyLookupFunction) {
|
|
31
|
+
for (const otherKey of this._cache.keys()) {
|
|
32
|
+
if (keyLookupFunction(key, otherKey)) {
|
|
33
|
+
return otherKey;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return key;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Observable } from "./Observable.js";
|
|
2
|
-
export declare class AccumulatingObservable<T> extends Observable<T> {
|
|
3
|
-
constructor();
|
|
4
|
-
private _accumulated;
|
|
5
|
-
get accumulated(): T[];
|
|
6
|
-
private accumulatedObservable;
|
|
7
|
-
listenForAccumulated: (listener: (v: T[]) => void) => void;
|
|
8
|
-
stopListenForAccumulated: (listener: (v: T[]) => void) => void;
|
|
9
|
-
clear: () => void;
|
|
10
|
-
}
|
|
1
|
+
import { Observable } from "./Observable.js";
|
|
2
|
+
export declare class AccumulatingObservable<T> extends Observable<T> {
|
|
3
|
+
constructor();
|
|
4
|
+
private _accumulated;
|
|
5
|
+
get accumulated(): T[];
|
|
6
|
+
private accumulatedObservable;
|
|
7
|
+
listenForAccumulated: (listener: (v: T[]) => void) => void;
|
|
8
|
+
stopListenForAccumulated: (listener: (v: T[]) => void) => void;
|
|
9
|
+
clear: () => void;
|
|
10
|
+
}
|
|
11
11
|
//# sourceMappingURL=AccumulatingObservable.d.ts.map
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { Observable } from "./Observable.js";
|
|
2
|
-
export class AccumulatingObservable extends Observable {
|
|
3
|
-
constructor() {
|
|
4
|
-
super();
|
|
5
|
-
this._accumulated = [];
|
|
6
|
-
this.accumulatedObservable = new Observable();
|
|
7
|
-
this.listenForAccumulated = (listener) => {
|
|
8
|
-
this.accumulatedObservable.listen(listener);
|
|
9
|
-
listener(this._accumulated);
|
|
10
|
-
};
|
|
11
|
-
this.stopListenForAccumulated = (listener) => {
|
|
12
|
-
this.accumulatedObservable.stopListen(listener);
|
|
13
|
-
};
|
|
14
|
-
this.clear = () => {
|
|
15
|
-
this._accumulated.length = 0;
|
|
16
|
-
};
|
|
17
|
-
this.listen((m) => {
|
|
18
|
-
this._accumulated.push(m);
|
|
19
|
-
this.accumulatedObservable.notifyAll(this.accumulated);
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
get accumulated() {
|
|
23
|
-
return this._accumulated;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
1
|
+
import { Observable } from "./Observable.js";
|
|
2
|
+
export class AccumulatingObservable extends Observable {
|
|
3
|
+
constructor() {
|
|
4
|
+
super();
|
|
5
|
+
this._accumulated = [];
|
|
6
|
+
this.accumulatedObservable = new Observable();
|
|
7
|
+
this.listenForAccumulated = (listener) => {
|
|
8
|
+
this.accumulatedObservable.listen(listener);
|
|
9
|
+
listener(this._accumulated);
|
|
10
|
+
};
|
|
11
|
+
this.stopListenForAccumulated = (listener) => {
|
|
12
|
+
this.accumulatedObservable.stopListen(listener);
|
|
13
|
+
};
|
|
14
|
+
this.clear = () => {
|
|
15
|
+
this._accumulated.length = 0;
|
|
16
|
+
};
|
|
17
|
+
this.listen((m) => {
|
|
18
|
+
this._accumulated.push(m);
|
|
19
|
+
this.accumulatedObservable.notifyAll(this.accumulated);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
get accumulated() {
|
|
23
|
+
return this._accumulated;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Observable } from "./Observable.js";
|
|
2
|
-
declare type LoadingToken = unknown;
|
|
3
|
-
export declare class AggregatedLoadingObservable extends Observable<boolean> {
|
|
4
|
-
private currentlyLoadingTokens;
|
|
5
|
-
startChildLoading: (token?: LoadingToken) => LoadingToken;
|
|
6
|
-
stopChildLoading: (token: LoadingToken) => void;
|
|
7
|
-
startStopChildLoading: (token: LoadingToken, on: boolean) => void;
|
|
8
|
-
private doNotifyAll;
|
|
9
|
-
}
|
|
10
|
-
export {};
|
|
1
|
+
import { Observable } from "./Observable.js";
|
|
2
|
+
declare type LoadingToken = unknown;
|
|
3
|
+
export declare class AggregatedLoadingObservable extends Observable<boolean> {
|
|
4
|
+
private currentlyLoadingTokens;
|
|
5
|
+
startChildLoading: (token?: LoadingToken) => LoadingToken;
|
|
6
|
+
stopChildLoading: (token: LoadingToken) => void;
|
|
7
|
+
startStopChildLoading: (token: LoadingToken, on: boolean) => void;
|
|
8
|
+
private doNotifyAll;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
11
11
|
//# sourceMappingURL=AggregatedLoadingObservable.d.ts.map
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { Observable } from "./Observable.js";
|
|
2
|
-
export class AggregatedLoadingObservable extends Observable {
|
|
3
|
-
constructor() {
|
|
4
|
-
super(...arguments);
|
|
5
|
-
this.currentlyLoadingTokens = new Set();
|
|
6
|
-
this.startChildLoading = (token) => {
|
|
7
|
-
if (token === undefined) {
|
|
8
|
-
token = {};
|
|
9
|
-
}
|
|
10
|
-
this.currentlyLoadingTokens.add(token);
|
|
11
|
-
this.doNotifyAll();
|
|
12
|
-
return token;
|
|
13
|
-
};
|
|
14
|
-
this.stopChildLoading = (token) => {
|
|
15
|
-
this.currentlyLoadingTokens.delete(token);
|
|
16
|
-
this.doNotifyAll();
|
|
17
|
-
};
|
|
18
|
-
this.startStopChildLoading = (token, on) => {
|
|
19
|
-
if (on) {
|
|
20
|
-
this.startChildLoading(token);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
this.stopChildLoading(token);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
this.doNotifyAll = () => this.notifyAll(0 < this.currentlyLoadingTokens.size);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
1
|
+
import { Observable } from "./Observable.js";
|
|
2
|
+
export class AggregatedLoadingObservable extends Observable {
|
|
3
|
+
constructor() {
|
|
4
|
+
super(...arguments);
|
|
5
|
+
this.currentlyLoadingTokens = new Set();
|
|
6
|
+
this.startChildLoading = (token) => {
|
|
7
|
+
if (token === undefined) {
|
|
8
|
+
token = {};
|
|
9
|
+
}
|
|
10
|
+
this.currentlyLoadingTokens.add(token);
|
|
11
|
+
this.doNotifyAll();
|
|
12
|
+
return token;
|
|
13
|
+
};
|
|
14
|
+
this.stopChildLoading = (token) => {
|
|
15
|
+
this.currentlyLoadingTokens.delete(token);
|
|
16
|
+
this.doNotifyAll();
|
|
17
|
+
};
|
|
18
|
+
this.startStopChildLoading = (token, on) => {
|
|
19
|
+
if (on) {
|
|
20
|
+
this.startChildLoading(token);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
this.stopChildLoading(token);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
this.doNotifyAll = () => this.notifyAll(0 < this.currentlyLoadingTokens.size);
|
|
27
|
+
}
|
|
28
|
+
}
|