@claspo/common 7.3.1-dev.4 → 7.4.0-nonlinear
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/{out/document → document}/Document.interface.d.ts +2 -0
- package/document/ViewNavigationGraph.d.ts +42 -0
- package/document/ViewNavigationGraph.js +1 -0
- package/package.json +2 -2
- package/velocity/SysVelocityRenderer.js +1 -0
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sorter.js +0 -196
- package/jest.config.ts +0 -204
- package/out/package.json +0 -50
- package/out/velocity/SysVelocityRenderer.js +0 -1
- package/src/DefaultEventEmitter.test.ts +0 -84
- package/src/DefaultEventEmitter.ts +0 -96
- package/src/HttpAbortableLoader.ts +0 -35
- package/src/InAppLayoutType.ts +0 -6
- package/src/LayoutType.ts +0 -18
- package/src/PrizePool.interface.ts +0 -32
- package/src/RenderMode.ts +0 -10
- package/src/UuidGenerator.ts +0 -16
- package/src/WidgetInitConfig.interface.ts +0 -163
- package/src/WidgetType.ts +0 -18
- package/src/action/type.ts +0 -7
- package/src/async/createAsyncIterator.ts +0 -33
- package/src/async/debounce.ts +0 -28
- package/src/async/timeout.ts +0 -3
- package/src/component-manifest/ComponentManifest.interface.ts +0 -160
- package/src/component-manifest/ContextMenuManifest.interface.ts +0 -52
- package/src/component-manifest/DisplayCondition.interface.ts +0 -65
- package/src/component-manifest/FloatingControlManifest.interface.ts +0 -89
- package/src/component-manifest/PropPathCondition.interface.ts +0 -4
- package/src/component-manifest/PropertyPaneManifest.interface.ts +0 -614
- package/src/converter/time/TimeConverter.spec.ts +0 -11
- package/src/converter/time/TimeUnit.spec.ts +0 -12
- package/src/converter/time/TimeUnit.ts +0 -34
- package/src/converter/time/TimerConverter.ts +0 -29
- package/src/document/ComponentInsertType.ts +0 -6
- package/src/document/Document.interface.ts +0 -625
- package/src/document/DocumentCssVarsReplace.test.ts +0 -2947
- package/src/document/DocumentCssVarsReplace.ts +0 -31
- package/src/document/DocumentUtils.test.ts +0 -595
- package/src/document/DocumentUtils.ts +0 -194
- package/src/document/hidden-fields.interface.ts +0 -54
- package/src/dom/ViewportSize.ts +0 -61
- package/src/dom/copyToClipboard.ts +0 -17
- package/src/dom/getMostNestedNode.ts +0 -9
- package/src/dom/insertHtmlIntoElement.ts +0 -36
- package/src/dom/sanitizeHTML.test.ts +0 -59
- package/src/dom/sanitizeHTML.ts +0 -78
- package/src/element/BaseElementInViewportHandler.ts +0 -41
- package/src/element/CssVarsOperations.ts +0 -37
- package/src/element/ThemeCssVars.ts +0 -28
- package/src/element/recursiveFindParentNodeByAttribute.test.ts +0 -63
- package/src/element/recursiveFindParentNodeByAttribute.ts +0 -25
- package/src/flat.ts +0 -16
- package/src/handler/HandlerTypes.ts +0 -4
- package/src/math/RandomDistributor.test.ts +0 -35
- package/src/math/RandomDistributor.ts +0 -58
- package/src/math/sum.ts +0 -3
- package/src/network/HttpClient.ts +0 -28
- package/src/network/HttpStatus.ts +0 -4
- package/src/object/isDictionary.test.ts +0 -24
- package/src/object/isDictionary.ts +0 -13
- package/src/object/omitKeys.test.ts +0 -19
- package/src/object/omitKeys.ts +0 -20
- package/src/storage/BaseCachingStorage.test.ts +0 -70
- package/src/storage/BaseCachingStorage.ts +0 -37
- package/src/storage/CachingCookieStorage.test.ts +0 -75
- package/src/storage/CachingCookieStorage.ts +0 -36
- package/src/storage/CachingLocalStorage.test.ts +0 -59
- package/src/storage/CachingLocalStorage.ts +0 -34
- package/src/storage/getCookie.test.ts +0 -53
- package/src/storage/getCookie.ts +0 -10
- package/src/storage/setCookie.test.ts +0 -97
- package/src/storage/setCookie.ts +0 -49
- package/src/theme/theme.utils.ts +0 -50
- package/src/url/sanitizeUrl.test.ts +0 -62
- package/src/url/sanitizeUrl.ts +0 -51
- package/src/utils/CaseTransformer.test.ts +0 -16
- package/src/utils/CaseTransformer.ts +0 -10
- package/src/utils/NullishCoalescingOperator.ts +0 -3
- package/src/utils/NumericDecline.ts +0 -25
- package/src/utils/addEventListener.ts +0 -23
- package/src/utils/allSettled.ts +0 -6
- package/src/utils/checkTimeZone.spec.ts +0 -18
- package/src/utils/checkTimeZone.ts +0 -6
- package/src/utils/deviceUtils.ts +0 -12
- package/src/utils/flatMap.test.ts +0 -21
- package/src/utils/flatMap.ts +0 -3
- package/src/utils/fromEntries.ts +0 -6
- package/src/utils/generateRandomNumber.test.ts +0 -23
- package/src/utils/generateRandomNumber.ts +0 -3
- package/src/utils/objectSort.ts +0 -41
- package/src/utils/orientationUtils.ts +0 -18
- package/src/velocity/SysVelocityContext.spec.ts +0 -88
- package/src/velocity/SysVelocityContext.ts +0 -129
- package/src/velocity/SysVelocityRenderer.spec.ts +0 -36
- package/src/velocity/SysVelocityRenderer.ts +0 -11
- package/test/__mocks/jestGlobalMocks.js +0 -1887
- /package/{out/DefaultEventEmitter.d.ts → DefaultEventEmitter.d.ts} +0 -0
- /package/{out/DefaultEventEmitter.js → DefaultEventEmitter.js} +0 -0
- /package/{out/HttpAbortableLoader.d.ts → HttpAbortableLoader.d.ts} +0 -0
- /package/{out/HttpAbortableLoader.js → HttpAbortableLoader.js} +0 -0
- /package/{out/InAppLayoutType.d.ts → InAppLayoutType.d.ts} +0 -0
- /package/{out/InAppLayoutType.js → InAppLayoutType.js} +0 -0
- /package/{out/LayoutType.d.ts → LayoutType.d.ts} +0 -0
- /package/{out/LayoutType.js → LayoutType.js} +0 -0
- /package/{out/PrizePool.interface.d.ts → PrizePool.interface.d.ts} +0 -0
- /package/{out/PrizePool.interface.js → PrizePool.interface.js} +0 -0
- /package/{out/RenderMode.d.ts → RenderMode.d.ts} +0 -0
- /package/{out/RenderMode.js → RenderMode.js} +0 -0
- /package/{out/UuidGenerator.d.ts → UuidGenerator.d.ts} +0 -0
- /package/{out/UuidGenerator.js → UuidGenerator.js} +0 -0
- /package/{out/WidgetInitConfig.interface.d.ts → WidgetInitConfig.interface.d.ts} +0 -0
- /package/{out/WidgetInitConfig.interface.js → WidgetInitConfig.interface.js} +0 -0
- /package/{out/WidgetType.d.ts → WidgetType.d.ts} +0 -0
- /package/{out/WidgetType.js → WidgetType.js} +0 -0
- /package/{out/action → action}/type.d.ts +0 -0
- /package/{out/action → action}/type.js +0 -0
- /package/{out/async → async}/createAsyncIterator.d.ts +0 -0
- /package/{out/async → async}/createAsyncIterator.js +0 -0
- /package/{out/async → async}/debounce.d.ts +0 -0
- /package/{out/async → async}/debounce.js +0 -0
- /package/{out/async → async}/timeout.d.ts +0 -0
- /package/{out/async → async}/timeout.js +0 -0
- /package/{out/component-manifest → component-manifest}/ComponentManifest.interface.d.ts +0 -0
- /package/{out/component-manifest → component-manifest}/ComponentManifest.interface.js +0 -0
- /package/{out/component-manifest → component-manifest}/ContextMenuManifest.interface.d.ts +0 -0
- /package/{out/component-manifest → component-manifest}/ContextMenuManifest.interface.js +0 -0
- /package/{out/component-manifest → component-manifest}/DisplayCondition.interface.d.ts +0 -0
- /package/{out/component-manifest → component-manifest}/DisplayCondition.interface.js +0 -0
- /package/{out/component-manifest → component-manifest}/FloatingControlManifest.interface.d.ts +0 -0
- /package/{out/component-manifest → component-manifest}/FloatingControlManifest.interface.js +0 -0
- /package/{out/component-manifest → component-manifest}/PropPathCondition.interface.d.ts +0 -0
- /package/{out/component-manifest → component-manifest}/PropPathCondition.interface.js +0 -0
- /package/{out/component-manifest → component-manifest}/PropertyPaneManifest.interface.d.ts +0 -0
- /package/{out/component-manifest → component-manifest}/PropertyPaneManifest.interface.js +0 -0
- /package/{out/converter → converter}/time/TimeUnit.d.ts +0 -0
- /package/{out/converter → converter}/time/TimeUnit.js +0 -0
- /package/{out/converter → converter}/time/TimerConverter.d.ts +0 -0
- /package/{out/converter → converter}/time/TimerConverter.js +0 -0
- /package/{out/document → document}/ComponentInsertType.d.ts +0 -0
- /package/{out/document → document}/ComponentInsertType.js +0 -0
- /package/{out/document → document}/Document.interface.js +0 -0
- /package/{out/document → document}/DocumentCssVarsReplace.d.ts +0 -0
- /package/{out/document → document}/DocumentCssVarsReplace.js +0 -0
- /package/{out/document → document}/DocumentUtils.d.ts +0 -0
- /package/{out/document → document}/DocumentUtils.js +0 -0
- /package/{out/document → document}/hidden-fields.interface.d.ts +0 -0
- /package/{out/document → document}/hidden-fields.interface.js +0 -0
- /package/{out/dom → dom}/ViewportSize.d.ts +0 -0
- /package/{out/dom → dom}/ViewportSize.js +0 -0
- /package/{out/dom → dom}/copyToClipboard.d.ts +0 -0
- /package/{out/dom → dom}/copyToClipboard.js +0 -0
- /package/{out/dom → dom}/getMostNestedNode.d.ts +0 -0
- /package/{out/dom → dom}/getMostNestedNode.js +0 -0
- /package/{out/dom → dom}/insertHtmlIntoElement.d.ts +0 -0
- /package/{out/dom → dom}/insertHtmlIntoElement.js +0 -0
- /package/{out/dom → dom}/sanitizeHTML.d.ts +0 -0
- /package/{out/dom → dom}/sanitizeHTML.js +0 -0
- /package/{out/element → element}/BaseElementInViewportHandler.d.ts +0 -0
- /package/{out/element → element}/BaseElementInViewportHandler.js +0 -0
- /package/{out/element → element}/CssVarsOperations.d.ts +0 -0
- /package/{out/element → element}/CssVarsOperations.js +0 -0
- /package/{out/element → element}/ThemeCssVars.d.ts +0 -0
- /package/{out/element → element}/ThemeCssVars.js +0 -0
- /package/{out/element → element}/recursiveFindParentNodeByAttribute.d.ts +0 -0
- /package/{out/element → element}/recursiveFindParentNodeByAttribute.js +0 -0
- /package/{out/flat.d.ts → flat.d.ts} +0 -0
- /package/{out/flat.js → flat.js} +0 -0
- /package/{out/handler → handler}/HandlerTypes.d.ts +0 -0
- /package/{out/handler → handler}/HandlerTypes.js +0 -0
- /package/{out/math → math}/RandomDistributor.d.ts +0 -0
- /package/{out/math → math}/RandomDistributor.js +0 -0
- /package/{out/math → math}/sum.d.ts +0 -0
- /package/{out/math → math}/sum.js +0 -0
- /package/{out/network → network}/HttpClient.d.ts +0 -0
- /package/{out/network → network}/HttpClient.js +0 -0
- /package/{out/network → network}/HttpStatus.d.ts +0 -0
- /package/{out/network → network}/HttpStatus.js +0 -0
- /package/{out/object → object}/isDictionary.d.ts +0 -0
- /package/{out/object → object}/isDictionary.js +0 -0
- /package/{out/object → object}/omitKeys.d.ts +0 -0
- /package/{out/object → object}/omitKeys.js +0 -0
- /package/{out/storage → storage}/BaseCachingStorage.d.ts +0 -0
- /package/{out/storage → storage}/BaseCachingStorage.js +0 -0
- /package/{out/storage → storage}/CachingCookieStorage.d.ts +0 -0
- /package/{out/storage → storage}/CachingCookieStorage.js +0 -0
- /package/{out/storage → storage}/CachingLocalStorage.d.ts +0 -0
- /package/{out/storage → storage}/CachingLocalStorage.js +0 -0
- /package/{out/storage → storage}/getCookie.d.ts +0 -0
- /package/{out/storage → storage}/getCookie.js +0 -0
- /package/{out/storage → storage}/setCookie.d.ts +0 -0
- /package/{out/storage → storage}/setCookie.js +0 -0
- /package/{out/theme → theme}/theme.utils.d.ts +0 -0
- /package/{out/theme → theme}/theme.utils.js +0 -0
- /package/{out/url → url}/sanitizeUrl.d.ts +0 -0
- /package/{out/url → url}/sanitizeUrl.js +0 -0
- /package/{out/utils → utils}/CaseTransformer.d.ts +0 -0
- /package/{out/utils → utils}/CaseTransformer.js +0 -0
- /package/{out/utils → utils}/NullishCoalescingOperator.d.ts +0 -0
- /package/{out/utils → utils}/NullishCoalescingOperator.js +0 -0
- /package/{out/utils → utils}/NumericDecline.d.ts +0 -0
- /package/{out/utils → utils}/NumericDecline.js +0 -0
- /package/{out/utils → utils}/addEventListener.d.ts +0 -0
- /package/{out/utils → utils}/addEventListener.js +0 -0
- /package/{out/utils → utils}/allSettled.d.ts +0 -0
- /package/{out/utils → utils}/allSettled.js +0 -0
- /package/{out/utils → utils}/checkTimeZone.d.ts +0 -0
- /package/{out/utils → utils}/checkTimeZone.js +0 -0
- /package/{out/utils → utils}/deviceUtils.d.ts +0 -0
- /package/{out/utils → utils}/deviceUtils.js +0 -0
- /package/{out/utils → utils}/flatMap.d.ts +0 -0
- /package/{out/utils → utils}/flatMap.js +0 -0
- /package/{out/utils → utils}/fromEntries.d.ts +0 -0
- /package/{out/utils → utils}/fromEntries.js +0 -0
- /package/{out/utils → utils}/generateRandomNumber.d.ts +0 -0
- /package/{out/utils → utils}/generateRandomNumber.js +0 -0
- /package/{out/utils → utils}/objectSort.d.ts +0 -0
- /package/{out/utils → utils}/objectSort.js +0 -0
- /package/{out/utils → utils}/orientationUtils.d.ts +0 -0
- /package/{out/utils → utils}/orientationUtils.js +0 -0
- /package/{out/velocity → velocity}/SysVelocityContext.d.ts +0 -0
- /package/{out/velocity → velocity}/SysVelocityContext.js +0 -0
- /package/{out/velocity → velocity}/SysVelocityRenderer.d.ts +0 -0
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export default function recursiveFindParentNodeByAttribute(
|
|
2
|
-
ref: Node | null,
|
|
3
|
-
attributeName: string,
|
|
4
|
-
attributeValue: string,
|
|
5
|
-
attributeValuePredicate?: (value: string | null) => boolean
|
|
6
|
-
): Element | null {
|
|
7
|
-
const recursiveWalk = (node: Node | null): Element | null => {
|
|
8
|
-
const isFragment = node instanceof DocumentFragment ||
|
|
9
|
-
node?.nodeType === Node.DOCUMENT_FRAGMENT_NODE; // instanceof DocumentFragment is broken (returns false) in FF, so we have to make this workaround
|
|
10
|
-
|
|
11
|
-
let hostNode: any = isFragment ? (node as any).host : node;
|
|
12
|
-
|
|
13
|
-
const getAttributeCheckResult = () => attributeValuePredicate && typeof attributeValuePredicate === 'function' ?
|
|
14
|
-
attributeValuePredicate(hostNode.getAttribute(attributeName)) :
|
|
15
|
-
hostNode?.getAttribute?.(attributeName) === attributeValue;
|
|
16
|
-
|
|
17
|
-
if (hostNode && getAttributeCheckResult()) {
|
|
18
|
-
return hostNode;
|
|
19
|
-
} else {
|
|
20
|
-
return hostNode && hostNode.parentNode && recursiveWalk(hostNode.parentNode) || null;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
return recursiveWalk(ref);
|
|
25
|
-
}
|
package/src/flat.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flattens a nested array to a specified depth.
|
|
3
|
-
* Similar to Array.prototype.flat() but with broader browser support.
|
|
4
|
-
* @typeParam T - The element type of the array
|
|
5
|
-
* @param arr - The array to flatten
|
|
6
|
-
* @param depth - The depth level to flatten (default: 1)
|
|
7
|
-
* @returns A new flattened array
|
|
8
|
-
* @example
|
|
9
|
-
* flat([[1, 2], [3, [4, 5]]], 1); // [1, 2, 3, [4, 5]]
|
|
10
|
-
* flat([[1, 2], [3, [4, 5]]], 2); // [1, 2, 3, 4, 5]
|
|
11
|
-
*/
|
|
12
|
-
export function flat<T>(arr: (T | T[])[], depth: number = 1): T[] {
|
|
13
|
-
return arr.reduce((acc: T[], val: T | T[]) => Array.isArray(val) && depth >= 1
|
|
14
|
-
? acc.concat(flat(val as (T | T[])[], depth - 1))
|
|
15
|
-
: acc.concat(val as T), []);
|
|
16
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import RandomDistributor from "./RandomDistributor";
|
|
2
|
-
|
|
3
|
-
describe('RandomDistributor', () => {
|
|
4
|
-
|
|
5
|
-
it('should calc', () => {
|
|
6
|
-
|
|
7
|
-
const randomDistributor = new RandomDistributor();
|
|
8
|
-
let options = [
|
|
9
|
-
{
|
|
10
|
-
id: 0,
|
|
11
|
-
weight: 1
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
id: 1,
|
|
15
|
-
weight: 1
|
|
16
|
-
}
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
let vars: Record<number, number> = {};
|
|
21
|
-
let length = 1_000_000;
|
|
22
|
-
|
|
23
|
-
for (let i = 0; i < length; i++) {
|
|
24
|
-
let id = randomDistributor.calculateFromWeights(options)!.id as number;
|
|
25
|
-
if (!vars[id]) {
|
|
26
|
-
vars[id] = 1;
|
|
27
|
-
} else {
|
|
28
|
-
vars[id] += 1;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
expect(vars[0] / length).toBeCloseTo(0.5, 2)
|
|
33
|
-
expect(vars[1] / length).toBeCloseTo(0.5, 2);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import sum from "./sum";
|
|
2
|
-
import generateRandomNumber from "../utils/generateRandomNumber";
|
|
3
|
-
|
|
4
|
-
interface WeightedOption {
|
|
5
|
-
id: string | number;
|
|
6
|
-
weight: number;
|
|
7
|
-
[key: string]: any;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
interface Range {
|
|
11
|
-
from: number;
|
|
12
|
-
to: number;
|
|
13
|
-
id: string | number;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export default class RandomDistributor {
|
|
17
|
-
|
|
18
|
-
calculateFromWeights(originOptions: WeightedOption[], multiplier = 1000): WeightedOption | undefined {
|
|
19
|
-
const options = originOptions.map(o => ({...o, weight: o.weight * multiplier}));
|
|
20
|
-
|
|
21
|
-
const sumResult = sum(options.map(o => parseFloat(String(o.weight))));
|
|
22
|
-
|
|
23
|
-
const targetValue = generateRandomNumber(1, sumResult);
|
|
24
|
-
let ranges = this._buildRanges(options);
|
|
25
|
-
|
|
26
|
-
const correspondingRule = this._getRangeByWeight(ranges, targetValue);
|
|
27
|
-
return options.find(o => o.id === correspondingRule?.id);
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
_getRangeByWeight(ranges: Range[], weight: number): Range | undefined {
|
|
32
|
-
return ranges.find(range => weight >= range.from && weight <= range.to);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
_buildRanges(rules: WeightedOption[]): Range[] {
|
|
36
|
-
let ranges: Range[] = [];
|
|
37
|
-
for (let i = 0; i < rules.length; i++) {
|
|
38
|
-
const splitRule = rules[i];
|
|
39
|
-
if (i === 0) {
|
|
40
|
-
ranges.push({
|
|
41
|
-
from: 1,
|
|
42
|
-
to: parseFloat(String(splitRule.weight)),
|
|
43
|
-
id: splitRule.id,
|
|
44
|
-
});
|
|
45
|
-
} else {
|
|
46
|
-
const last = ranges[ranges.length - 1];
|
|
47
|
-
const from = last.to;
|
|
48
|
-
const to = from + parseFloat(String(splitRule.weight));
|
|
49
|
-
ranges.push({
|
|
50
|
-
from: from + 1,
|
|
51
|
-
to,
|
|
52
|
-
id: splitRule.id,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return ranges;
|
|
57
|
-
}
|
|
58
|
-
}
|
package/src/math/sum.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
class HttpClient {
|
|
2
|
-
execute(
|
|
3
|
-
URL: string,
|
|
4
|
-
method: string = 'GET',
|
|
5
|
-
body: any = null,
|
|
6
|
-
headers?: Record<string, string>,
|
|
7
|
-
abortSignal?: AbortSignal,
|
|
8
|
-
): Promise<Response> {
|
|
9
|
-
const requestParams: RequestInit = {
|
|
10
|
-
method,
|
|
11
|
-
headers: {
|
|
12
|
-
'Content-Type': 'text/plain',
|
|
13
|
-
...(headers || {}),
|
|
14
|
-
},
|
|
15
|
-
credentials: 'same-origin',
|
|
16
|
-
body: null,
|
|
17
|
-
signal: abortSignal,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
if (body) {
|
|
21
|
-
requestParams.body = typeof body === 'string' ? body : JSON.stringify(body);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return fetch(URL, requestParams);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export default new HttpClient();
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import isDictionary from './isDictionary';
|
|
2
|
-
|
|
3
|
-
describe('isDictionary', () => {
|
|
4
|
-
|
|
5
|
-
it('should not pass primitives', () => {
|
|
6
|
-
expect(isDictionary(2)).toEqual(false);
|
|
7
|
-
expect(isDictionary('abc')).toEqual(false);
|
|
8
|
-
expect(isDictionary(true)).toEqual(false);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it('should not pass null', () => {
|
|
12
|
-
expect(isDictionary(null)).toEqual(false);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should not pass array', () => {
|
|
16
|
-
expect(isDictionary([])).toEqual(false);
|
|
17
|
-
expect(isDictionary([1])).toEqual(false);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should pass dictionary', () => {
|
|
21
|
-
expect(isDictionary({})).toEqual(true);
|
|
22
|
-
expect(isDictionary({a: [1]})).toEqual(true);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if a value is a plain object (dictionary).
|
|
3
|
-
* Returns true for objects that are not null and not arrays.
|
|
4
|
-
* @param object - The value to check
|
|
5
|
-
* @returns True if the value is a plain object, false otherwise
|
|
6
|
-
* @example
|
|
7
|
-
* isDictionary({a: 1}); // true
|
|
8
|
-
* isDictionary([1, 2, 3]); // false
|
|
9
|
-
* isDictionary(null); // false
|
|
10
|
-
*/
|
|
11
|
-
export default function isDictionary(object: unknown): boolean {
|
|
12
|
-
return typeof object === 'object' && object !== null && !Array.isArray(object);
|
|
13
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import omitKeys from "./omitKeys";
|
|
2
|
-
|
|
3
|
-
describe('omitKeys', function () {
|
|
4
|
-
it('should omit', function () {
|
|
5
|
-
const map = {
|
|
6
|
-
key1: {a: true, b: 1},
|
|
7
|
-
key2: 'red',
|
|
8
|
-
key3: []
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const actualResult = omitKeys(map, ['key2']);
|
|
12
|
-
|
|
13
|
-
expect(actualResult).toStrictEqual({
|
|
14
|
-
key1: {a: true, b: 1},
|
|
15
|
-
key3: []
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
});
|
|
19
|
-
});
|
package/src/object/omitKeys.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates a new object with specified keys omitted.
|
|
3
|
-
* @typeParam T - The source object type
|
|
4
|
-
* @typeParam K - The keys to omit
|
|
5
|
-
* @param kv - The source object
|
|
6
|
-
* @param ignoreKeys - Array of keys to exclude from the result
|
|
7
|
-
* @returns A new object without the specified keys
|
|
8
|
-
* @example
|
|
9
|
-
* const obj = { a: 1, b: 2, c: 3 };
|
|
10
|
-
* omitKeys(obj, ['b']); // { a: 1, c: 3 }
|
|
11
|
-
*/
|
|
12
|
-
export default function omitKeys<T extends Record<string, unknown>, K extends keyof T>(
|
|
13
|
-
kv: T,
|
|
14
|
-
ignoreKeys: K[]
|
|
15
|
-
): Omit<T, K> {
|
|
16
|
-
return Object
|
|
17
|
-
.keys(kv)
|
|
18
|
-
.filter(keyName => !ignoreKeys.includes(keyName as K))
|
|
19
|
-
.reduce((acc, keyName) => ({...acc, [keyName]: kv[keyName]}), {}) as Omit<T, K>;
|
|
20
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
import BaseCachingStorage from './BaseCachingStorage';
|
|
3
|
-
|
|
4
|
-
class ConcreteStorage extends BaseCachingStorage {
|
|
5
|
-
store: Record<string, string | null> = {};
|
|
6
|
-
|
|
7
|
-
get(key: string): string | null {
|
|
8
|
-
const cached = this._getFromCache(key);
|
|
9
|
-
if (cached !== null) return cached;
|
|
10
|
-
return this._process(() => {
|
|
11
|
-
const val = this.store[key] ?? null;
|
|
12
|
-
this._setToCache(key, val);
|
|
13
|
-
return val;
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
set(key: string, value: string): void {
|
|
18
|
-
this._setToCache(key, value);
|
|
19
|
-
this._process(() => { this.store[key] = value; });
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
remove(key: string): void {
|
|
23
|
-
this._removeFromCache(key);
|
|
24
|
-
this._process(() => { delete this.store[key]; });
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
describe('BaseCachingStorage', () => {
|
|
29
|
-
let storage: ConcreteStorage;
|
|
30
|
-
|
|
31
|
-
beforeEach(() => {
|
|
32
|
-
storage = new ConcreteStorage();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('returns value when set', () => {
|
|
36
|
-
storage.set('key', 'value');
|
|
37
|
-
expect(storage.get('key')).toBe('value');
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('returns cached value without re-reading storage within TTL', () => {
|
|
41
|
-
storage.set('key', 'value');
|
|
42
|
-
storage.store['key'] = 'changed-in-storage';
|
|
43
|
-
expect(storage.get('key')).toBe('value');
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('re-reads from storage after cache expires', () => {
|
|
47
|
-
jest.useFakeTimers();
|
|
48
|
-
storage.set('key', 'first');
|
|
49
|
-
jest.advanceTimersByTime(2001);
|
|
50
|
-
storage.store['key'] = 'second';
|
|
51
|
-
expect(storage.get('key')).toBe('second');
|
|
52
|
-
jest.useRealTimers();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('returns null after remove', () => {
|
|
56
|
-
storage.set('key', 'value');
|
|
57
|
-
storage.remove('key');
|
|
58
|
-
expect(storage.get('key')).toBeNull();
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('returns null for unknown key', () => {
|
|
62
|
-
expect(storage.get('missing')).toBeNull();
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('does not throw when storage operation throws', () => {
|
|
66
|
-
const throwing = new ConcreteStorage();
|
|
67
|
-
jest.spyOn(throwing, '_process').mockImplementation(() => null);
|
|
68
|
-
expect(() => throwing.get('key')).not.toThrow();
|
|
69
|
-
});
|
|
70
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
interface CacheEntry {
|
|
2
|
-
value: string | null;
|
|
3
|
-
expiration: number;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export default abstract class BaseCachingStorage {
|
|
7
|
-
cache: Record<string, CacheEntry> = {};
|
|
8
|
-
cacheTimeMs = 2000;
|
|
9
|
-
|
|
10
|
-
protected _process(operationCallback: () => string | null): string | null {
|
|
11
|
-
try {
|
|
12
|
-
return operationCallback();
|
|
13
|
-
} catch (e) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
protected _getFromCache(key: string): string | null {
|
|
19
|
-
const currentTime = Date.now();
|
|
20
|
-
const cachedItem = this.cache[key];
|
|
21
|
-
if (cachedItem && currentTime < cachedItem.expiration) {
|
|
22
|
-
return cachedItem.value;
|
|
23
|
-
}
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
protected _setToCache(key: string, value: string | null): void {
|
|
28
|
-
this.cache[key] = {
|
|
29
|
-
value,
|
|
30
|
-
expiration: Date.now() + this.cacheTimeMs,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
protected _removeFromCache(key: string): void {
|
|
35
|
-
delete this.cache[key];
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import CachingCookieStorage from './CachingCookieStorage';
|
|
2
|
-
import getCookie from './getCookie';
|
|
3
|
-
import setCookie from './setCookie';
|
|
4
|
-
|
|
5
|
-
jest.mock('./getCookie', () => ({
|
|
6
|
-
__esModule: true,
|
|
7
|
-
default: jest.fn(),
|
|
8
|
-
}));
|
|
9
|
-
|
|
10
|
-
jest.mock('./setCookie', () => ({
|
|
11
|
-
__esModule: true,
|
|
12
|
-
default: jest.fn(),
|
|
13
|
-
}));
|
|
14
|
-
|
|
15
|
-
describe('CachingCookieStorage', () => {
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
CachingCookieStorage.cache = {};
|
|
18
|
-
jest.clearAllMocks();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe('get', () => {
|
|
22
|
-
it('returns cookie value when cookie exists', () => {
|
|
23
|
-
(getCookie as jest.Mock).mockReturnValue('bar');
|
|
24
|
-
|
|
25
|
-
expect(CachingCookieStorage.get('foo')).toBe('bar');
|
|
26
|
-
expect(getCookie).toHaveBeenCalledWith('foo');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('returns null when cookie does not exist', () => {
|
|
30
|
-
(getCookie as jest.Mock).mockReturnValue(undefined);
|
|
31
|
-
|
|
32
|
-
expect(CachingCookieStorage.get('unknown_key_xyz')).toBeNull();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('returns cached value on second call without re-reading cookie', () => {
|
|
36
|
-
(getCookie as jest.Mock).mockReturnValue('original');
|
|
37
|
-
|
|
38
|
-
CachingCookieStorage.get('cached_key');
|
|
39
|
-
expect(CachingCookieStorage.get('cached_key')).toBe('original');
|
|
40
|
-
expect(getCookie).toHaveBeenCalledTimes(1);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('returns null when getCookie returns undefined after failure', () => {
|
|
44
|
-
(getCookie as jest.Mock).mockReturnValue(undefined);
|
|
45
|
-
|
|
46
|
-
expect(CachingCookieStorage.get('key')).toBeNull();
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
describe('set', () => {
|
|
51
|
-
it('delegates string values to setCookie', () => {
|
|
52
|
-
CachingCookieStorage.set('key', 'value');
|
|
53
|
-
|
|
54
|
-
expect(setCookie).toHaveBeenCalledWith('key', 'value', {});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('stringifies non-string values before delegating', () => {
|
|
58
|
-
CachingCookieStorage.set('key', { a: 1 });
|
|
59
|
-
|
|
60
|
-
expect(setCookie).toHaveBeenCalledWith('key', '{"a":1}', {});
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
describe('remove', () => {
|
|
65
|
-
it('removes value from cache after remove', () => {
|
|
66
|
-
(getCookie as jest.Mock).mockReturnValue('bar');
|
|
67
|
-
|
|
68
|
-
CachingCookieStorage.get('remove_test');
|
|
69
|
-
CachingCookieStorage.remove('remove_test');
|
|
70
|
-
|
|
71
|
-
expect(CachingCookieStorage.cache['remove_test']).toBeUndefined();
|
|
72
|
-
expect(setCookie).toHaveBeenCalledWith('remove_test', '', { expires: new Date(0) });
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
});
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import BaseCachingStorage from './BaseCachingStorage';
|
|
2
|
-
import getCookie from './getCookie';
|
|
3
|
-
import setCookie, { CookieOptionsI } from './setCookie';
|
|
4
|
-
|
|
5
|
-
class CachingCookieStorage extends BaseCachingStorage {
|
|
6
|
-
get(name: string): string | null {
|
|
7
|
-
const cached = this._getFromCache(name);
|
|
8
|
-
if (cached !== null) {
|
|
9
|
-
return cached;
|
|
10
|
-
}
|
|
11
|
-
return this._process(() => {
|
|
12
|
-
const value = getCookie(name) ?? null;
|
|
13
|
-
this._setToCache(name, value);
|
|
14
|
-
return value;
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
set(name: string, value: string | object, options: CookieOptionsI = {}): void {
|
|
19
|
-
const stringifiedValue = typeof value === 'string' ? value : this._process(() => JSON.stringify(value)) as string;
|
|
20
|
-
this._setToCache(name, stringifiedValue);
|
|
21
|
-
this._process(() => {
|
|
22
|
-
setCookie(name, stringifiedValue, options);
|
|
23
|
-
return null;
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
remove(name: string): void {
|
|
28
|
-
this._removeFromCache(name);
|
|
29
|
-
this._process(() => {
|
|
30
|
-
setCookie(name, '', { expires: new Date(0) });
|
|
31
|
-
return null;
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export default new CachingCookieStorage();
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
import CachingLocalStorage from './CachingLocalStorage';
|
|
3
|
-
|
|
4
|
-
describe('CachingLocalStorage', () => {
|
|
5
|
-
beforeEach(() => {
|
|
6
|
-
CachingLocalStorage.cache = {};
|
|
7
|
-
localStorage.clear();
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
describe('get', () => {
|
|
11
|
-
it('returns value when key exists', () => {
|
|
12
|
-
localStorage.setItem('key', 'hello');
|
|
13
|
-
expect(CachingLocalStorage.get('key')).toBe('hello');
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('returns null when key does not exist', () => {
|
|
17
|
-
expect(CachingLocalStorage.get('missing')).toBeNull();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('returns cached value on second call without re-reading localStorage', () => {
|
|
21
|
-
localStorage.setItem('key', 'original');
|
|
22
|
-
CachingLocalStorage.get('key');
|
|
23
|
-
localStorage.setItem('key', 'modified');
|
|
24
|
-
expect(CachingLocalStorage.get('key')).toBe('original');
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('returns null when localStorage.getItem throws', () => {
|
|
28
|
-
jest.spyOn(Storage.prototype, 'getItem').mockImplementation(() => { throw new Error('blocked'); });
|
|
29
|
-
expect(CachingLocalStorage.get('key')).toBeNull();
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
describe('set', () => {
|
|
34
|
-
it('stores value in localStorage', () => {
|
|
35
|
-
CachingLocalStorage.set('key', 'value');
|
|
36
|
-
expect(localStorage.getItem('key')).toBe('value');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('stringifies non-string values', () => {
|
|
40
|
-
CachingLocalStorage.set('key', { a: 1 });
|
|
41
|
-
expect(localStorage.getItem('key')).toBe('{"a":1}');
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe('remove', () => {
|
|
46
|
-
it('removes value from localStorage', () => {
|
|
47
|
-
localStorage.setItem('key', 'value');
|
|
48
|
-
CachingLocalStorage.remove('key');
|
|
49
|
-
expect(localStorage.getItem('key')).toBeNull();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('removes value from cache after remove', () => {
|
|
53
|
-
localStorage.setItem('key', 'value');
|
|
54
|
-
CachingLocalStorage.get('key');
|
|
55
|
-
CachingLocalStorage.remove('key');
|
|
56
|
-
expect(CachingLocalStorage.cache['key']).toBeUndefined();
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
});
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import BaseCachingStorage from './BaseCachingStorage';
|
|
2
|
-
|
|
3
|
-
class CachingLocalStorage extends BaseCachingStorage {
|
|
4
|
-
get(key: string): string | null {
|
|
5
|
-
const cached = this._getFromCache(key);
|
|
6
|
-
if (cached !== null) {
|
|
7
|
-
return cached;
|
|
8
|
-
}
|
|
9
|
-
return this._process(() => {
|
|
10
|
-
const value = localStorage.getItem(key);
|
|
11
|
-
this._setToCache(key, value);
|
|
12
|
-
return value;
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
set(key: string, value: string | object): void {
|
|
17
|
-
const stringifiedValue = typeof value === 'string' ? value : this._process(() => JSON.stringify(value)) as string;
|
|
18
|
-
this._setToCache(key, stringifiedValue);
|
|
19
|
-
this._process(() => {
|
|
20
|
-
localStorage.setItem(key, stringifiedValue);
|
|
21
|
-
return null;
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
remove(key: string): void {
|
|
26
|
-
this._removeFromCache(key);
|
|
27
|
-
this._process(() => {
|
|
28
|
-
localStorage.removeItem(key);
|
|
29
|
-
return null;
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export default new CachingLocalStorage();
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import getCookie from './getCookie';
|
|
2
|
-
|
|
3
|
-
describe('getCookie', () => {
|
|
4
|
-
let originalDescriptor: PropertyDescriptor | undefined;
|
|
5
|
-
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
originalDescriptor = Object.getOwnPropertyDescriptor(Document.prototype, 'cookie');
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
afterEach(() => {
|
|
11
|
-
if (originalDescriptor) {
|
|
12
|
-
Object.defineProperty(document, 'cookie', originalDescriptor);
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('returns cookie value when cookie exists', () => {
|
|
17
|
-
Object.defineProperty(document, 'cookie', {
|
|
18
|
-
get: () => 'foo=bar; x=y',
|
|
19
|
-
configurable: true,
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
expect(getCookie('foo')).toBe('bar');
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('returns undefined when cookie does not exist', () => {
|
|
26
|
-
Object.defineProperty(document, 'cookie', {
|
|
27
|
-
get: () => 'foo=bar',
|
|
28
|
-
configurable: true,
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
expect(getCookie('unknown_key_xyz')).toBeUndefined();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('decodes URI-encoded cookie values', () => {
|
|
35
|
-
Object.defineProperty(document, 'cookie', {
|
|
36
|
-
get: () => 'encoded_val=' + encodeURIComponent('hello world'),
|
|
37
|
-
configurable: true,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
expect(getCookie('encoded_val')).toBe('hello world');
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('returns undefined when document.cookie access throws', () => {
|
|
44
|
-
Object.defineProperty(document, 'cookie', {
|
|
45
|
-
get: () => {
|
|
46
|
-
throw new Error('blocked');
|
|
47
|
-
},
|
|
48
|
-
configurable: true,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
expect(getCookie('key')).toBeUndefined();
|
|
52
|
-
});
|
|
53
|
-
});
|
package/src/storage/getCookie.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export default function getCookie(name: string): string | undefined {
|
|
2
|
-
try {
|
|
3
|
-
const matches = document.cookie.match(new RegExp(
|
|
4
|
-
'(?:^|; )' + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + '=([^;]*)'
|
|
5
|
-
));
|
|
6
|
-
return matches ? decodeURIComponent(matches[1]) : undefined;
|
|
7
|
-
} catch (e) {
|
|
8
|
-
return undefined;
|
|
9
|
-
}
|
|
10
|
-
}
|