@vpmedia/simplify 1.54.0 → 1.55.0
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/CHANGELOG.md +36 -0
- package/package.json +14 -14
- package/src/index.js +9 -19
- package/src/logging/Logger.js +1 -1
- package/src/logging/OpenTelemetryLogHandler.js +1 -1
- package/src/logging/util.js +2 -0
- package/src/logging/util.test.js +4 -1
- package/src/pagelifecycle/util.js +17 -21
- package/src/util/async.js +20 -0
- package/src/util/{delayPromise.test.js → async.test.js} +1 -1
- package/src/util/{getErrorDetails.test.js → error.test.js} +1 -1
- package/src/util/{fetchRetry.js → fetch.js} +6 -4
- package/src/util/number.js +116 -0
- package/src/util/number.test.js +115 -0
- package/src/util/object.js +97 -0
- package/src/util/object.test.js +205 -0
- package/src/util/{getURLParam.js → query.js} +12 -2
- package/src/util/{sanitizeURLParam.test.js → query.test.js} +18 -1
- package/src/util/{serverDataToState.js → state.js} +1 -1
- package/src/util/{serverDataToState.test.js → state.test.js} +1 -1
- package/src/util/string.js +54 -0
- package/src/util/{capitalize.test.js → string.test.js} +19 -1
- package/src/util/validate.js +272 -0
- package/src/util/validate.test.js +325 -0
- package/tsconfig.build.json +24 -0
- package/types/index.d.ts +9 -19
- package/types/logging/util.d.ts.map +1 -1
- package/types/pagelifecycle/util.d.ts +1 -1
- package/types/pagelifecycle/util.d.ts.map +1 -1
- package/types/util/async.d.ts +3 -0
- package/types/util/async.d.ts.map +1 -0
- package/types/util/{getErrorDetails.d.ts → error.d.ts} +1 -1
- package/types/util/error.d.ts.map +1 -0
- package/types/util/{fetchRetry.d.ts → fetch.d.ts} +1 -1
- package/types/util/fetch.d.ts.map +1 -0
- package/types/util/number.d.ts +13 -0
- package/types/util/number.d.ts.map +1 -0
- package/types/util/object.d.ts +6 -0
- package/types/util/object.d.ts.map +1 -0
- package/types/util/{getURLParam.d.ts → query.d.ts} +2 -1
- package/types/util/query.d.ts.map +1 -0
- package/types/util/{serverDataToState.d.ts → state.d.ts} +1 -1
- package/types/util/state.d.ts.map +1 -0
- package/types/util/string.d.ts +5 -0
- package/types/util/string.d.ts.map +1 -0
- package/types/util/validate.d.ts +54 -0
- package/types/util/validate.d.ts.map +1 -0
- package/src/util/addLeadingZero.js +0 -16
- package/src/util/addLeadingZero.test.js +0 -11
- package/src/util/capitalize.js +0 -15
- package/src/util/deepMerge.js +0 -24
- package/src/util/deepMerge.test.js +0 -103
- package/src/util/deg2rad.js +0 -8
- package/src/util/deg2rad.test.js +0 -5
- package/src/util/delayPromise.js +0 -6
- package/src/util/fixFloatPrecision.js +0 -16
- package/src/util/fixFloatPrecision.test.js +0 -27
- package/src/util/getObjArrayPropSum.js +0 -11
- package/src/util/getObjValueByPath.js +0 -20
- package/src/util/getObjValueByPath.test.js +0 -51
- package/src/util/getRandomInt.js +0 -9
- package/src/util/getRandomInt.test.js +0 -24
- package/src/util/getURLParam.test.js +0 -18
- package/src/util/loadJSON.js +0 -10
- package/src/util/purgeObject.js +0 -13
- package/src/util/purgeObject.test.js +0 -8
- package/src/util/safeFloat.js +0 -31
- package/src/util/safeFloat.test.js +0 -13
- package/src/util/sanitizeURLParam.js +0 -11
- package/src/util/saveAsFile.js +0 -14
- package/src/util/setObjValueByPath.js +0 -26
- package/src/util/setObjValueByPath.test.js +0 -47
- package/src/util/underscoreToCamelCase.js +0 -10
- package/src/util/underscoreToCamelCase.test.js +0 -7
- package/typedefs/global.d.ts +0 -5
- package/types/util/addLeadingZero.d.ts +0 -2
- package/types/util/addLeadingZero.d.ts.map +0 -1
- package/types/util/capitalize.d.ts +0 -2
- package/types/util/capitalize.d.ts.map +0 -1
- package/types/util/deepMerge.d.ts +0 -2
- package/types/util/deepMerge.d.ts.map +0 -1
- package/types/util/deg2rad.d.ts +0 -2
- package/types/util/deg2rad.d.ts.map +0 -1
- package/types/util/delayPromise.d.ts +0 -2
- package/types/util/delayPromise.d.ts.map +0 -1
- package/types/util/fetchRetry.d.ts.map +0 -1
- package/types/util/fixFloatPrecision.d.ts +0 -7
- package/types/util/fixFloatPrecision.d.ts.map +0 -1
- package/types/util/getErrorDetails.d.ts.map +0 -1
- package/types/util/getObjArrayPropSum.d.ts +0 -2
- package/types/util/getObjArrayPropSum.d.ts.map +0 -1
- package/types/util/getObjValueByPath.d.ts +0 -2
- package/types/util/getObjValueByPath.d.ts.map +0 -1
- package/types/util/getRandomInt.d.ts +0 -2
- package/types/util/getRandomInt.d.ts.map +0 -1
- package/types/util/getURLParam.d.ts.map +0 -1
- package/types/util/loadJSON.d.ts +0 -7
- package/types/util/loadJSON.d.ts.map +0 -1
- package/types/util/purgeObject.d.ts +0 -2
- package/types/util/purgeObject.d.ts.map +0 -1
- package/types/util/safeFloat.d.ts +0 -22
- package/types/util/safeFloat.d.ts.map +0 -1
- package/types/util/sanitizeURLParam.d.ts +0 -2
- package/types/util/sanitizeURLParam.d.ts.map +0 -1
- package/types/util/saveAsFile.d.ts +0 -2
- package/types/util/saveAsFile.d.ts.map +0 -1
- package/types/util/serverDataToState.d.ts.map +0 -1
- package/types/util/setObjValueByPath.d.ts +0 -2
- package/types/util/setObjValueByPath.d.ts.map +0 -1
- package/types/util/underscoreToCamelCase.d.ts +0 -2
- package/types/util/underscoreToCamelCase.d.ts.map +0 -1
- /package/src/util/{getErrorDetails.js → error.js} +0 -0
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { deepMerge } from './deepMerge.js';
|
|
2
|
-
|
|
3
|
-
describe('deepMerge', () => {
|
|
4
|
-
test('should override deep properties correctly', () => {
|
|
5
|
-
const defaultObj = { a: { b: 1, c: 2 }, d: 3 };
|
|
6
|
-
const overrideObj = { a: { b: 42 } };
|
|
7
|
-
const expectedResult = { a: { b: 42, c: 2 }, d: 3 };
|
|
8
|
-
|
|
9
|
-
expect(deepMerge({ ...defaultObj }, overrideObj)).toEqual(expectedResult);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
test('should not modify the original target object', () => {
|
|
13
|
-
const target = { x: { y: 10 } };
|
|
14
|
-
const source = { x: { y: 20 } };
|
|
15
|
-
const copy = { ...target };
|
|
16
|
-
|
|
17
|
-
deepMerge(target, source);
|
|
18
|
-
expect(target).toEqual(copy);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test('should handle non-object values correctly', () => {
|
|
22
|
-
expect(deepMerge(null, { a: 1 })).toEqual({ a: 1 });
|
|
23
|
-
expect(deepMerge({ a: 1 }, null)).toEqual({ a: 1 });
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test('should handle arrays correctly', () => {
|
|
27
|
-
const target = { arr: [1, 2] };
|
|
28
|
-
const source = { arr: [3, 4] };
|
|
29
|
-
|
|
30
|
-
expect(deepMerge(target, source)).toEqual({ arr: [3, 4] });
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test('should handle nested arrays correctly', () => {
|
|
34
|
-
const target = { obj: { arr: [1, 2] } };
|
|
35
|
-
const source = { obj: { arr: [3, 4] } };
|
|
36
|
-
|
|
37
|
-
expect(deepMerge(target, source)).toEqual({ obj: { arr: [3, 4] } });
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test('should handle string values', () => {
|
|
41
|
-
const target = { str: 'hello' };
|
|
42
|
-
const source = { str: 'world' };
|
|
43
|
-
|
|
44
|
-
expect(deepMerge(target, source)).toEqual({ str: 'world' });
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test('should handle number values', () => {
|
|
48
|
-
const target = { num: 42 };
|
|
49
|
-
const source = { num: 100 };
|
|
50
|
-
|
|
51
|
-
expect(deepMerge(target, source)).toEqual({ num: 100 });
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('should handle boolean values', () => {
|
|
55
|
-
const target = { bool: true };
|
|
56
|
-
const source = { bool: false };
|
|
57
|
-
|
|
58
|
-
expect(deepMerge(target, source)).toEqual({ bool: false });
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test('should handle undefined values', () => {
|
|
62
|
-
const target = { undef: undefined };
|
|
63
|
-
const source = { undef: 'value' };
|
|
64
|
-
|
|
65
|
-
expect(deepMerge(target, source)).toEqual({ undef: 'value' });
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test('should handle null values', () => {
|
|
69
|
-
const target = { nullVal: null };
|
|
70
|
-
const source = { nullVal: 'value' };
|
|
71
|
-
|
|
72
|
-
expect(deepMerge(target, source)).toEqual({ nullVal: 'value' });
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
test('should handle mixed property types', () => {
|
|
76
|
-
const target = {
|
|
77
|
-
str: 'hello',
|
|
78
|
-
num: 42,
|
|
79
|
-
arr: [1, 2],
|
|
80
|
-
obj: { nested: 'value' },
|
|
81
|
-
};
|
|
82
|
-
const source = {
|
|
83
|
-
str: 'world',
|
|
84
|
-
num: 100,
|
|
85
|
-
arr: [3, 4],
|
|
86
|
-
obj: { nested: 'newValue' },
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
expect(deepMerge(target, source)).toEqual({
|
|
90
|
-
str: 'world',
|
|
91
|
-
num: 100,
|
|
92
|
-
arr: [3, 4],
|
|
93
|
-
obj: { nested: 'newValue' },
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
test('should handle constructor and __proto__ protection', () => {
|
|
98
|
-
const target = { a: 1 };
|
|
99
|
-
const source = { b: 2 };
|
|
100
|
-
|
|
101
|
-
expect(deepMerge(target, source)).toEqual({ a: 1, b: 2 });
|
|
102
|
-
});
|
|
103
|
-
});
|
package/src/util/deg2rad.js
DELETED
package/src/util/deg2rad.test.js
DELETED
package/src/util/delayPromise.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns a promise with delayed resolve.
|
|
3
|
-
* @param {number} delayMS - Promise resolve delay in milliseconds.
|
|
4
|
-
* @returns {Promise<void>} Delayed resolve promise.
|
|
5
|
-
*/
|
|
6
|
-
export const delayPromise = (delayMS) => new Promise((resolve) => setTimeout(resolve, delayMS));
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fixes floating point number (0.20000000000000004 -> 0.2).
|
|
3
|
-
* @param {number} value - Number to fix.
|
|
4
|
-
* @returns {number} The fixed number.
|
|
5
|
-
*/
|
|
6
|
-
export function fixFloatPrecision(value) {
|
|
7
|
-
// Handle string inputs by converting to number first
|
|
8
|
-
if (typeof value === 'string') {
|
|
9
|
-
value = Number(value);
|
|
10
|
-
}
|
|
11
|
-
if (value >= 0 && value < 0.00000000001) {
|
|
12
|
-
const valuePlusOne = value + 1;
|
|
13
|
-
return Number.parseFloat(valuePlusOne.toPrecision(12)) - 1;
|
|
14
|
-
}
|
|
15
|
-
return Number.parseFloat(value.toPrecision(12));
|
|
16
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { fixFloatPrecision } from './fixFloatPrecision.js';
|
|
2
|
-
|
|
3
|
-
describe('fixFloatPrecision', () => {
|
|
4
|
-
test('Fixes float precision issues', () => {
|
|
5
|
-
expect(fixFloatPrecision(0.20000000000000004)).toBe(0.2);
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
test('Handles zero', () => {
|
|
9
|
-
expect(fixFloatPrecision(0)).toBe(0);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
test('Handles negative numbers', () => {
|
|
13
|
-
expect(fixFloatPrecision(-0.20000000000000004)).toBe(-0.2);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test('Handles very small numbers', () => {
|
|
17
|
-
expect(fixFloatPrecision(0.0000000000001)).toBe(0);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test('Handles integer numbers', () => {
|
|
21
|
-
expect(fixFloatPrecision(5)).toBe(5);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test('Handles string input', () => {
|
|
25
|
-
expect(fixFloatPrecision('5.123456789')).toBe(5.123456789);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns the sum value of an array of objects field.
|
|
3
|
-
* @param {object[]} arr - The list of input objects.
|
|
4
|
-
* @param {string} prop - The object property key.
|
|
5
|
-
* @returns {number} The sum value.
|
|
6
|
-
*/
|
|
7
|
-
export const getObjArrayPropSum = (arr, prop) => {
|
|
8
|
-
return arr.reduce((accumulator, object) => {
|
|
9
|
-
return accumulator + object[prop];
|
|
10
|
-
}, 0);
|
|
11
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get object value by path.
|
|
3
|
-
* @param {object} obj - The source object to get the value from.
|
|
4
|
-
* @param {string} path - The path to the property in dot notation (e.g. 'a.b.c').
|
|
5
|
-
* @returns {object | null} The value at the specified path or null if not found.
|
|
6
|
-
*/
|
|
7
|
-
export const getObjValueByPath = (obj, path) => {
|
|
8
|
-
if (!obj || !path) {
|
|
9
|
-
return null;
|
|
10
|
-
}
|
|
11
|
-
const keyParts = path.split('.');
|
|
12
|
-
const nextKey = keyParts[0];
|
|
13
|
-
if (keyParts.length === 1) {
|
|
14
|
-
return obj[nextKey] === undefined ? null : obj[nextKey];
|
|
15
|
-
}
|
|
16
|
-
if (obj[nextKey] === undefined || obj[nextKey] === null) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
return getObjValueByPath(obj[nextKey], keyParts.slice(1).join('.'));
|
|
20
|
-
};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { getObjValueByPath } from './getObjValueByPath.js';
|
|
2
|
-
|
|
3
|
-
describe('getObjValueByPath', () => {
|
|
4
|
-
test('Gets object value by path', () => {
|
|
5
|
-
const source = { a: { b: { c: 'd' } } };
|
|
6
|
-
expect(getObjValueByPath(source, 'a.b.c')).toBe('d');
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
test('Returns null when object is null or undefined', () => {
|
|
10
|
-
expect(getObjValueByPath(null, 'a.b.c')).toBeNull();
|
|
11
|
-
expect(getObjValueByPath(undefined, 'a.b.c')).toBeNull();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
test('Returns null when path is empty or null', () => {
|
|
15
|
-
expect(getObjValueByPath({ a: 'b' }, '')).toBeNull();
|
|
16
|
-
expect(getObjValueByPath({ a: 'b' }, null)).toBeNull();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test('Returns null when property does not exist', () => {
|
|
20
|
-
const source = { a: { b: 'c' } };
|
|
21
|
-
expect(getObjValueByPath(source, 'a.b.c')).toBeNull();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test('Returns null when property is undefined', () => {
|
|
25
|
-
const source = { a: { b: undefined } };
|
|
26
|
-
expect(getObjValueByPath(source, 'a.b')).toBeNull();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('Handles single-level paths correctly', () => {
|
|
30
|
-
const source = { a: 'value' };
|
|
31
|
-
expect(getObjValueByPath(source, 'a')).toBe('value');
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test('Handles nested paths correctly', () => {
|
|
35
|
-
const source = {
|
|
36
|
-
level1: {
|
|
37
|
-
level2: {
|
|
38
|
-
level3: 'deepValue',
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
expect(getObjValueByPath(source, 'level1.level2.level3')).toBe('deepValue');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test('Handles arrays in paths', () => {
|
|
46
|
-
const source = {
|
|
47
|
-
items: [{ name: 'item1' }, { name: 'item2' }],
|
|
48
|
-
};
|
|
49
|
-
expect(getObjValueByPath(source, 'items.0.name')).toBe('item1');
|
|
50
|
-
});
|
|
51
|
-
});
|
package/src/util/getRandomInt.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns random integer in range.
|
|
3
|
-
* @param {number} min - Min value.
|
|
4
|
-
* @param {number} max - Max value.
|
|
5
|
-
* @returns {number} Random integer in given range.
|
|
6
|
-
*/
|
|
7
|
-
export const getRandomInt = (min, max) => {
|
|
8
|
-
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
9
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { getRandomInt } from './getRandomInt.js';
|
|
2
|
-
|
|
3
|
-
describe('getRandomInt', () => {
|
|
4
|
-
test('Returns random integer within range when min equals max', () => {
|
|
5
|
-
expect(getRandomInt(1, 1)).toBe(1);
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
test('Returns random integer within range when min is less than max', () => {
|
|
9
|
-
const result = getRandomInt(1, 10);
|
|
10
|
-
expect(result).toBeGreaterThanOrEqual(1);
|
|
11
|
-
expect(result).toBeLessThanOrEqual(10);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
test('Works with negative numbers', () => {
|
|
15
|
-
const result = getRandomInt(-5, -1);
|
|
16
|
-
expect(result).toBeGreaterThanOrEqual(-5);
|
|
17
|
-
expect(result).toBeLessThanOrEqual(-1);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test('Works with zero range', () => {
|
|
21
|
-
const result = getRandomInt(0, 0);
|
|
22
|
-
expect(result).toBe(0);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { getURLParam } from './getURLParam.js';
|
|
2
|
-
|
|
3
|
-
describe('getURLParam', () => {
|
|
4
|
-
test('Returns fallback value when parameter is not found', () => {
|
|
5
|
-
const result = getURLParam('nonexistent', 'fallback');
|
|
6
|
-
expect(result).toBe('fallback');
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
test('Handles null/undefined input gracefully', () => {
|
|
10
|
-
const result = getURLParam(null, 'fallback');
|
|
11
|
-
expect(result).toBe('fallback');
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
test('Returns default value when param is null', () => {
|
|
15
|
-
const result = getURLParam('key', 'default');
|
|
16
|
-
expect(result).toBe('default');
|
|
17
|
-
});
|
|
18
|
-
});
|
package/src/util/loadJSON.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Load JSON file using a fetch GET request.
|
|
3
|
-
* @param {string} url - URL to load.
|
|
4
|
-
* @returns {Promise<string>} The parsed JSON data.
|
|
5
|
-
*/
|
|
6
|
-
export async function loadJSON(url) {
|
|
7
|
-
const response = await fetch(url);
|
|
8
|
-
const json = await response.json();
|
|
9
|
-
return JSON.stringify(json);
|
|
10
|
-
}
|
package/src/util/purgeObject.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Purges object properties to free up memory.
|
|
3
|
-
* @param {object} target - The target object.
|
|
4
|
-
*/
|
|
5
|
-
export const purgeObject = (target) => {
|
|
6
|
-
if (!target) {
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
const reference = target;
|
|
10
|
-
for (const entry of Object.keys(target)) {
|
|
11
|
-
reference[entry] = null;
|
|
12
|
-
}
|
|
13
|
-
};
|
package/src/util/safeFloat.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Convenience method for floating point precision handling.
|
|
3
|
-
* @param {number} value - The number to process.
|
|
4
|
-
* @param {number} p - The precision. Defaults to 2.
|
|
5
|
-
* @returns {number} The processed value.
|
|
6
|
-
*/
|
|
7
|
-
export function fixFloat(value, p = 2) {
|
|
8
|
-
return Number.parseFloat(value.toFixed(p));
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Adds two value with floating point precision.
|
|
13
|
-
* @param {number} a - The number a.
|
|
14
|
-
* @param {number} b - The number b.
|
|
15
|
-
* @returns {number} The processed value.
|
|
16
|
-
*/
|
|
17
|
-
export function addFloat(a, b) {
|
|
18
|
-
const p = 100;
|
|
19
|
-
return fixFloat((a * p + b * p) / p);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Substracts two value with floating point precision.
|
|
24
|
-
* @param {number} a - The number a.
|
|
25
|
-
* @param {number} b - The number b.
|
|
26
|
-
* @returns {number} The processed value.
|
|
27
|
-
*/
|
|
28
|
-
export function subFloat(a, b) {
|
|
29
|
-
const p = 100;
|
|
30
|
-
return fixFloat((a * p - b * p) / p);
|
|
31
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { addFloat, fixFloat, subFloat } from './safeFloat.js';
|
|
2
|
-
|
|
3
|
-
test('fixFloat()', () => {
|
|
4
|
-
expect(fixFloat(0.20000000000000004)).toBe(0.2);
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
test('addFloat()', () => {
|
|
8
|
-
expect(addFloat(0.20000000000000004, 0.1000001)).toBe(0.3);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
test('subFloat()', () => {
|
|
12
|
-
expect(subFloat(0.20000000000000004, 0.1000001)).toBe(0.1);
|
|
13
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sanitizes URL parameters allowing only alpha-numeric characters and dash.
|
|
3
|
-
* @param {string} input - The input string to be sanitized.
|
|
4
|
-
* @returns {string} The sanitized output string.
|
|
5
|
-
*/
|
|
6
|
-
export const sanitizeURLParam = (input) => {
|
|
7
|
-
if (!input) {
|
|
8
|
-
return input;
|
|
9
|
-
}
|
|
10
|
-
return input.replaceAll(/[^\w-]/gi, '');
|
|
11
|
-
};
|
package/src/util/saveAsFile.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Saves text file.
|
|
3
|
-
* @param {string} filename - File name.
|
|
4
|
-
* @param {string} text - File content.
|
|
5
|
-
*/
|
|
6
|
-
export const saveAsFile = (filename, text) => {
|
|
7
|
-
const element = document.createElement('a');
|
|
8
|
-
element.setAttribute('href', `data:text/plain;charset=utf-8,${encodeURIComponent(text)}`);
|
|
9
|
-
element.setAttribute('download', filename);
|
|
10
|
-
element.style.display = 'none';
|
|
11
|
-
document.body.append(element);
|
|
12
|
-
element.click();
|
|
13
|
-
element.remove();
|
|
14
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Set object value by path.
|
|
3
|
-
* @param {object} obj - The source object to set the value in.
|
|
4
|
-
* @param {string} path - The path to the property in dot notation (e.g. 'a.b.c').
|
|
5
|
-
* @param {object | null | undefined} value - The value to set at the specified path.
|
|
6
|
-
* @throws {SyntaxError} Error when illegal path value has been provided.
|
|
7
|
-
*/
|
|
8
|
-
export const setObjValueByPath = (obj, path, value) => {
|
|
9
|
-
if (!obj || !path) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
const keyParts = path.split('.');
|
|
13
|
-
const nextKey = keyParts[0];
|
|
14
|
-
if (nextKey === '__proto__') {
|
|
15
|
-
throw new SyntaxError('Security violation error. Cannot use "__proto__" as parameter.');
|
|
16
|
-
}
|
|
17
|
-
if (keyParts.length === 1) {
|
|
18
|
-
obj[nextKey] = value;
|
|
19
|
-
} else {
|
|
20
|
-
// Create the nested object if it doesn't exist
|
|
21
|
-
if (obj[nextKey] === undefined || obj[nextKey] === null) {
|
|
22
|
-
obj[nextKey] = {};
|
|
23
|
-
}
|
|
24
|
-
setObjValueByPath(obj[nextKey], keyParts.slice(1).join('.'), value);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { getObjValueByPath } from './getObjValueByPath.js';
|
|
2
|
-
import { setObjValueByPath } from './setObjValueByPath.js';
|
|
3
|
-
|
|
4
|
-
describe('setObjValueByPath', () => {
|
|
5
|
-
test('Sets object value by path', () => {
|
|
6
|
-
const source = { a: { b: { c: 'd' } } };
|
|
7
|
-
expect(getObjValueByPath(source, 'a.b.c')).toBe('d');
|
|
8
|
-
setObjValueByPath(source, 'a.b.c', 'newValue');
|
|
9
|
-
expect(getObjValueByPath(source, 'a.b.c')).toBe('newValue');
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
test('Handles null or undefined object', () => {
|
|
13
|
-
// Should not throw error
|
|
14
|
-
setObjValueByPath(null, 'a.b.c', 'value');
|
|
15
|
-
setObjValueByPath(undefined, 'a.b.c', 'value');
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test('Handles null or undefined path', () => {
|
|
19
|
-
const source = { a: 'b' };
|
|
20
|
-
// Should not throw error
|
|
21
|
-
setObjValueByPath(source, null, 'value');
|
|
22
|
-
setObjValueByPath(source, undefined, 'value');
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test('Sets value at root level', () => {
|
|
26
|
-
const source = { a: 'oldValue' };
|
|
27
|
-
setObjValueByPath(source, 'a', 'newValue');
|
|
28
|
-
expect(source.a).toBe('newValue');
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('Creates new nested properties', () => {
|
|
32
|
-
const source = { a: { b: 'existing' } };
|
|
33
|
-
setObjValueByPath(source, 'a.c.d', 'newNestedValue');
|
|
34
|
-
expect(getObjValueByPath(source, 'a.c.d')).toBe('newNestedValue');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('Handles array paths', () => {
|
|
38
|
-
const source = { items: [{ name: 'item1' }] };
|
|
39
|
-
setObjValueByPath(source, 'items.0.name', 'updatedItem');
|
|
40
|
-
expect(getObjValueByPath(source, 'items.0.name')).toBe('updatedItem');
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test('Throws error for __proto__ path', () => {
|
|
44
|
-
const source = { a: 'b' };
|
|
45
|
-
expect(() => setObjValueByPath(source, '__proto__.test', 'value')).toThrow(SyntaxError);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converts underscore case string to camel case.
|
|
3
|
-
* @param {string} value - The input string in underscore case.
|
|
4
|
-
* @returns {string} The output string in camel case.
|
|
5
|
-
*/
|
|
6
|
-
export const underscoreToCamelCase = (value) => {
|
|
7
|
-
return value.replaceAll(/(_\w)/g, (m) => {
|
|
8
|
-
return m[1].toUpperCase();
|
|
9
|
-
});
|
|
10
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { underscoreToCamelCase } from './underscoreToCamelCase.js';
|
|
2
|
-
|
|
3
|
-
test('Converts underscore to camelCase', () => {
|
|
4
|
-
expect(underscoreToCamelCase('test')).toBe('test');
|
|
5
|
-
expect(underscoreToCamelCase('test_variable')).toBe('testVariable');
|
|
6
|
-
expect(underscoreToCamelCase('test_variable_name')).toBe('testVariableName');
|
|
7
|
-
});
|
package/typedefs/global.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"addLeadingZero.d.ts","sourceRoot":"","sources":["../../src/util/addLeadingZero.js"],"names":[],"mappings":"AAMO,sCAJI,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,SAClC,MAAM,GACJ,MAAM,GAAG,IAAI,CAWzB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"capitalize.d.ts","sourceRoot":"","sources":["../../src/util/capitalize.js"],"names":[],"mappings":"AAKO,kCAHI,MAAM,GAAG,IAAI,GAAG,SAAS,GACvB,MAAM,GAAG,IAAI,CAWzB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deepMerge.d.ts","sourceRoot":"","sources":["../../src/util/deepMerge.js"],"names":[],"mappings":"AAMO,kCAJI,MAAM,UACN,MAAM,GACJ,MAAM,CAmBlB"}
|
package/types/util/deg2rad.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deg2rad.d.ts","sourceRoot":"","sources":["../../src/util/deg2rad.js"],"names":[],"mappings":"AAKO,6BAHI,MAAM,GACJ,MAAM,CAIlB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delayPromise.d.ts","sourceRoot":"","sources":["../../src/util/delayPromise.js"],"names":[],"mappings":"AAKO,sCAHI,MAAM,GACJ,OAAO,CAAC,IAAI,CAAC,CAEqE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetchRetry.d.ts","sourceRoot":"","sources":["../../src/util/fetchRetry.js"],"names":[],"mappings":"AAYA,yBAA0B,CAAC,CAAC;AAE5B;IACE;;;;;;OAMG;IACH,qBALW,MAAM,YACN,MAAM,GAAG,GAAG,GAAG,OAAO,gBACtB,WAAW,YACX,QAAQ,EAQlB;IAHC,iCAAwB;IACxB,0BAAgC;IAChC,mBAAwB;CAE3B;AASM,qCALI,MAAM,GAAG,GAAG,GAAG,OAAO,gBACtB,WAAW,iBACX;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAC,GAC9E,OAAO,CAAC,QAAQ,CAAC,CAgD7B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fixFloatPrecision.d.ts","sourceRoot":"","sources":["../../src/util/fixFloatPrecision.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,yCAHW,MAAM,GACJ,MAAM,CAYlB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getErrorDetails.d.ts","sourceRoot":"","sources":["../../src/util/getErrorDetails.js"],"names":[],"mappings":"AAMO,uCAJI,KAAK,aACL,MAAM,EAAE,GACN,MAAM,CAmBlB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getObjArrayPropSum.d.ts","sourceRoot":"","sources":["../../src/util/getObjArrayPropSum.js"],"names":[],"mappings":"AAMO,wCAJI,MAAM,EAAE,QACR,MAAM,GACJ,MAAM,CAMlB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getObjValueByPath.d.ts","sourceRoot":"","sources":["../../src/util/getObjValueByPath.js"],"names":[],"mappings":"AAMO,uCAJI,MAAM,QACN,MAAM,GACJ,MAAM,GAAG,IAAI,CAezB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getRandomInt.d.ts","sourceRoot":"","sources":["../../src/util/getRandomInt.js"],"names":[],"mappings":"AAMO,kCAJI,MAAM,OACN,MAAM,GACJ,MAAM,CAIlB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getURLParam.d.ts","sourceRoot":"","sources":["../../src/util/getURLParam.js"],"names":[],"mappings":"AAYO,4BANM,CAAC,OACH,MAAM,iBACN,CAAC,eACD,OAAO,GACL,MAAM,GAAG,CAAC,CAWtB"}
|
package/types/util/loadJSON.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"loadJSON.d.ts","sourceRoot":"","sources":["../../src/util/loadJSON.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,8BAHW,MAAM,GACJ,OAAO,CAAC,MAAM,CAAC,CAM3B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"purgeObject.d.ts","sourceRoot":"","sources":["../../src/util/purgeObject.js"],"names":[],"mappings":"AAIO,oCAFI,MAAM,QAUhB"}
|