@3dsource/utils 1.0.3 → 1.0.5
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/fesm2022/3dsource-utils.mjs +1793 -0
- package/fesm2022/3dsource-utils.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/{src/lib/color/CMYKtoRGB.ts → lib/color/CMYKtoRGB.d.ts} +1 -11
- package/lib/color/HEXtoRGB.d.ts +5 -0
- package/lib/color/HSVtoRGB.d.ts +21 -0
- package/{src/lib/color/RGBtoCMYK.ts → lib/color/RGBtoCMYK.d.ts} +1 -31
- package/lib/color/RGBtoHEX.d.ts +1 -0
- package/lib/color/RGBtoHSV.d.ts +19 -0
- package/lib/color/hsv.d.ts +1 -0
- package/lib/color/max.d.ts +1 -0
- package/lib/color/min.d.ts +1 -0
- package/lib/color/overlay.d.ts +1 -0
- package/{src/lib/color/rgb.ts → lib/color/rgb.d.ts} +1 -3
- package/lib/color/sub.d.ts +1 -0
- package/lib/color/subtract.d.ts +1 -0
- package/lib/color/sum.d.ts +1 -0
- package/{src/lib/color/toRGB.ts → lib/color/toRGB.d.ts} +1 -7
- package/lib/color/toRGBA.d.ts +1 -0
- package/lib/constants/color-codes.constant.d.ts +9 -0
- package/lib/csv/CSV2Array.d.ts +1 -0
- package/lib/csv/CSV2Records.d.ts +1 -0
- package/lib/csv/ObjectToCSV.d.ts +1 -0
- package/lib/dev/dev3d.d.ts +1 -0
- package/lib/dev/logger.d.ts +11 -0
- package/lib/dev/timeToString.d.ts +5 -0
- package/lib/filenaming/cleanupFileName.d.ts +1 -0
- package/lib/filenaming/makePath.d.ts +1 -0
- package/lib/filenaming/normalizePath.d.ts +1 -0
- package/lib/geom/expandOverRectangle.d.ts +2 -0
- package/lib/geom/fitIntoRectangle.d.ts +2 -0
- package/{src/lib/geom/interfaces/area.interface.ts → lib/geom/interfaces/area.interface.d.ts} +1 -2
- package/{src/lib/geom/interfaces/rect.interface.ts → lib/geom/interfaces/rect.interface.d.ts} +2 -2
- package/lib/geom/interfaces/size.interface.d.ts +4 -0
- package/lib/geom/interfaces//321/201oords.interface.d.ts +4 -0
- package/lib/helpers/BatchLoader.d.ts +47 -0
- package/lib/helpers/KeyboardNumericCode.d.ts +103 -0
- package/lib/helpers/serialize.d.ts +1 -0
- package/lib/helpers/sleep.d.ts +1 -0
- package/lib/helpers/trimLastSlashFromUrl.d.ts +1 -0
- package/lib/image/SaveImage.d.ts +18 -0
- package/lib/image/getCanvasCached.d.ts +4 -0
- package/lib/image/getSnapshot.d.ts +2 -0
- package/lib/image/loadImage.d.ts +1 -0
- package/lib/interfaces/image-output.d.ts +7 -0
- package/{src/lib/interfaces/load-args-tmp.interface.ts → lib/interfaces/load-args-tmp.interface.d.ts} +1 -2
- package/lib/interfaces/load-args.interface.d.ts +15 -0
- package/{src/lib/math/baseSortedIndex.ts → lib/math/baseSortedIndex.d.ts} +1 -19
- package/{src/lib/math/calculateMedian.ts → lib/math/calculateMedian.d.ts} +1 -17
- package/{src/lib/math/circularIndex.ts → lib/math/circularIndex.d.ts} +1 -5
- package/lib/math/clampf.d.ts +8 -0
- package/lib/math/degrees.d.ts +2 -0
- package/{src/lib/math/floatCompare.ts → lib/math/floatCompare.d.ts} +3 -30
- package/{src/lib/math/inverseLerp.ts → lib/math/inverseLerp.d.ts} +1 -22
- package/lib/math/lerp.d.ts +7 -0
- package/{src/lib/mutex/Mutex.ts → lib/mutex/Mutex.d.ts} +8 -15
- package/{src/lib/mutex/Semaphore.ts → lib/mutex/Semaphore.d.ts} +7 -27
- package/lib/mutex/TaskRunner.d.ts +5 -0
- package/lib/predicates/BooleanPredictors.d.ts +27 -0
- package/{src/lib/predicates/textForSearch.ts → lib/predicates/textForSearch.d.ts} +1 -17
- package/{src/lib/predicates/where.ts → lib/predicates/where.d.ts} +2 -32
- package/lib/rxjs/leadingTrailingDebounceTime.d.ts +15 -0
- package/{src/lib/rxjs/smoothTransition.ts → lib/rxjs/smoothTransition.d.ts} +1 -19
- package/lib/rxjs/tapLog.d.ts +2 -0
- package/lib/strings/pad.d.ts +8 -0
- package/package.json +13 -2
- package/eslint.config.js +0 -37
- package/ng-package.json +0 -7
- package/src/lib/color/HEXtoRGB.ts +0 -9
- package/src/lib/color/HSVtoRGB.ts +0 -82
- package/src/lib/color/RGBtoHEX.ts +0 -17
- package/src/lib/color/RGBtoHSV.ts +0 -53
- package/src/lib/color/hsv.ts +0 -14
- package/src/lib/color/max.ts +0 -18
- package/src/lib/color/min.ts +0 -18
- package/src/lib/color/overlay.ts +0 -25
- package/src/lib/color/sub.ts +0 -18
- package/src/lib/color/subtract.ts +0 -27
- package/src/lib/color/sum.ts +0 -19
- package/src/lib/color/toRGBA.ts +0 -8
- package/src/lib/constants/color-codes.constant.ts +0 -9
- package/src/lib/csv/CSV2Array.ts +0 -66
- package/src/lib/csv/CSV2Records.ts +0 -56
- package/src/lib/csv/ObjectToCSV.ts +0 -21
- package/src/lib/csv/test/Csv.spec.ts +0 -51
- package/src/lib/dev/dev3d.ts +0 -1
- package/src/lib/dev/logger.ts +0 -94
- package/src/lib/dev/timeToString.ts +0 -16
- package/src/lib/filenaming/cleanupFileName.ts +0 -18
- package/src/lib/filenaming/makePath.ts +0 -5
- package/src/lib/filenaming/normalizePath.ts +0 -9
- package/src/lib/filenaming/test/cleanupFileName.spec.ts +0 -9
- package/src/lib/filenaming/test/makePath.spec.ts +0 -7
- package/src/lib/filenaming/test/normalizePath.spec.ts +0 -9
- package/src/lib/geom/expandOverRectangle.ts +0 -17
- package/src/lib/geom/fitIntoRectangle.ts +0 -43
- package/src/lib/geom/interfaces/size.interface.ts +0 -4
- package/src/lib/geom/interfaces//321/201oords.interface.ts +0 -4
- package/src/lib/geom/test/fitRectangle.spec.ts +0 -54
- package/src/lib/helpers/BatchLoader.ts +0 -243
- package/src/lib/helpers/KeyboardNumericCode.ts +0 -118
- package/src/lib/helpers/serialize.ts +0 -11
- package/src/lib/helpers/sleep.ts +0 -3
- package/src/lib/helpers/test/sleep.spec.ts +0 -11
- package/src/lib/helpers/trimLastSlashFromUrl.ts +0 -9
- package/src/lib/image/SaveImage.ts +0 -65
- package/src/lib/image/getCanvasCached.ts +0 -16
- package/src/lib/image/getSnapshot.ts +0 -99
- package/src/lib/image/loadImage.ts +0 -13
- package/src/lib/interfaces/image-output.ts +0 -8
- package/src/lib/interfaces/load-args.interface.ts +0 -15
- package/src/lib/math/clampf.ts +0 -14
- package/src/lib/math/degrees.ts +0 -7
- package/src/lib/math/lerp.ts +0 -12
- package/src/lib/math/test/baseSortedIndex.spec.ts +0 -43
- package/src/lib/math/test/circularIndex.spec.ts +0 -38
- package/src/lib/mutex/TaskRunner.ts +0 -26
- package/src/lib/predicates/BooleanPredictors.ts +0 -47
- package/src/lib/predicates/test/BooleanPredictors.spec.ts +0 -71
- package/src/lib/predicates/test/where.spec.ts +0 -94
- package/src/lib/rxjs/leadingTrailingDebounceTime.ts +0 -86
- package/src/lib/rxjs/tapLog.ts +0 -13
- package/src/lib/strings/pad.ts +0 -18
- package/tsconfig.lib.json +0 -13
- package/tsconfig.lib.prod.json +0 -11
- /package/{src/lib/color/index.ts → lib/color/index.d.ts} +0 -0
- /package/{src/lib/constants/index.ts → lib/constants/index.d.ts} +0 -0
- /package/{src/lib/csv/index.ts → lib/csv/index.d.ts} +0 -0
- /package/{src/lib/dev/index.ts → lib/dev/index.d.ts} +0 -0
- /package/{src/lib/filenaming/index.ts → lib/filenaming/index.d.ts} +0 -0
- /package/{src/lib/geom/index.ts → lib/geom/index.d.ts} +0 -0
- /package/{src/lib/geom/interfaces/index.ts → lib/geom/interfaces/index.d.ts} +0 -0
- /package/{src/lib/helpers/index.ts → lib/helpers/index.d.ts} +0 -0
- /package/{src/lib/image/index.ts → lib/image/index.d.ts} +0 -0
- /package/{src/lib/interfaces/index.ts → lib/interfaces/index.d.ts} +0 -0
- /package/{src/lib/math/index.ts → lib/math/index.d.ts} +0 -0
- /package/{src/lib/mutex/index.ts → lib/mutex/index.d.ts} +0 -0
- /package/{src/lib/predicates/index.ts → lib/predicates/index.d.ts} +0 -0
- /package/{src/lib/rxjs/index.ts → lib/rxjs/index.d.ts} +0 -0
- /package/{src/lib/strings/index.ts → lib/strings/index.d.ts} +0 -0
- /package/{src/public-api.ts → public-api.d.ts} +0 -0
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { fitIntoRectangle } from '../geom';
|
|
2
|
-
import type { ImageOutputValues } from '../interfaces';
|
|
3
|
-
|
|
4
|
-
function getSnapshot2(
|
|
5
|
-
imageElement:
|
|
6
|
-
| HTMLImageElement
|
|
7
|
-
| HTMLCanvasElement
|
|
8
|
-
| HTMLVideoElement
|
|
9
|
-
| ImageBitmap,
|
|
10
|
-
maxWidth = 1024,
|
|
11
|
-
output: ImageOutputValues = 'image/png',
|
|
12
|
-
quality = 0.9,
|
|
13
|
-
): HTMLCanvasElement | string {
|
|
14
|
-
const drawableImage = imageElement as any;
|
|
15
|
-
const canvasHelper: HTMLCanvasElement = document.createElement('canvas');
|
|
16
|
-
const drawCTX: CanvasRenderingContext2D = canvasHelper.getContext(
|
|
17
|
-
'2d',
|
|
18
|
-
) as CanvasRenderingContext2D;
|
|
19
|
-
|
|
20
|
-
const prop = fitIntoRectangle(
|
|
21
|
-
{
|
|
22
|
-
x: 0,
|
|
23
|
-
y: 0,
|
|
24
|
-
w: drawableImage.naturalWidth || drawableImage.width,
|
|
25
|
-
h: drawableImage.naturalHeight || drawableImage.height,
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
x: 0,
|
|
29
|
-
y: 0,
|
|
30
|
-
w: maxWidth,
|
|
31
|
-
h: drawableImage.naturalHeight || drawableImage.height,
|
|
32
|
-
},
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
const width = prop.w;
|
|
36
|
-
const height = prop.h;
|
|
37
|
-
canvasHelper.width = width;
|
|
38
|
-
canvasHelper.height = height;
|
|
39
|
-
|
|
40
|
-
drawCTX.save();
|
|
41
|
-
drawCTX.clearRect(0, 0, width, height);
|
|
42
|
-
drawCTX.drawImage(drawableImage, 0, 0, width, height);
|
|
43
|
-
drawCTX.restore();
|
|
44
|
-
|
|
45
|
-
if (output === 'canvas') {
|
|
46
|
-
return canvasHelper;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return canvasHelper.toDataURL(output, quality);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function getSnapshot(
|
|
53
|
-
imageElement:
|
|
54
|
-
| HTMLImageElement
|
|
55
|
-
| HTMLCanvasElement
|
|
56
|
-
| HTMLVideoElement
|
|
57
|
-
| ImageBitmap,
|
|
58
|
-
maxWidth = 1024,
|
|
59
|
-
output: ImageOutputValues = 'image/png',
|
|
60
|
-
quality = 0.9,
|
|
61
|
-
): HTMLCanvasElement | string {
|
|
62
|
-
const drawableImage = imageElement as any;
|
|
63
|
-
const canvasHelper: HTMLCanvasElement = document.createElement('canvas');
|
|
64
|
-
const drawCTX: CanvasRenderingContext2D = canvasHelper.getContext(
|
|
65
|
-
'2d',
|
|
66
|
-
) as CanvasRenderingContext2D;
|
|
67
|
-
|
|
68
|
-
const prop = fitIntoRectangle(
|
|
69
|
-
{
|
|
70
|
-
x: 0,
|
|
71
|
-
y: 0,
|
|
72
|
-
w: drawableImage.naturalWidth || drawableImage.width,
|
|
73
|
-
h: drawableImage.naturalHeight || drawableImage.height,
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
x: 0,
|
|
77
|
-
y: 0,
|
|
78
|
-
w: (drawableImage.naturalWidth || drawableImage.width) / 2,
|
|
79
|
-
h: drawableImage.naturalHeight || drawableImage.height,
|
|
80
|
-
},
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
const width = prop.w;
|
|
84
|
-
const height = prop.h;
|
|
85
|
-
canvasHelper.width = width;
|
|
86
|
-
canvasHelper.height = height;
|
|
87
|
-
|
|
88
|
-
drawCTX.save();
|
|
89
|
-
drawCTX.clearRect(0, 0, width, height);
|
|
90
|
-
drawCTX.drawImage(drawableImage, 0, 0, width, height);
|
|
91
|
-
|
|
92
|
-
drawCTX.restore();
|
|
93
|
-
|
|
94
|
-
if (width > maxWidth * 2) {
|
|
95
|
-
return getSnapshot(canvasHelper, maxWidth, output, quality);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return getSnapshot2(drawableImage, maxWidth, output, quality);
|
|
99
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export function loadImage(url: string): Promise<HTMLImageElement> {
|
|
2
|
-
return new Promise((resolve: any, reject) => {
|
|
3
|
-
const img = new Image();
|
|
4
|
-
img.crossOrigin = 'anonymous';
|
|
5
|
-
img.onload = () => {
|
|
6
|
-
setTimeout(() => resolve(img), 1);
|
|
7
|
-
};
|
|
8
|
-
img.onerror = () => {
|
|
9
|
-
setTimeout(() => reject(null), 1);
|
|
10
|
-
};
|
|
11
|
-
img.src = url;
|
|
12
|
-
});
|
|
13
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export interface LoadArgs {
|
|
2
|
-
order: number;
|
|
3
|
-
extra: any;
|
|
4
|
-
item?: HTMLImageElement;
|
|
5
|
-
useXhr?: boolean;
|
|
6
|
-
path: string;
|
|
7
|
-
onLoadEnd: (data: LoadArgs) => void;
|
|
8
|
-
onLoadStart: (data: ProgressEvent) => void;
|
|
9
|
-
onProgress: (data: ProgressEvent) => void;
|
|
10
|
-
id?: string;
|
|
11
|
-
img?: HTMLImageElement;
|
|
12
|
-
error?: boolean;
|
|
13
|
-
fallBack?: string;
|
|
14
|
-
resolutionId: number | string | null;
|
|
15
|
-
}
|
package/src/lib/math/clampf.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Clamps value between min and max;
|
|
3
|
-
* @param min minValue
|
|
4
|
-
* @param max maxValue
|
|
5
|
-
* @param value inputValue
|
|
6
|
-
* @returns number
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export function clampf(min: number, max: number, value: number): number {
|
|
10
|
-
if (min > max) {
|
|
11
|
-
return min;
|
|
12
|
-
}
|
|
13
|
-
return Math.min(max, Math.max(min, value));
|
|
14
|
-
}
|
package/src/lib/math/degrees.ts
DELETED
package/src/lib/math/lerp.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { clampf } from './clampf';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @param min minimums
|
|
5
|
-
* @param max maximums
|
|
6
|
-
* @param value current float value in 0-1 range
|
|
7
|
-
* @returns clamped value
|
|
8
|
-
*/
|
|
9
|
-
export function lerp(min: number, max: number, value: number): number {
|
|
10
|
-
value = clampf(0, 1, value);
|
|
11
|
-
return value * (max - min) + min;
|
|
12
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { baseSortedIndex } from '../baseSortedIndex';
|
|
2
|
-
|
|
3
|
-
describe('baseSortedIndex', () => {
|
|
4
|
-
it('should return the correct insertion index in a sorted array', () => {
|
|
5
|
-
const array = [10, 20, 30, 40, 50];
|
|
6
|
-
const value = 35;
|
|
7
|
-
const index = baseSortedIndex(array, value);
|
|
8
|
-
expect(index).toBe(3); // 35 should be inserted at index 3 to maintain sorted order
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it('should handle empty arrays', () => {
|
|
12
|
-
const array: number[] = [];
|
|
13
|
-
const value = 10;
|
|
14
|
-
const index = baseSortedIndex(array, value);
|
|
15
|
-
expect(index).toBe(0); // In an empty array, the insertion index is always 0
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('should place value at the start if less than all elements', () => {
|
|
19
|
-
const array = [10, 20, 30, 40, 50];
|
|
20
|
-
const value = 5;
|
|
21
|
-
const index = baseSortedIndex(array, value);
|
|
22
|
-
expect(index).toBe(0); // 5 should be inserted at index 0
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('should place value at the end if greater than all elements', () => {
|
|
26
|
-
const array = [10, 20, 30, 40, 50];
|
|
27
|
-
const value = 60;
|
|
28
|
-
const index = baseSortedIndex(array, value);
|
|
29
|
-
expect(index).toBe(5); // 60 should be inserted at index 5, which is the array's length
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('should handle arrays with the maximum safe size', () => {
|
|
33
|
-
// Assuming a simplified scenario for demonstration, as actually filling an array to max length would be impractical
|
|
34
|
-
const array = [1, 2]; // Simulate a sorted array
|
|
35
|
-
const value = 2;
|
|
36
|
-
// Manually set the array length to mimic a large array scenario
|
|
37
|
-
Object.defineProperty(array, 'length', { value: Math.pow(2, 31) - 1 });
|
|
38
|
-
const index = baseSortedIndex(array, value);
|
|
39
|
-
// The expected index would depend on the actual implementation and purpose of handling large arrays
|
|
40
|
-
// For this example, we'll assume it should return the position based on the 'value' in a sorted array logic
|
|
41
|
-
expect(index).not.toBeUndefined(); // Adjust this based on the actual intended behavior for large arrays
|
|
42
|
-
});
|
|
43
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { circularIndex } from '../circularIndex';
|
|
2
|
-
|
|
3
|
-
describe('circularIndex', () => {
|
|
4
|
-
it('should return 0', () => {
|
|
5
|
-
expect(circularIndex(5, 5)).toBe(0);
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
it('should return 1', () => {
|
|
9
|
-
expect(circularIndex(6, 5)).toBe(1);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('should return 4', () => {
|
|
13
|
-
expect(circularIndex(-1, 5)).toBe(4);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('should return 3', () => {
|
|
17
|
-
expect(circularIndex(-2, 5)).toBe(3);
|
|
18
|
-
});
|
|
19
|
-
it('should return 4', () => {
|
|
20
|
-
expect(circularIndex(-6, 5)).toBe(4);
|
|
21
|
-
});
|
|
22
|
-
it('should return 1', () => {
|
|
23
|
-
expect(circularIndex(11, 5)).toBe(1);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('should return 0', () => {
|
|
27
|
-
expect(circularIndex(1, 1)).toBe(0);
|
|
28
|
-
});
|
|
29
|
-
it('should return 0', () => {
|
|
30
|
-
expect(circularIndex(2, 1)).toBe(0);
|
|
31
|
-
});
|
|
32
|
-
it('should return 0', () => {
|
|
33
|
-
expect(circularIndex(-2, 1)).toBe(0);
|
|
34
|
-
});
|
|
35
|
-
it('should return 0', () => {
|
|
36
|
-
expect(circularIndex(10, 0)).toBe(0);
|
|
37
|
-
});
|
|
38
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { Observable } from 'rxjs';
|
|
2
|
-
import { finalize, from, switchMap } from 'rxjs';
|
|
3
|
-
import { Logger } from '../dev';
|
|
4
|
-
import { Mutex } from './Mutex';
|
|
5
|
-
|
|
6
|
-
export class TaskRunner {
|
|
7
|
-
private mutex = new Mutex();
|
|
8
|
-
|
|
9
|
-
runTask(name: string, task: () => Observable<string | null>) {
|
|
10
|
-
// Log that the task is waiting to acquire the mutex
|
|
11
|
-
Logger.log(`${name} waiting to acquire mutex`);
|
|
12
|
-
|
|
13
|
-
return from(this.mutex.acquire()).pipe(
|
|
14
|
-
switchMap((release) => {
|
|
15
|
-
// Log that the mutex has been acquired
|
|
16
|
-
Logger.log(`${name} acquired mutex`);
|
|
17
|
-
return task().pipe(
|
|
18
|
-
finalize(() => {
|
|
19
|
-
Logger.log(`${name} releasing mutex`);
|
|
20
|
-
release();
|
|
21
|
-
}),
|
|
22
|
-
);
|
|
23
|
-
}),
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
type TruthyTypesOf<T> = T extends false | '' | 0 | null | undefined ? never : T;
|
|
2
|
-
type FalsyTypesOf<T> = T extends false | '' | 0 | null | undefined ? T : never;
|
|
3
|
-
type EmptyTypesOf<T> = T extends undefined | null | object | '' ? T : never;
|
|
4
|
-
type NonEmptyTypesOf<T> = T extends undefined | null | object | '' ? never : T;
|
|
5
|
-
/**
|
|
6
|
-
* The Boolean object represents a truth value: true or false.
|
|
7
|
-
* @param value
|
|
8
|
-
* @constructor
|
|
9
|
-
* Returns:boolean
|
|
10
|
-
*/
|
|
11
|
-
export const Truthy: <T>(value: T) => value is TruthyTypesOf<T> = <T>(
|
|
12
|
-
value?: T,
|
|
13
|
-
): value is TruthyTypesOf<T> =>
|
|
14
|
-
!!value && value !== 'false' && value !== 'undefined' && value !== 'null';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* The Boolean object represents a INVERSE truth value: true or false.
|
|
18
|
-
* @param value
|
|
19
|
-
* @constructor
|
|
20
|
-
* Returns:boolean
|
|
21
|
-
*/
|
|
22
|
-
export const Falsy: <T>(value: T) => value is FalsyTypesOf<T> = <T>(
|
|
23
|
-
value?: T,
|
|
24
|
-
): value is FalsyTypesOf<T> => !Truthy(value);
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Checks if a value is empty.
|
|
28
|
-
*
|
|
29
|
-
* @param {any} value - The value to check.
|
|
30
|
-
* @return {boolean} Returns true if the value is empty, otherwise false.
|
|
31
|
-
*/
|
|
32
|
-
export const IsEmpty: <T>(value: T) => value is EmptyTypesOf<T> = <T>(
|
|
33
|
-
value: T,
|
|
34
|
-
): value is EmptyTypesOf<T> => {
|
|
35
|
-
return (
|
|
36
|
-
value === undefined ||
|
|
37
|
-
value === null ||
|
|
38
|
-
(typeof value === 'object' && Object.keys(value).length === 0) ||
|
|
39
|
-
(typeof value === 'string' && value.trim().length === 0)
|
|
40
|
-
);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export const NotEmpty: <T>(value: T) => value is NonEmptyTypesOf<T> = <T>(
|
|
44
|
-
value: T,
|
|
45
|
-
): value is NonEmptyTypesOf<T> => {
|
|
46
|
-
return !IsEmpty(value);
|
|
47
|
-
};
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { Falsy, IsEmpty, Truthy } from '../BooleanPredictors';
|
|
2
|
-
|
|
3
|
-
describe('Truthy function', () => {
|
|
4
|
-
it('should return true for truthy values', () => {
|
|
5
|
-
expect(Truthy(true)).toBeTruthy();
|
|
6
|
-
expect(Truthy('true')).toBeTruthy();
|
|
7
|
-
expect(Truthy(1)).toBeTruthy();
|
|
8
|
-
expect(Truthy('non-empty')).toBeTruthy();
|
|
9
|
-
expect(Truthy({ key: 'value' })).toBeTruthy();
|
|
10
|
-
expect(Truthy([1, 2, 3])).toBeTruthy();
|
|
11
|
-
expect(Truthy([])).toBeTruthy();
|
|
12
|
-
expect(Truthy({})).toBeTruthy();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should return false for falsy values', () => {
|
|
16
|
-
expect(Truthy('undefined')).toBeFalsy();
|
|
17
|
-
expect(Truthy(undefined)).toBeFalsy();
|
|
18
|
-
expect(Truthy(null)).toBeFalsy();
|
|
19
|
-
expect(Truthy('null')).toBeFalsy();
|
|
20
|
-
expect(Truthy('false')).toBeFalsy();
|
|
21
|
-
expect(Truthy(false)).toBeFalsy();
|
|
22
|
-
expect(Truthy(0)).toBeFalsy();
|
|
23
|
-
expect(Truthy(-0)).toBeFalsy();
|
|
24
|
-
expect(Truthy(-0)).toBeFalsy();
|
|
25
|
-
expect(Truthy(NaN)).toBeFalsy();
|
|
26
|
-
expect(Truthy('')).toBeFalsy();
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe('Falsy function', () => {
|
|
31
|
-
it('should return false for truthy values', () => {
|
|
32
|
-
expect(Falsy(1)).toBeFalsy();
|
|
33
|
-
expect(Falsy('non-empty')).toBeFalsy();
|
|
34
|
-
expect(Falsy({ key: 'value' })).toBeFalsy();
|
|
35
|
-
expect(Falsy([1, 2, 3])).toBeFalsy();
|
|
36
|
-
expect(Falsy([])).toBeFalsy();
|
|
37
|
-
expect(Falsy({})).toBeFalsy();
|
|
38
|
-
expect(Falsy('true')).toBeFalsy();
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('should return true for falsy values', () => {
|
|
42
|
-
expect(Falsy('false')).toBeTruthy();
|
|
43
|
-
expect(Falsy('undefined')).toBeTruthy();
|
|
44
|
-
expect(Falsy('null')).toBeTruthy();
|
|
45
|
-
expect(Falsy(false)).toBeTruthy();
|
|
46
|
-
expect(Falsy(undefined)).toBeTruthy();
|
|
47
|
-
expect(Falsy(null)).toBeTruthy();
|
|
48
|
-
expect(Falsy(0)).toBeTruthy();
|
|
49
|
-
expect(Falsy(-0)).toBeTruthy();
|
|
50
|
-
expect(Falsy(-0)).toBeTruthy();
|
|
51
|
-
expect(Falsy(NaN)).toBeTruthy();
|
|
52
|
-
expect(Falsy('')).toBeTruthy();
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe('IsEmpty function', () => {
|
|
57
|
-
it('should return true for empty values', () => {
|
|
58
|
-
expect(IsEmpty('')).toBeTruthy();
|
|
59
|
-
expect(IsEmpty(' ')).toBeTruthy();
|
|
60
|
-
expect(IsEmpty(null)).toBeTruthy();
|
|
61
|
-
expect(IsEmpty(undefined)).toBeTruthy();
|
|
62
|
-
expect(IsEmpty({})).toBeTruthy();
|
|
63
|
-
expect(IsEmpty([])).toBeTruthy();
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('should return false for non-empty values', () => {
|
|
67
|
-
expect(IsEmpty('non-empty')).toBeFalsy();
|
|
68
|
-
expect(IsEmpty({ key: 'value' })).toBeFalsy();
|
|
69
|
-
expect(IsEmpty([1])).toBeFalsy();
|
|
70
|
-
});
|
|
71
|
-
});
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
// Mocking the textForSearch if necessary, or import if available
|
|
2
|
-
import { where, whereNot } from '../where';
|
|
3
|
-
|
|
4
|
-
describe('where', () => {
|
|
5
|
-
it('should filter records based on a single criteria match', () => {
|
|
6
|
-
const records = [{ name: 'John Doe' }, { name: 'Jane Doe' }];
|
|
7
|
-
const criteria = { name: 'John Doe' };
|
|
8
|
-
const filter = where(criteria);
|
|
9
|
-
expect(records.filter(filter)).toEqual([{ name: 'John Doe' }]);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('should be case sensitive when specified', () => {
|
|
13
|
-
const records = [{ name: 'john doe' }, { name: 'Jane Doe' }];
|
|
14
|
-
const criteria = { name: 'John Doe' };
|
|
15
|
-
const filter = where(criteria, true);
|
|
16
|
-
expect(records.filter(filter)).toEqual([]);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('should handle multiple criteria', () => {
|
|
20
|
-
const records = [
|
|
21
|
-
{ name: 'John Doe', age: 30 },
|
|
22
|
-
{ name: 'Jane Doe', age: 25 },
|
|
23
|
-
];
|
|
24
|
-
const criteria = { name: 'Jane Doe', age: 25 };
|
|
25
|
-
const filter = where(criteria);
|
|
26
|
-
expect(records.filter(filter)).toEqual([{ name: 'Jane Doe', age: 25 }]);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('should return empty array if criteria is empty', () => {
|
|
30
|
-
const records = [{ name: 'John Doe' }, { name: 'Jane Doe' }];
|
|
31
|
-
const criteria = {};
|
|
32
|
-
const filter = where(criteria);
|
|
33
|
-
expect(records.filter(filter)).toEqual([]);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should handle non-string values correctly', () => {
|
|
37
|
-
const records = [{ age: 20 }, { age: 30 }];
|
|
38
|
-
const criteria = { age: 20 };
|
|
39
|
-
const filter = where(criteria);
|
|
40
|
-
expect(records.filter(filter)).toEqual([{ age: 20 }]);
|
|
41
|
-
});
|
|
42
|
-
it('should handle undefined values correctly', () => {
|
|
43
|
-
const records = [{ age: 20 }, { age: 30 }];
|
|
44
|
-
const criteria = { age: undefined };
|
|
45
|
-
const filter = where(criteria);
|
|
46
|
-
expect(records.filter(filter)).toEqual([]);
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
describe('whereNot', () => {
|
|
51
|
-
it('should filter records not matching the criteria', () => {
|
|
52
|
-
const records = [{ name: 'John Doe' }, { name: 'Jane Doe' }];
|
|
53
|
-
const criteria = { name: 'john doe' };
|
|
54
|
-
const filter = whereNot(criteria);
|
|
55
|
-
expect(records.filter(filter)).toEqual([{ name: 'Jane Doe' }]);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('should filter records not matching the criteria', () => {
|
|
59
|
-
const records = [{ name: 'John Doe' }, { name: 'Jane Doe' }];
|
|
60
|
-
const criteria = { name: 'john Doe' };
|
|
61
|
-
const filter = whereNot(criteria, true);
|
|
62
|
-
expect(records.filter(filter)).toEqual([
|
|
63
|
-
{ name: 'John Doe' },
|
|
64
|
-
{ name: 'Jane Doe' },
|
|
65
|
-
]);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('should respect case sensitivity', () => {
|
|
69
|
-
const records = [{ name: 'john doe' }, { name: 'Jane Doe' }];
|
|
70
|
-
const criteria = { name: 'Jane Doe' };
|
|
71
|
-
const filter = whereNot(criteria);
|
|
72
|
-
expect(records.filter(filter)).toEqual([{ name: 'john doe' }]);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('should process empty values', () => {
|
|
76
|
-
const records = [{ name: 'john doe' }, { name: 'Jane Doe' }];
|
|
77
|
-
const criteria = { name: undefined };
|
|
78
|
-
const filter = whereNot(criteria);
|
|
79
|
-
expect(records.filter(filter)).toEqual([
|
|
80
|
-
{ name: 'john doe' },
|
|
81
|
-
{ name: 'Jane Doe' },
|
|
82
|
-
]);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('should process empty values', () => {
|
|
86
|
-
const records = [{ name: 'john doe' }, { name: 'Jane Doe' }];
|
|
87
|
-
const criteria = {};
|
|
88
|
-
const filter = whereNot(criteria);
|
|
89
|
-
expect(records.filter(filter)).toEqual([
|
|
90
|
-
{ name: 'john doe' },
|
|
91
|
-
{ name: 'Jane Doe' },
|
|
92
|
-
]);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import type { SchedulerLike, Subscriber, Subscription } from 'rxjs';
|
|
2
|
-
import { asyncScheduler, Observable, timer } from 'rxjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Emits the most recent value emitted by the source Observable after a
|
|
6
|
-
* specified time span has passed without another source emission.
|
|
7
|
-
*
|
|
8
|
-
* This is a combination of `debounceTime` and `auditTime` operators.
|
|
9
|
-
*
|
|
10
|
-
* The leading value is emitted immediately, and trailing values are debounced.
|
|
11
|
-
*
|
|
12
|
-
* @param dueTime The time to wait before emitting the last value.
|
|
13
|
-
* @param scheduler The scheduler to use for the timeout.
|
|
14
|
-
* @returns A function that returns an Observable that mirrors the source Observable, but applies the specified debouncing.
|
|
15
|
-
*/
|
|
16
|
-
export function leadingTrailingDebounceTime<T>(
|
|
17
|
-
dueTime: number,
|
|
18
|
-
scheduler: SchedulerLike = asyncScheduler,
|
|
19
|
-
): (source: Observable<T>) => Observable<T> {
|
|
20
|
-
return (source: Observable<T>) =>
|
|
21
|
-
new Observable<T>((subscriber: Subscriber<T>) => {
|
|
22
|
-
let hasValue = false;
|
|
23
|
-
let lastValue: T | null = null;
|
|
24
|
-
let timerSubscription: Subscription | null = null;
|
|
25
|
-
let leading = true; // Controls whether we emit immediately.
|
|
26
|
-
|
|
27
|
-
const clearTimer = () => {
|
|
28
|
-
if (timerSubscription) {
|
|
29
|
-
timerSubscription.unsubscribe();
|
|
30
|
-
timerSubscription = null;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const resetValues = () => {
|
|
35
|
-
hasValue = false;
|
|
36
|
-
lastValue = null;
|
|
37
|
-
leading = true; // Reset so the next new value is immediate.
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const emitLastValue = () => {
|
|
41
|
-
if (hasValue && lastValue !== null) {
|
|
42
|
-
subscriber.next(lastValue);
|
|
43
|
-
resetValues();
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const sourceSubscription = source.subscribe({
|
|
48
|
-
next: (value) => {
|
|
49
|
-
// If we are "leading", emit immediately and switch leading off
|
|
50
|
-
if (leading) {
|
|
51
|
-
subscriber.next(value);
|
|
52
|
-
leading = false;
|
|
53
|
-
timerSubscription = timer(dueTime, scheduler).subscribe(() => {
|
|
54
|
-
resetValues();
|
|
55
|
-
clearTimer();
|
|
56
|
-
});
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Otherwise, save the value and start (or restart) timer
|
|
61
|
-
hasValue = true;
|
|
62
|
-
lastValue = value;
|
|
63
|
-
clearTimer();
|
|
64
|
-
timerSubscription = timer(dueTime, scheduler).subscribe(() => {
|
|
65
|
-
emitLastValue();
|
|
66
|
-
});
|
|
67
|
-
},
|
|
68
|
-
error: (err: unknown) => {
|
|
69
|
-
clearTimer();
|
|
70
|
-
subscriber.error(err);
|
|
71
|
-
},
|
|
72
|
-
complete: () => {
|
|
73
|
-
// If there is a pending emission, emit it before completing
|
|
74
|
-
clearTimer();
|
|
75
|
-
emitLastValue();
|
|
76
|
-
subscriber.complete();
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
// Cleanup logic
|
|
81
|
-
return () => {
|
|
82
|
-
clearTimer();
|
|
83
|
-
sourceSubscription.unsubscribe();
|
|
84
|
-
};
|
|
85
|
-
});
|
|
86
|
-
}
|
package/src/lib/rxjs/tapLog.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { tap } from 'rxjs/operators';
|
|
2
|
-
import type { Observable } from 'rxjs';
|
|
3
|
-
import { Logger } from '../dev';
|
|
4
|
-
import { COLOR_CODES } from '../constants';
|
|
5
|
-
|
|
6
|
-
export const tapLog =
|
|
7
|
-
<T>(text: string, ...args: any): ((source: Observable<T>) => Observable<T>) =>
|
|
8
|
-
(source: Observable<T>) =>
|
|
9
|
-
source.pipe(
|
|
10
|
-
tap((data) => {
|
|
11
|
-
Logger.colored(...COLOR_CODES.TAP_LOG, text, data, ...args);
|
|
12
|
-
}),
|
|
13
|
-
);
|
package/src/lib/strings/pad.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adds required number of symbols before input
|
|
3
|
-
* @param input input string
|
|
4
|
-
* @param size amount of total symbols
|
|
5
|
-
* @param symbol filler
|
|
6
|
-
* @returns string
|
|
7
|
-
*/
|
|
8
|
-
export function pad(
|
|
9
|
-
input: number | string,
|
|
10
|
-
size: number,
|
|
11
|
-
symbol = '0',
|
|
12
|
-
): string {
|
|
13
|
-
let s = input + '';
|
|
14
|
-
while (s.length < size) {
|
|
15
|
-
s = symbol + s;
|
|
16
|
-
}
|
|
17
|
-
return s.slice(-size);
|
|
18
|
-
}
|
package/tsconfig.lib.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
|
|
2
|
-
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
|
|
3
|
-
{
|
|
4
|
-
"extends": "../../../tsconfig.json",
|
|
5
|
-
"compilerOptions": {
|
|
6
|
-
"outDir": "../../../out-tsc/lib",
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"declarationMap": true,
|
|
9
|
-
"inlineSources": true,
|
|
10
|
-
"types": []
|
|
11
|
-
},
|
|
12
|
-
"exclude": ["**/*.spec.ts"]
|
|
13
|
-
}
|
package/tsconfig.lib.prod.json
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
|
|
2
|
-
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
|
|
3
|
-
{
|
|
4
|
-
"extends": "./tsconfig.lib.json",
|
|
5
|
-
"compilerOptions": {
|
|
6
|
-
"declarationMap": false
|
|
7
|
-
},
|
|
8
|
-
"angularCompilerOptions": {
|
|
9
|
-
"compilationMode": "partial"
|
|
10
|
-
}
|
|
11
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|