@3dsource/utils 1.0.2 → 1.0.4
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/package.json +1 -1
- package/src/lib/csv/test/Csv.spec.ts +0 -51
- 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/test/fitRectangle.spec.ts +0 -54
- package/src/lib/helpers/test/sleep.spec.ts +0 -11
- package/src/lib/math/test/baseSortedIndex.spec.ts +0 -43
- package/src/lib/math/test/circularIndex.spec.ts +0 -38
- package/src/lib/predicates/test/BooleanPredictors.spec.ts +0 -71
- package/src/lib/predicates/test/where.spec.ts +0 -94
package/package.json
CHANGED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { CSV2Records } from '@utils/csv/CSV2Records';
|
|
2
|
-
|
|
3
|
-
function generateMockCSV() {
|
|
4
|
-
const headers = '"name","age","isStudent"\n';
|
|
5
|
-
const mockData = [
|
|
6
|
-
{ name: 'Alice Johnson', age: 22, isStudent: true },
|
|
7
|
-
{ name: 'Bob Smith', age: 28, isStudent: false },
|
|
8
|
-
{ name: 'Charlie Brown', age: 19, isStudent: true },
|
|
9
|
-
];
|
|
10
|
-
|
|
11
|
-
const rows = mockData
|
|
12
|
-
.map((record) => `"${record.name}","${record.age}","${record.isStudent}"`)
|
|
13
|
-
.join('\n');
|
|
14
|
-
|
|
15
|
-
return headers + rows;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
describe('CSV2Records with mocked data', () => {
|
|
19
|
-
let csv: string;
|
|
20
|
-
|
|
21
|
-
beforeEach(() => {
|
|
22
|
-
csv = generateMockCSV();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('should convert generated CSV to records correctly', () => {
|
|
26
|
-
const result = CSV2Records(csv, 0);
|
|
27
|
-
expect(result).toEqual([
|
|
28
|
-
{ name: 'Alice Johnson', age: 22, isStudent: true },
|
|
29
|
-
{ name: 'Bob Smith', age: 28, isStudent: false },
|
|
30
|
-
{ name: 'Charlie Brown', age: 19, isStudent: true },
|
|
31
|
-
]);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should correctly parse each field from the mock CSV', () => {
|
|
35
|
-
const result = CSV2Records(csv, 0);
|
|
36
|
-
expect(result.length).toBe(3);
|
|
37
|
-
|
|
38
|
-
// Verify individual properties directly
|
|
39
|
-
expect(result[0].name).toEqual('Alice Johnson');
|
|
40
|
-
expect(result[0].age).toEqual(22);
|
|
41
|
-
expect(result[0].isStudent).toEqual(true);
|
|
42
|
-
|
|
43
|
-
expect(result[1].name).toEqual('Bob Smith');
|
|
44
|
-
expect(result[1].age).toEqual(28);
|
|
45
|
-
expect(result[1].isStudent).toEqual(false);
|
|
46
|
-
|
|
47
|
-
expect(result[2].name).toEqual('Charlie Brown');
|
|
48
|
-
expect(result[2].age).toEqual(19);
|
|
49
|
-
expect(result[2].isStudent).toEqual(true);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { cleanupFileName } from '@shared/utils/filenaming/cleanupFileName';
|
|
2
|
-
|
|
3
|
-
xdescribe('cleanupFileName', () => {
|
|
4
|
-
it('should pass', () => {
|
|
5
|
-
expect(
|
|
6
|
-
cleanupFileName('T__e*8\\//s!`~"\'-_test =;$%^any word&():,@#{t}e.r'),
|
|
7
|
-
).toEqual('t_e_8_-s_-_test_any_word_t_e.r');
|
|
8
|
-
});
|
|
9
|
-
});
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { fitIntoRectangle } from '@shared/utils/geom/fitIntoRectangle';
|
|
2
|
-
|
|
3
|
-
xdescribe('fitRectangle', () => {
|
|
4
|
-
it('should pass', () => {
|
|
5
|
-
expect(
|
|
6
|
-
fitIntoRectangle(
|
|
7
|
-
{ x: 0, y: 0, w: 100, h: 100 },
|
|
8
|
-
{ x: 0, y: 0, w: 200, h: 150 },
|
|
9
|
-
),
|
|
10
|
-
).toEqual({ x: 25, y: 0, w: 150, h: 150, scale: 2 });
|
|
11
|
-
expect(
|
|
12
|
-
fitIntoRectangle(
|
|
13
|
-
{ x: 0, y: 0, w: 100, h: 100 },
|
|
14
|
-
{ x: 0, y: 0, w: 50, h: 150 },
|
|
15
|
-
),
|
|
16
|
-
).toEqual({ x: 0, y: 50, w: 50, h: 50, scale: 0.5 });
|
|
17
|
-
expect(
|
|
18
|
-
fitIntoRectangle(
|
|
19
|
-
{ x: 0, y: 0, w: 100, h: 100 },
|
|
20
|
-
{ x: 0, y: 0, w: 150, h: 150 },
|
|
21
|
-
),
|
|
22
|
-
).toEqual({ x: 0, y: 0, w: 150, h: 150, scale: 1.5 });
|
|
23
|
-
expect(
|
|
24
|
-
fitIntoRectangle(
|
|
25
|
-
{ x: 0, y: 0, w: 200, h: 200 },
|
|
26
|
-
{ x: 0, y: 0, w: 150, h: 150 },
|
|
27
|
-
),
|
|
28
|
-
).toEqual({ x: 0, y: 0, w: 150, h: 150, scale: 0.75 });
|
|
29
|
-
expect(
|
|
30
|
-
fitIntoRectangle(
|
|
31
|
-
{ x: 0, y: 0, w: 200, h: 200 },
|
|
32
|
-
{ x: 10, y: 10, w: 150, h: 150 },
|
|
33
|
-
),
|
|
34
|
-
).toEqual({
|
|
35
|
-
x: 10,
|
|
36
|
-
y: 10,
|
|
37
|
-
w: 150,
|
|
38
|
-
h: 150,
|
|
39
|
-
scale: 0.75,
|
|
40
|
-
});
|
|
41
|
-
expect(
|
|
42
|
-
fitIntoRectangle(
|
|
43
|
-
{ x: 0, y: 0, w: 200, h: 300 },
|
|
44
|
-
{ x: 10, y: 10, w: 210, h: 150 },
|
|
45
|
-
),
|
|
46
|
-
).toEqual({
|
|
47
|
-
x: 65,
|
|
48
|
-
y: 10,
|
|
49
|
-
w: 100,
|
|
50
|
-
h: 150,
|
|
51
|
-
scale: 1.05,
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { sleep } from '@shared/utils/helpers/sleep';
|
|
2
|
-
|
|
3
|
-
describe('sleep', () => {
|
|
4
|
-
it('should wait 100 msec', async () => {
|
|
5
|
-
const time = new Date().getTime();
|
|
6
|
-
await sleep(100);
|
|
7
|
-
const diff = (new Date().getTime() - time) / 100;
|
|
8
|
-
|
|
9
|
-
expect(diff).toBeCloseTo(1.01, 1);
|
|
10
|
-
});
|
|
11
|
-
});
|
|
@@ -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,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
|
-
});
|