mielk-fn 1.2.4 → 1.2.6
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/dist/arrays/arrays.spec.d.ts +1 -0
- package/dist/arrays/arrays.spec.js +89 -0
- package/dist/dates/dates.spec.d.ts +1 -0
- package/dist/dates/dates.spec.js +47 -0
- package/dist/io/io.spec.d.ts +1 -0
- package/dist/io/io.spec.js +66 -0
- package/dist/math/math.spec.d.ts +1 -0
- package/dist/math/math.spec.js +73 -0
- package/dist/objects/objects.spec.d.ts +1 -0
- package/dist/objects/objects.spec.js +199 -0
- package/dist/redis/redisActions.js +1 -1
- package/dist/regex/regex.spec.d.ts +1 -0
- package/dist/regex/regex.spec.js +15 -0
- package/dist/strings/strings.spec.d.ts +1 -0
- package/dist/strings/strings.spec.js +61 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/objects.d.ts +3 -0
- package/dist/variables/variables.spec.d.ts +1 -0
- package/dist/variables/variables.spec.js +239 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { toIndexedArray, toMap } from "./arrays.js";
|
|
2
|
+
describe('toMap', () => {
|
|
3
|
+
const objects = [
|
|
4
|
+
{ name: 'Adam', id: 1 },
|
|
5
|
+
{ name: 'Bartek', id: 4 },
|
|
6
|
+
{ name: 'Czesiek', id: 5 },
|
|
7
|
+
];
|
|
8
|
+
const primitives = ['Adam', 'Bartek', 'Czesiek'];
|
|
9
|
+
it('should create a map from an array of objects', () => {
|
|
10
|
+
const map = toMap(objects, (obj) => obj.id);
|
|
11
|
+
expect(map.size).toBe(3);
|
|
12
|
+
expect(map.get(1)).toEqual(objects[0]);
|
|
13
|
+
expect(map.get(4)).toEqual(objects[1]);
|
|
14
|
+
expect(map.get(5)).toEqual(objects[2]);
|
|
15
|
+
});
|
|
16
|
+
it('should create a map from an array of primitives', () => {
|
|
17
|
+
const map = toMap(primitives, (str) => str.charAt(0));
|
|
18
|
+
expect(map.size).toBe(3);
|
|
19
|
+
expect(map.get('A')).toEqual(primitives[0]);
|
|
20
|
+
expect(map.get('B')).toEqual(primitives[1]);
|
|
21
|
+
expect(map.get('C')).toEqual(primitives[2]);
|
|
22
|
+
});
|
|
23
|
+
it('should allow custom value callback', () => {
|
|
24
|
+
const map = toMap(objects, (obj) => obj.id, (obj) => obj.name);
|
|
25
|
+
expect(map.size).toBe(3);
|
|
26
|
+
expect(map.get(1)).toBe('Adam');
|
|
27
|
+
expect(map.get(4)).toBe('Bartek');
|
|
28
|
+
expect(map.get(5)).toBe('Czesiek');
|
|
29
|
+
});
|
|
30
|
+
it('should ignore duplicate keys by default', () => {
|
|
31
|
+
const objectsWithDuplicate = [
|
|
32
|
+
{ name: 'Adam', id: 1 },
|
|
33
|
+
{ name: 'Bartek', id: 4 },
|
|
34
|
+
{ name: 'Czesiek', id: 4 },
|
|
35
|
+
];
|
|
36
|
+
const map = toMap(objectsWithDuplicate, (obj) => obj.id);
|
|
37
|
+
expect(map.size).toBe(2);
|
|
38
|
+
expect(map.get(1)).toEqual(objectsWithDuplicate[0]);
|
|
39
|
+
expect(map.get(4)).toEqual(objectsWithDuplicate[1]);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
describe('toIndexedArray', () => {
|
|
43
|
+
it('should return an indexed array with basic objects', () => {
|
|
44
|
+
const items = [
|
|
45
|
+
{ name: 'Adam', id: 1 },
|
|
46
|
+
{ name: 'Bartek', id: 4 },
|
|
47
|
+
{ name: 'Czesiek', id: 5 },
|
|
48
|
+
];
|
|
49
|
+
const callback = (item) => item.id;
|
|
50
|
+
const result = toIndexedArray(items, callback);
|
|
51
|
+
expect(result[1]).toEqual({ name: 'Adam', id: 1 });
|
|
52
|
+
expect(result[4]).toEqual({ name: 'Bartek', id: 4 });
|
|
53
|
+
expect(result[5]).toEqual({ name: 'Czesiek', id: 5 });
|
|
54
|
+
});
|
|
55
|
+
it('should handle custom class instances', () => {
|
|
56
|
+
class Person {
|
|
57
|
+
constructor(fullName, id) {
|
|
58
|
+
this.fullName = fullName;
|
|
59
|
+
this.id = id;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const items = [new Person('Adam', 1), new Person('Bartek', 4), new Person('Czesiek', 5)];
|
|
63
|
+
const callback = (item) => {
|
|
64
|
+
if (typeof item === 'object' && item !== null && 'id' in item) {
|
|
65
|
+
return item.id;
|
|
66
|
+
}
|
|
67
|
+
return -1;
|
|
68
|
+
};
|
|
69
|
+
const result = toIndexedArray(items, callback);
|
|
70
|
+
expect(result[1]).toEqual(new Person('Adam', 1));
|
|
71
|
+
expect(result[4]).toEqual(new Person('Bartek', 4));
|
|
72
|
+
expect(result[5]).toEqual(new Person('Czesiek', 5));
|
|
73
|
+
});
|
|
74
|
+
it('should throw an error when the callback returns a non-number value', () => {
|
|
75
|
+
const items = [
|
|
76
|
+
{ name: 'Adam', id: '1' },
|
|
77
|
+
{ name: 'Bartek', id: '4' },
|
|
78
|
+
{ name: 'Czesiek', id: '5' },
|
|
79
|
+
];
|
|
80
|
+
const callback = (item) => item.id;
|
|
81
|
+
expect(() => toIndexedArray(items, callback)).toThrow(new TypeError('Callback should return a number.'));
|
|
82
|
+
});
|
|
83
|
+
it('should handle an empty array', () => {
|
|
84
|
+
const items = [];
|
|
85
|
+
const callback = (item) => item.id;
|
|
86
|
+
const result = toIndexedArray(items, callback);
|
|
87
|
+
expect(result).toEqual([]);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { formatDateDefault } from "./dates";
|
|
2
|
+
describe('formatDateDefault', () => {
|
|
3
|
+
it('should return empty string for undefined', () => {
|
|
4
|
+
expect(formatDateDefault(undefined)).toBe('');
|
|
5
|
+
});
|
|
6
|
+
it('should return string in format YYYY-MM-DD HH:mm:ss', () => {
|
|
7
|
+
const date = new Date('2024-01-02T03:04:05Z');
|
|
8
|
+
const result = formatDateDefault(date);
|
|
9
|
+
expect(result).toMatch(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
|
|
10
|
+
});
|
|
11
|
+
it('should always have 2-digit month, day, hour, minute, second', () => {
|
|
12
|
+
const date = new Date('2024-04-05T06:07:08Z');
|
|
13
|
+
const result = formatDateDefault(date);
|
|
14
|
+
const [datePart, timePart] = result.split(' ');
|
|
15
|
+
const [year, month, day] = datePart.split('-');
|
|
16
|
+
const [hour, minute, second] = timePart.split(':');
|
|
17
|
+
expect(year.length).toBe(4);
|
|
18
|
+
expect(month.length).toBe(2);
|
|
19
|
+
expect(day.length).toBe(2);
|
|
20
|
+
expect(hour.length).toBe(2);
|
|
21
|
+
expect(minute.length).toBe(2);
|
|
22
|
+
expect(second.length).toBe(2);
|
|
23
|
+
});
|
|
24
|
+
it('should accept custom timeZone parameter', () => {
|
|
25
|
+
const date = new Date('2024-01-02T03:04:05Z');
|
|
26
|
+
const result = formatDateDefault(date, 'UTC');
|
|
27
|
+
expect(result).toMatch(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
|
|
28
|
+
});
|
|
29
|
+
it('should still return valid structure for different time zones', () => {
|
|
30
|
+
const date = new Date('2024-06-15T10:20:30Z');
|
|
31
|
+
const resultWarsaw = formatDateDefault(date, 'Europe/Warsaw');
|
|
32
|
+
const resultUTC = formatDateDefault(date, 'UTC');
|
|
33
|
+
expect(resultWarsaw).toMatch(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
|
|
34
|
+
expect(resultUTC).toMatch(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/);
|
|
35
|
+
expect(resultWarsaw).not.toBe(resultUTC);
|
|
36
|
+
});
|
|
37
|
+
it('should be deterministic', () => {
|
|
38
|
+
const date = new Date('2024-06-15T10:20:30Z');
|
|
39
|
+
expect(formatDateDefault(date)).toBe(formatDateDefault(date));
|
|
40
|
+
});
|
|
41
|
+
it('should not mutate input date', () => {
|
|
42
|
+
const date = new Date('2024-01-01T00:00:00Z');
|
|
43
|
+
const time = date.getTime();
|
|
44
|
+
formatDateDefault(date);
|
|
45
|
+
expect(date.getTime()).toBe(time);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { parseJsonFile } from './io.js';
|
|
2
|
+
describe('parseJson', () => {
|
|
3
|
+
it('should return default object when valid', () => {
|
|
4
|
+
const input = {
|
|
5
|
+
a: 12,
|
|
6
|
+
default: { x: 1, y: 2 },
|
|
7
|
+
};
|
|
8
|
+
expect(parseJsonFile(input)).toEqual({ x: 1, y: 2 });
|
|
9
|
+
});
|
|
10
|
+
it('should return empty object when default is missing', () => {
|
|
11
|
+
const input = { a: 12, b: 23 };
|
|
12
|
+
expect(parseJsonFile(input)).toEqual({});
|
|
13
|
+
});
|
|
14
|
+
it('should return empty object when default is null', () => {
|
|
15
|
+
const input = { default: null };
|
|
16
|
+
expect(parseJsonFile(input)).toEqual({});
|
|
17
|
+
});
|
|
18
|
+
it('should return empty object when default is not an object', () => {
|
|
19
|
+
expect(parseJsonFile({ default: 123 })).toEqual({});
|
|
20
|
+
expect(parseJsonFile({ default: 'text' })).toEqual({});
|
|
21
|
+
expect(parseJsonFile({ default: true })).toEqual({});
|
|
22
|
+
});
|
|
23
|
+
it('should return empty object when default is an array', () => {
|
|
24
|
+
expect(parseJsonFile({ default: [] })).toEqual({});
|
|
25
|
+
});
|
|
26
|
+
it('should return empty object when input is null', () => {
|
|
27
|
+
expect(parseJsonFile(null)).toEqual({});
|
|
28
|
+
});
|
|
29
|
+
it('should return empty object when input is undefined', () => {
|
|
30
|
+
expect(parseJsonFile(undefined)).toEqual({});
|
|
31
|
+
});
|
|
32
|
+
it('should return empty object when input is primitive', () => {
|
|
33
|
+
expect(parseJsonFile(123)).toEqual({});
|
|
34
|
+
expect(parseJsonFile('text')).toEqual({});
|
|
35
|
+
expect(parseJsonFile(true)).toEqual({});
|
|
36
|
+
});
|
|
37
|
+
it('should return empty object when input is array', () => {
|
|
38
|
+
expect(parseJsonFile([])).toEqual({});
|
|
39
|
+
});
|
|
40
|
+
it('should return empty object when default is a special object (Date, Map, etc.)', () => {
|
|
41
|
+
expect(parseJsonFile({ default: new Date() })).toEqual({});
|
|
42
|
+
expect(parseJsonFile({ default: new Map() })).toEqual({});
|
|
43
|
+
});
|
|
44
|
+
it('should handle nested default object', () => {
|
|
45
|
+
const input = {
|
|
46
|
+
default: {
|
|
47
|
+
nested: {
|
|
48
|
+
value: 42,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
expect(parseJsonFile(input)).toEqual({
|
|
53
|
+
nested: {
|
|
54
|
+
value: 42,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
it('should not mutate input object', () => {
|
|
59
|
+
const input = {
|
|
60
|
+
default: { a: 1 },
|
|
61
|
+
};
|
|
62
|
+
const result = parseJsonFile(input);
|
|
63
|
+
expect(result).toEqual({ a: 1 });
|
|
64
|
+
expect(input.default).toEqual({ a: 1 });
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { formatPercent, formatWithSign } from "./math";
|
|
2
|
+
describe('formatWithSign', () => {
|
|
3
|
+
it('formats positive numbers with + sign', () => {
|
|
4
|
+
expect(formatWithSign(1.234)).toBe('+1');
|
|
5
|
+
});
|
|
6
|
+
it('formats negative numbers with unicode minus', () => {
|
|
7
|
+
expect(formatWithSign(-1.234)).toBe('−1');
|
|
8
|
+
});
|
|
9
|
+
it('returns plain zero without sign', () => {
|
|
10
|
+
expect(formatWithSign(0)).toBe('0');
|
|
11
|
+
});
|
|
12
|
+
it('respects decimals', () => {
|
|
13
|
+
expect(formatWithSign(1.234, 2)).toBe('+1.23');
|
|
14
|
+
expect(formatWithSign(-1.234, 2)).toBe('−1.23');
|
|
15
|
+
});
|
|
16
|
+
it('rounds values correctly', () => {
|
|
17
|
+
expect(formatWithSign(1.235, 2)).toBe('+1.24');
|
|
18
|
+
expect(formatWithSign(-1.235, 2)).toBe('−1.24');
|
|
19
|
+
});
|
|
20
|
+
it('handles NaN', () => {
|
|
21
|
+
expect(formatWithSign(NaN)).toBe('NaN');
|
|
22
|
+
});
|
|
23
|
+
it('handles Infinity', () => {
|
|
24
|
+
expect(formatWithSign(Infinity)).toBe('+Infinity');
|
|
25
|
+
expect(formatWithSign(-Infinity)).toBe('−Infinity');
|
|
26
|
+
});
|
|
27
|
+
it('handles very large numbers', () => {
|
|
28
|
+
expect(formatWithSign(1e20)).toBe('+100000000000000000000');
|
|
29
|
+
});
|
|
30
|
+
it('handles very small numbers', () => {
|
|
31
|
+
expect(formatWithSign(1e-10, 0)).toBe('+0');
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
describe('formatPercent', () => {
|
|
35
|
+
it('formats positive percentages without plus by default', () => {
|
|
36
|
+
expect(formatPercent(0.1234)).toBe('12%');
|
|
37
|
+
});
|
|
38
|
+
it('formats positive percentages with plus when flag is true', () => {
|
|
39
|
+
expect(formatPercent(0.1234, 2, true)).toBe('+12.34%');
|
|
40
|
+
});
|
|
41
|
+
it('formats negative percentages', () => {
|
|
42
|
+
expect(formatPercent(-0.1234)).toBe('−12%');
|
|
43
|
+
});
|
|
44
|
+
it('formats negative percentages with decimals', () => {
|
|
45
|
+
expect(formatPercent(-0.1234, 2)).toBe('−12.34%');
|
|
46
|
+
});
|
|
47
|
+
it('handles zero', () => {
|
|
48
|
+
expect(formatPercent(0)).toBe('0%');
|
|
49
|
+
});
|
|
50
|
+
it('handles zero with plus flag (still no sign)', () => {
|
|
51
|
+
expect(formatPercent(0, 0, true)).toBe('0%');
|
|
52
|
+
});
|
|
53
|
+
it('handles zero with fraction and plus flag (still no sign)', () => {
|
|
54
|
+
expect(formatPercent(0, 2, true)).toBe('0.00%');
|
|
55
|
+
});
|
|
56
|
+
it('respects decimals', () => {
|
|
57
|
+
expect(formatPercent(0.1234, 2)).toBe('12.34%');
|
|
58
|
+
});
|
|
59
|
+
it('multiplies by 100 correctly', () => {
|
|
60
|
+
expect(formatPercent(1)).toBe('100%');
|
|
61
|
+
expect(formatPercent(0.01)).toBe('1%');
|
|
62
|
+
});
|
|
63
|
+
it('rounds correctly', () => {
|
|
64
|
+
expect(formatPercent(0.01479, 2)).toBe('1.48%');
|
|
65
|
+
});
|
|
66
|
+
it('handles NaN', () => {
|
|
67
|
+
expect(formatPercent(NaN)).toBe('NaN%');
|
|
68
|
+
});
|
|
69
|
+
it('handles Infinity', () => {
|
|
70
|
+
expect(formatPercent(Infinity)).toBe('Infinity%');
|
|
71
|
+
expect(formatPercent(-Infinity)).toBe('−Infinity%');
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { invert, isNonEmptyObject, merge, modifyKeys } from "./objects.js";
|
|
2
|
+
describe('invert', () => {
|
|
3
|
+
it('Basic case', () => {
|
|
4
|
+
const input = { key1: 'value1', key2: 'value2' };
|
|
5
|
+
const result = invert(input);
|
|
6
|
+
expect(result).toEqual({ value1: 'key1', value2: 'key2' });
|
|
7
|
+
});
|
|
8
|
+
it('Number keys and values', () => {
|
|
9
|
+
const input = { 1: 2, 3: 4 };
|
|
10
|
+
const result = invert(input);
|
|
11
|
+
expect(result).toEqual({ 2: '1', 4: '3' });
|
|
12
|
+
});
|
|
13
|
+
it('Mixed keys and values', () => {
|
|
14
|
+
const input = { key1: 1, 2: 'value2' };
|
|
15
|
+
const result = invert(input);
|
|
16
|
+
expect(result).toEqual({ 1: 'key1', value2: '2' });
|
|
17
|
+
});
|
|
18
|
+
it('Empty object', () => {
|
|
19
|
+
const input = {};
|
|
20
|
+
const result = invert(input);
|
|
21
|
+
expect(result).toEqual({});
|
|
22
|
+
});
|
|
23
|
+
it('Non-object input', () => {
|
|
24
|
+
const input = 'string';
|
|
25
|
+
expect(() => invert(input)).toThrow('Invalid input: the input must be an object.');
|
|
26
|
+
});
|
|
27
|
+
it('Invalid value type', () => {
|
|
28
|
+
const input = { key1: true };
|
|
29
|
+
expect(() => invert(input)).toThrow('Invalid value type: the value must be a string or a number.');
|
|
30
|
+
});
|
|
31
|
+
it('should invert object with string keys and number values', () => {
|
|
32
|
+
const obj = { a: 1, b: 2, c: 3 };
|
|
33
|
+
const result = invert(obj);
|
|
34
|
+
expect(result).toEqual({ '1': 'a', '2': 'b', '3': 'c' });
|
|
35
|
+
});
|
|
36
|
+
it('should invert object with number keys and string values', () => {
|
|
37
|
+
const obj = { '1': 'a', '2': 'b', '3': 'c' };
|
|
38
|
+
const result = invert(obj);
|
|
39
|
+
expect(result).toEqual({ a: '1', b: '2', c: '3' });
|
|
40
|
+
});
|
|
41
|
+
it('should invert object with string keys and string values', () => {
|
|
42
|
+
const obj = { a: '1', b: '2', c: '3' };
|
|
43
|
+
const result = invert(obj);
|
|
44
|
+
expect(result).toEqual({ '1': 'a', '2': 'b', '3': 'c' });
|
|
45
|
+
});
|
|
46
|
+
it('should invert object with number keys and number values', () => {
|
|
47
|
+
const obj = { '1': 2, '3': 4, '5': 6 };
|
|
48
|
+
const result = invert(obj);
|
|
49
|
+
expect(result).toEqual({ '2': '1', '4': '3', '6': '5' });
|
|
50
|
+
});
|
|
51
|
+
it('should invert object with unusual but valid keys or values', () => {
|
|
52
|
+
const obj = { '': 1, a: 0, b: -1 };
|
|
53
|
+
const result = invert(obj);
|
|
54
|
+
expect(result).toEqual({ '1': '', '0': 'a', '-1': 'b' });
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
describe('isNonEmptyObject', () => {
|
|
58
|
+
it('should return false for a number', () => {
|
|
59
|
+
expect(isNonEmptyObject(1)).toBeFalsy();
|
|
60
|
+
});
|
|
61
|
+
it('should return false for a text', () => {
|
|
62
|
+
expect(isNonEmptyObject('a')).toBeFalsy();
|
|
63
|
+
});
|
|
64
|
+
it('should return false for non-empty array', () => {
|
|
65
|
+
expect(isNonEmptyObject([1, 2, 3])).toBeFalsy();
|
|
66
|
+
});
|
|
67
|
+
it('should return false for empty array', () => {
|
|
68
|
+
expect(isNonEmptyObject([])).toBeFalsy();
|
|
69
|
+
});
|
|
70
|
+
it('should return false for multidimensional array', () => {
|
|
71
|
+
expect(isNonEmptyObject([[], []])).toBeFalsy();
|
|
72
|
+
});
|
|
73
|
+
it('should return false for null', () => {
|
|
74
|
+
expect(isNonEmptyObject(null)).toBeFalsy();
|
|
75
|
+
});
|
|
76
|
+
it('should return false for undefined', () => {
|
|
77
|
+
expect(isNonEmptyObject(undefined)).toBeFalsy();
|
|
78
|
+
});
|
|
79
|
+
it('should return false for empty object', () => {
|
|
80
|
+
expect(isNonEmptyObject({})).toBeFalsy();
|
|
81
|
+
});
|
|
82
|
+
it('should return true for non-empty object', () => {
|
|
83
|
+
expect(isNonEmptyObject({ id: 1 })).toBeTruthy();
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
describe('merge', () => {
|
|
87
|
+
test('Empty array', () => {
|
|
88
|
+
const result = merge([]);
|
|
89
|
+
expect(result).toEqual({});
|
|
90
|
+
});
|
|
91
|
+
it('Array with non-objects', () => {
|
|
92
|
+
const input = ['string1', 42, true];
|
|
93
|
+
const result = merge(input);
|
|
94
|
+
expect(result).toEqual({});
|
|
95
|
+
});
|
|
96
|
+
it('Array with objects and non-objects', () => {
|
|
97
|
+
const obj1 = { key1: 'value1' };
|
|
98
|
+
const obj2 = { key2: 'value2' };
|
|
99
|
+
const input = [obj1, 'string1', 42, obj2, true];
|
|
100
|
+
const result = merge(input);
|
|
101
|
+
expect(result).toEqual({ key1: 'value1', key2: 'value2' });
|
|
102
|
+
});
|
|
103
|
+
test('Array with empty objects', () => {
|
|
104
|
+
const result = merge([{}, {}, {}]);
|
|
105
|
+
expect(result).toEqual({});
|
|
106
|
+
});
|
|
107
|
+
test('Array with objects without duplicated properties', () => {
|
|
108
|
+
const result = merge([{ a: 1 }, { b: 2 }, { c: 3 }]);
|
|
109
|
+
expect(result).toEqual({ a: 1, b: 2, c: 3 });
|
|
110
|
+
});
|
|
111
|
+
test('Array with objects with duplicated properties and override=false', () => {
|
|
112
|
+
const result = merge([{ a: 1 }, { a: 2 }, { a: 3 }], false);
|
|
113
|
+
expect(result).toEqual({ a: 1 });
|
|
114
|
+
});
|
|
115
|
+
test('Array with objects with duplicated properties and override=true', () => {
|
|
116
|
+
const result = merge([{ a: 1 }, { a: 2 }, { a: 3 }], true);
|
|
117
|
+
expect(result).toEqual({ a: 3 });
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
describe('modifyKeys', () => {
|
|
121
|
+
describe('modifyKeys', () => {
|
|
122
|
+
it('should modify the keys of the object', () => {
|
|
123
|
+
const input = { id: 1, name: 'John' };
|
|
124
|
+
const callback = (key) => ('' + key).toUpperCase();
|
|
125
|
+
const result = modifyKeys(input, callback);
|
|
126
|
+
expect(result).toEqual({ ID: 1, NAME: 'John' });
|
|
127
|
+
});
|
|
128
|
+
it('should handle an empty object', () => {
|
|
129
|
+
const input = {};
|
|
130
|
+
const callback = (key) => ('' + key).toUpperCase();
|
|
131
|
+
const result = modifyKeys(input, callback);
|
|
132
|
+
expect(result).toEqual({});
|
|
133
|
+
});
|
|
134
|
+
it('should handle an object with non-string keys', () => {
|
|
135
|
+
const input = { 1: 'one', 2: 'two', 3: 'three' };
|
|
136
|
+
const callback = (key) => key + '_new';
|
|
137
|
+
const result = modifyKeys(input, callback);
|
|
138
|
+
expect(result).toEqual({ '1_new': 'one', '2_new': 'two', '3_new': 'three' });
|
|
139
|
+
});
|
|
140
|
+
it('should modify the keys based on the callback function', () => {
|
|
141
|
+
const input = { id: 1, name: 'John', age: 30 };
|
|
142
|
+
const callback = (key) => key + '_new';
|
|
143
|
+
const result = modifyKeys(input, callback);
|
|
144
|
+
expect(result).toEqual({ id_new: 1, name_new: 'John', age_new: 30 });
|
|
145
|
+
});
|
|
146
|
+
it('should not modify the original object', () => {
|
|
147
|
+
const input = { id: 1, name: 'John' };
|
|
148
|
+
const callback = (key) => ('' + key).toUpperCase();
|
|
149
|
+
const result = modifyKeys(input, callback);
|
|
150
|
+
expect(result).toEqual({ ID: 1, NAME: 'John' });
|
|
151
|
+
expect(input).toEqual({ id: 1, name: 'John' });
|
|
152
|
+
});
|
|
153
|
+
it('should modify the keys of an object', () => {
|
|
154
|
+
const obj = { a: 1, b: 2, c: 3 };
|
|
155
|
+
const callback = (key) => ('' + key).toUpperCase();
|
|
156
|
+
const result = modifyKeys(obj, callback);
|
|
157
|
+
expect(result).toEqual({ A: 1, B: 2, C: 3 });
|
|
158
|
+
});
|
|
159
|
+
it('should handle an empty object', () => {
|
|
160
|
+
const obj = {};
|
|
161
|
+
const callback = (key) => ('' + key).toUpperCase();
|
|
162
|
+
const result = modifyKeys(obj, callback);
|
|
163
|
+
expect(result).toEqual({});
|
|
164
|
+
});
|
|
165
|
+
it('should throw an error if the second argument is not a function', () => {
|
|
166
|
+
const obj = { a: 1, b: 2, c: 3 };
|
|
167
|
+
const callback = 'not a function';
|
|
168
|
+
expect(() => modifyKeys(obj, callback)).toThrow(TypeError);
|
|
169
|
+
});
|
|
170
|
+
it('should handle an object with duplicate modified keys', () => {
|
|
171
|
+
const obj = { a: 1, b: 2, c: 3 };
|
|
172
|
+
const callback = (key) => 'new_key';
|
|
173
|
+
const result = modifyKeys(obj, callback, true);
|
|
174
|
+
expect(result).toEqual({ new_key: 1 });
|
|
175
|
+
});
|
|
176
|
+
it('should handle an object with duplicate modified keys if ignoreDuplicates is false', () => {
|
|
177
|
+
const obj = { a: 1, b: 2, c: 3 };
|
|
178
|
+
const callback = (key) => 'new_key';
|
|
179
|
+
const result = modifyKeys(obj, callback, false);
|
|
180
|
+
expect(result).toEqual({ new_key: 3 });
|
|
181
|
+
});
|
|
182
|
+
it('should throw an error in strict mode if given a non-object value', () => {
|
|
183
|
+
'use strict';
|
|
184
|
+
const callback = (key) => 'new_key';
|
|
185
|
+
const fn = () => { };
|
|
186
|
+
expect(() => modifyKeys(undefined, callback)).toThrow(new TypeError('Invalid type of undefined. Expected JavaScript object'));
|
|
187
|
+
expect(() => modifyKeys(123, callback)).toThrow(new TypeError('Invalid type of Number. Expected JavaScript object'));
|
|
188
|
+
expect(() => modifyKeys('string', callback)).toThrow(new TypeError('Invalid type of String. Expected JavaScript object'));
|
|
189
|
+
expect(() => modifyKeys(Symbol(), callback)).toThrow(new TypeError('Invalid type of Symbol. Expected JavaScript object'));
|
|
190
|
+
expect(() => modifyKeys(true, callback)).toThrow(new TypeError('Invalid type of Boolean. Expected JavaScript object'));
|
|
191
|
+
expect(() => modifyKeys(fn, callback)).toThrow(new TypeError('Invalid type of Function. Expected JavaScript object'));
|
|
192
|
+
expect(() => modifyKeys([], callback)).toThrow(new TypeError('Invalid type of Array. Expected JavaScript object'));
|
|
193
|
+
expect(() => modifyKeys(new Date(), callback)).toThrow(new TypeError(`Invalid type of Date. Expected JavaScript object`));
|
|
194
|
+
class MyClass {
|
|
195
|
+
}
|
|
196
|
+
expect(() => modifyKeys(new MyClass(), callback)).toThrow(new TypeError(`Invalid type of MyClass. Expected JavaScript object`));
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getCapturedNumber } from "./regex";
|
|
2
|
+
describe('getCapturedNumber', () => {
|
|
3
|
+
it('If there is a match, correct number should be returned', () => {
|
|
4
|
+
const pattern = 'value: (\\d+)';
|
|
5
|
+
const input = 'Current value: 123;';
|
|
6
|
+
const result = getCapturedNumber(input, pattern);
|
|
7
|
+
expect(result).toBe(123);
|
|
8
|
+
});
|
|
9
|
+
it('If there is no match, undefined is returned', () => {
|
|
10
|
+
const pattern = 'value: (d+)';
|
|
11
|
+
const input = 'Current value: 123;';
|
|
12
|
+
const result = getCapturedNumber(input, pattern);
|
|
13
|
+
expect(result).toBe(undefined);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { capitalizeFirst, clear } from './strings.js';
|
|
2
|
+
describe('capitalizeFirst', () => {
|
|
3
|
+
it('should capitalize first letter of a lowercase word', () => {
|
|
4
|
+
expect(capitalizeFirst('hello')).toBe('Hello');
|
|
5
|
+
});
|
|
6
|
+
it('should not change already capitalized string', () => {
|
|
7
|
+
expect(capitalizeFirst('Hello')).toBe('Hello');
|
|
8
|
+
});
|
|
9
|
+
it('should not modify rest of the string', () => {
|
|
10
|
+
expect(capitalizeFirst('hELLO')).toBe('HELLO');
|
|
11
|
+
});
|
|
12
|
+
it('should handle empty string', () => {
|
|
13
|
+
expect(capitalizeFirst('')).toBe('');
|
|
14
|
+
});
|
|
15
|
+
it('should handle single character', () => {
|
|
16
|
+
expect(capitalizeFirst('a')).toBe('A');
|
|
17
|
+
});
|
|
18
|
+
it('should handle strings starting with non-letter', () => {
|
|
19
|
+
expect(capitalizeFirst('1hello')).toBe('1hello');
|
|
20
|
+
expect(capitalizeFirst('!test')).toBe('!test');
|
|
21
|
+
});
|
|
22
|
+
it('should handle unicode characters', () => {
|
|
23
|
+
expect(capitalizeFirst('żółw')).toBe('Żółw');
|
|
24
|
+
});
|
|
25
|
+
it('should capitalize first non-whitespace character', () => {
|
|
26
|
+
expect(capitalizeFirst(' hello')).toBe(' Hello');
|
|
27
|
+
expect(capitalizeFirst(' world')).toBe(' World');
|
|
28
|
+
});
|
|
29
|
+
it('should return string unchanged if it contains only whitespace', () => {
|
|
30
|
+
expect(capitalizeFirst(' ')).toBe(' ');
|
|
31
|
+
});
|
|
32
|
+
it('should not modify non-letter first non-whitespace character', () => {
|
|
33
|
+
expect(capitalizeFirst(' 123abc')).toBe(' 123abc');
|
|
34
|
+
expect(capitalizeFirst(' !test')).toBe(' !test');
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe('clear', () => {
|
|
38
|
+
test('clear should remove leading and trailing spaces', () => {
|
|
39
|
+
expect(clear(' Hello world ')).toBe('Hello world');
|
|
40
|
+
});
|
|
41
|
+
test('clear should remove multiple spaces inside the string', () => {
|
|
42
|
+
expect(clear('Hello world')).toBe('Hello world');
|
|
43
|
+
});
|
|
44
|
+
test('clear should return the same string if no extra spaces', () => {
|
|
45
|
+
expect(clear('Hello world')).toBe('Hello world');
|
|
46
|
+
});
|
|
47
|
+
test('clear should return empty string if input string contains only spaces', () => {
|
|
48
|
+
expect(clear(' ')).toBe('');
|
|
49
|
+
});
|
|
50
|
+
test('clear should throw an error if input is not a string', () => {
|
|
51
|
+
expect(() => {
|
|
52
|
+
clear(123);
|
|
53
|
+
}).toThrow();
|
|
54
|
+
});
|
|
55
|
+
test('clear should handle string with only one word correctly', () => {
|
|
56
|
+
expect(clear(' Hello ')).toBe('Hello');
|
|
57
|
+
});
|
|
58
|
+
test('clear should handle empty string correctly', () => {
|
|
59
|
+
expect(clear('')).toBe('');
|
|
60
|
+
});
|
|
61
|
+
});
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { JSONFile } from './io.js';
|
|
2
2
|
import type { Range } from './math.js';
|
|
3
|
-
import type { ObjectAny, ObjectPrimitives } from './objects.js';
|
|
3
|
+
import type { DeepPartial, ObjectAny, ObjectPrimitives } from './objects.js';
|
|
4
4
|
export type { JSONFile };
|
|
5
5
|
export type { Range };
|
|
6
|
-
export type { ObjectAny, ObjectPrimitives };
|
|
6
|
+
export type { DeepPartial, ObjectAny, ObjectPrimitives };
|
package/dist/types/objects.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { isArrayOfPrimitives, isObject, isPlainObject, isPrimitive, isStringOrNumber } from './variables.js';
|
|
2
|
+
describe('isArrayOfPrimitives', () => {
|
|
3
|
+
it('should return true for an array of numbers', () => {
|
|
4
|
+
expect(isArrayOfPrimitives([1, 2, 3])).toBe(true);
|
|
5
|
+
});
|
|
6
|
+
it('should return false for an empty array', () => {
|
|
7
|
+
expect(isArrayOfPrimitives([])).toBe(false);
|
|
8
|
+
});
|
|
9
|
+
it('should return true for an array of strings', () => {
|
|
10
|
+
expect(isArrayOfPrimitives(['hello', 'world'])).toBe(true);
|
|
11
|
+
});
|
|
12
|
+
it('should return false for an array containing a non-primitive value', () => {
|
|
13
|
+
expect(isArrayOfPrimitives([1, {}, 3])).toBe(false);
|
|
14
|
+
});
|
|
15
|
+
it('should return true for an array containing null and undefined values by default', () => {
|
|
16
|
+
expect(isArrayOfPrimitives([1, null, undefined])).toBe(true);
|
|
17
|
+
});
|
|
18
|
+
it('should return false for an array containing null and undefined values if includeNullAndUndefined is set to false', () => {
|
|
19
|
+
expect(isArrayOfPrimitives([1, null, undefined], false)).toBe(false);
|
|
20
|
+
});
|
|
21
|
+
it('should return true for an array containing boolean values', () => {
|
|
22
|
+
expect(isArrayOfPrimitives([true, false])).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
it('should return true for an array containing mixed primitive types', () => {
|
|
25
|
+
expect(isArrayOfPrimitives([1, 'string', true, null, undefined])).toBe(true);
|
|
26
|
+
});
|
|
27
|
+
it('should return false for a non-array value', () => {
|
|
28
|
+
expect(isArrayOfPrimitives('not an array')).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
it('should return false for an array containing mixed types, with a non-primitive included', () => {
|
|
31
|
+
expect(isArrayOfPrimitives([1, 'string', true, null, undefined, {}])).toBe(false);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
describe('isObject', () => {
|
|
35
|
+
test('should return true for non-empty object', () => {
|
|
36
|
+
const obj = { value: 123 };
|
|
37
|
+
expect(isObject(obj)).toEqual(true);
|
|
38
|
+
});
|
|
39
|
+
test('should return true for empty object', () => {
|
|
40
|
+
expect(isObject({})).toEqual(true);
|
|
41
|
+
});
|
|
42
|
+
test('should return true for an object', () => {
|
|
43
|
+
expect(isObject({ key: 'value' })).toBe(true);
|
|
44
|
+
});
|
|
45
|
+
test('should return false for an array', () => {
|
|
46
|
+
expect(isObject([1, 2, 3])).toBe(false);
|
|
47
|
+
});
|
|
48
|
+
test('should return false for null', () => {
|
|
49
|
+
expect(isObject(null)).toBe(false);
|
|
50
|
+
});
|
|
51
|
+
test('should return false for undefined', () => {
|
|
52
|
+
expect(isObject(undefined)).toBe(false);
|
|
53
|
+
});
|
|
54
|
+
test('should return false for a string', () => {
|
|
55
|
+
expect(isObject('string')).toBe(false);
|
|
56
|
+
});
|
|
57
|
+
test('should return false for a number', () => {
|
|
58
|
+
expect(isObject(42)).toBe(false);
|
|
59
|
+
});
|
|
60
|
+
test('should return false for a boolean', () => {
|
|
61
|
+
expect(isObject(true)).toBe(false);
|
|
62
|
+
expect(isObject(false)).toBe(false);
|
|
63
|
+
});
|
|
64
|
+
test('should return false for a function', () => {
|
|
65
|
+
expect(isObject(() => { })).toBe(false);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
describe('isPlainObject', () => {
|
|
69
|
+
it('should return false for undefined', () => {
|
|
70
|
+
expect(isPlainObject(undefined)).toBeFalsy();
|
|
71
|
+
});
|
|
72
|
+
it('should return false for null', () => {
|
|
73
|
+
expect(isPlainObject(null)).toBeFalsy();
|
|
74
|
+
});
|
|
75
|
+
it('should return false for boolean', () => {
|
|
76
|
+
expect(isPlainObject(true)).toBeFalsy();
|
|
77
|
+
expect(isPlainObject(false)).toBeFalsy();
|
|
78
|
+
});
|
|
79
|
+
it('should return false for number', () => {
|
|
80
|
+
expect(isPlainObject(0)).toBeFalsy();
|
|
81
|
+
expect(isPlainObject(123)).toBeFalsy();
|
|
82
|
+
expect(isPlainObject(NaN)).toBeFalsy();
|
|
83
|
+
});
|
|
84
|
+
it('should return false for string', () => {
|
|
85
|
+
expect(isPlainObject('')).toBeFalsy();
|
|
86
|
+
expect(isPlainObject('text')).toBeFalsy();
|
|
87
|
+
});
|
|
88
|
+
it('should return false for symbol', () => {
|
|
89
|
+
expect(isPlainObject(Symbol())).toBeFalsy();
|
|
90
|
+
});
|
|
91
|
+
it('should return false for bigint', () => {
|
|
92
|
+
expect(isPlainObject(BigInt(10))).toBeFalsy();
|
|
93
|
+
});
|
|
94
|
+
it('should return false for function', () => {
|
|
95
|
+
expect(isPlainObject(() => { return undefined; })).toBeFalsy();
|
|
96
|
+
expect(isPlainObject(function () { return undefined; })).toBeFalsy();
|
|
97
|
+
});
|
|
98
|
+
it('should return false for array', () => {
|
|
99
|
+
expect(isPlainObject([])).toBeFalsy();
|
|
100
|
+
expect(isPlainObject([1, 2, 3])).toBeFalsy();
|
|
101
|
+
});
|
|
102
|
+
it('should return false for Date', () => {
|
|
103
|
+
expect(isPlainObject(new Date())).toBeFalsy();
|
|
104
|
+
});
|
|
105
|
+
it('should return false for RegExp', () => {
|
|
106
|
+
expect(isPlainObject(/abc/)).toBeFalsy();
|
|
107
|
+
});
|
|
108
|
+
it('should return false for Map', () => {
|
|
109
|
+
expect(isPlainObject(new Map())).toBeFalsy();
|
|
110
|
+
});
|
|
111
|
+
it('should return false for Set', () => {
|
|
112
|
+
expect(isPlainObject(new Set())).toBeFalsy();
|
|
113
|
+
});
|
|
114
|
+
it('should return false for Error', () => {
|
|
115
|
+
expect(isPlainObject(new Error('test'))).toBeFalsy();
|
|
116
|
+
});
|
|
117
|
+
it('should return false for class instance', () => {
|
|
118
|
+
class Test {
|
|
119
|
+
}
|
|
120
|
+
expect(isPlainObject(new Test())).toBeFalsy();
|
|
121
|
+
});
|
|
122
|
+
it('should return false for object wrapper types', () => {
|
|
123
|
+
expect(isPlainObject(new String('test'))).toBeFalsy();
|
|
124
|
+
expect(isPlainObject(new Number(123))).toBeFalsy();
|
|
125
|
+
expect(isPlainObject(new Boolean(true))).toBeFalsy();
|
|
126
|
+
});
|
|
127
|
+
it('should return false for Promise', () => {
|
|
128
|
+
expect(isPlainObject(Promise.resolve())).toBeFalsy();
|
|
129
|
+
});
|
|
130
|
+
it('should return false for global objects', () => {
|
|
131
|
+
expect(isPlainObject(Math)).toBeFalsy();
|
|
132
|
+
expect(isPlainObject(JSON)).toBeFalsy();
|
|
133
|
+
});
|
|
134
|
+
it('should return true for empty object', () => {
|
|
135
|
+
expect(isPlainObject({})).toBeTruthy();
|
|
136
|
+
});
|
|
137
|
+
it('should return true for non-empty object', () => {
|
|
138
|
+
expect(isPlainObject({ a: 1 })).toBeTruthy();
|
|
139
|
+
});
|
|
140
|
+
it('should return true for object created with Object constructor', () => {
|
|
141
|
+
expect(isPlainObject(new Object())).toBeTruthy();
|
|
142
|
+
});
|
|
143
|
+
it('should return true for object with null prototype', () => {
|
|
144
|
+
expect(isPlainObject(Object.create(null))).toBeTruthy();
|
|
145
|
+
});
|
|
146
|
+
it('should return true for object of strings', () => {
|
|
147
|
+
expect(isPlainObject({ a: 'a', b: 'b' })).toBeTruthy();
|
|
148
|
+
});
|
|
149
|
+
it('should return true for object of objects', () => {
|
|
150
|
+
expect(isPlainObject({ a: new Object(), b: [] })).toBeTruthy();
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
describe('isPrimitive', () => {
|
|
154
|
+
test('should return true for string', () => {
|
|
155
|
+
expect(isPrimitive('Hello')).toBe(true);
|
|
156
|
+
});
|
|
157
|
+
test('should return true for number', () => {
|
|
158
|
+
expect(isPrimitive(123)).toBe(true);
|
|
159
|
+
});
|
|
160
|
+
test('should return true for boolean', () => {
|
|
161
|
+
expect(isPrimitive(true)).toBe(true);
|
|
162
|
+
expect(isPrimitive(false)).toBe(true);
|
|
163
|
+
});
|
|
164
|
+
test('should return true for null if includeNullAndUndefined is set to false', () => {
|
|
165
|
+
expect(isPrimitive(null, true)).toBe(true);
|
|
166
|
+
});
|
|
167
|
+
test('should return true for undefined if includeNullAndUndefined is set to false', () => {
|
|
168
|
+
expect(isPrimitive(undefined, true)).toBe(true);
|
|
169
|
+
});
|
|
170
|
+
test('should return false for null if includeNullAndUndefined is set to true', () => {
|
|
171
|
+
expect(isPrimitive(null, false)).toBe(false);
|
|
172
|
+
});
|
|
173
|
+
test('should return false for undefined if includeNullAndUndefined is set to true', () => {
|
|
174
|
+
expect(isPrimitive(undefined, false)).toBe(false);
|
|
175
|
+
});
|
|
176
|
+
test('should return true for symbol', () => {
|
|
177
|
+
expect(isPrimitive(Symbol('symbol'))).toBe(true);
|
|
178
|
+
});
|
|
179
|
+
test('should return false for object', () => {
|
|
180
|
+
expect(isPrimitive({})).toBe(false);
|
|
181
|
+
expect(isPrimitive({ key: 'value' })).toBe(false);
|
|
182
|
+
});
|
|
183
|
+
test('should return false for array', () => {
|
|
184
|
+
expect(isPrimitive([])).toBe(false);
|
|
185
|
+
expect(isPrimitive([1, 2, 3])).toBe(false);
|
|
186
|
+
});
|
|
187
|
+
test('should return false for function', () => {
|
|
188
|
+
expect(isPrimitive(() => { })).toBe(false);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
describe('isStringOrNumber', () => {
|
|
192
|
+
test('returns false for non-empty object', () => {
|
|
193
|
+
const obj = { value: 123 };
|
|
194
|
+
expect(isStringOrNumber(obj)).toEqual(false);
|
|
195
|
+
});
|
|
196
|
+
test('returns false for empty object', () => {
|
|
197
|
+
expect(isStringOrNumber({})).toEqual(false);
|
|
198
|
+
});
|
|
199
|
+
test('should return false for an object', () => {
|
|
200
|
+
const obj = { key: 'value' };
|
|
201
|
+
expect(isStringOrNumber(obj)).toBe(false);
|
|
202
|
+
});
|
|
203
|
+
test('should return false for an array', () => {
|
|
204
|
+
const arr = [1, 2, 3];
|
|
205
|
+
expect(isStringOrNumber(arr)).toBe(false);
|
|
206
|
+
});
|
|
207
|
+
test('should return false for null', () => {
|
|
208
|
+
expect(isStringOrNumber(null)).toBe(false);
|
|
209
|
+
});
|
|
210
|
+
test('should return false for undefined', () => {
|
|
211
|
+
expect(isStringOrNumber(undefined)).toBe(false);
|
|
212
|
+
});
|
|
213
|
+
test('should return true for a non-empty string', () => {
|
|
214
|
+
expect(isStringOrNumber('string')).toBe(true);
|
|
215
|
+
});
|
|
216
|
+
test('should return true for an empty string', () => {
|
|
217
|
+
expect(isStringOrNumber('string')).toBe(true);
|
|
218
|
+
});
|
|
219
|
+
test('should return true for a positive number', () => {
|
|
220
|
+
expect(isStringOrNumber(42)).toBe(true);
|
|
221
|
+
});
|
|
222
|
+
test('should return true for a zero', () => {
|
|
223
|
+
expect(isStringOrNumber(42)).toBe(true);
|
|
224
|
+
});
|
|
225
|
+
test('should return true for a negative number', () => {
|
|
226
|
+
expect(isStringOrNumber(42)).toBe(true);
|
|
227
|
+
});
|
|
228
|
+
test('should return true for a float number', () => {
|
|
229
|
+
expect(isStringOrNumber(42.5)).toBe(true);
|
|
230
|
+
});
|
|
231
|
+
test('should return false for a boolean', () => {
|
|
232
|
+
expect(isStringOrNumber(true)).toBe(false);
|
|
233
|
+
expect(isStringOrNumber(false)).toBe(false);
|
|
234
|
+
});
|
|
235
|
+
test('should return false for a function', () => {
|
|
236
|
+
const func = () => { };
|
|
237
|
+
expect(isStringOrNumber(func)).toBe(false);
|
|
238
|
+
});
|
|
239
|
+
});
|