@qrvey/utils 1.1.2 → 1.1.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.
Files changed (128) hide show
  1. package/README.md +196 -143
  2. package/dist/cjs/constants/COLUMN_PROPERTY_VALUE.js +1 -1
  3. package/dist/cjs/date/constants/DATE_VALUES.js +1 -1
  4. package/dist/cjs/filters/adapters/FDToFlatUI.js +2 -1
  5. package/dist/cjs/filters/adapters/FDToUI.js +2 -1
  6. package/dist/cjs/filters/adapters/UIToFlatUI.js +2 -1
  7. package/dist/cjs/filters/adapters/UIToOldLogic.js +2 -1
  8. package/dist/cjs/filters/adapters/adaptFilterValues.d.ts +8 -0
  9. package/dist/cjs/filters/adapters/adaptFilterValues.js +18 -0
  10. package/dist/cjs/filters/adapters/flatUIToFD.js +2 -1
  11. package/dist/cjs/filters/adapters/flatUIToUI.js +2 -1
  12. package/dist/cjs/filters/adapters/logicToFlatUI.js +0 -3
  13. package/dist/cjs/filters/helpers/common/getFilterColumnLabel.js +1 -1
  14. package/dist/cjs/filters/helpers/common/getFiltersByParams.js +1 -1
  15. package/dist/cjs/filters/helpers/ui/getFilterPropertyLabel.d.ts +7 -0
  16. package/dist/cjs/filters/helpers/ui/getFilterPropertyLabel.js +13 -0
  17. package/dist/cjs/filters/helpers/ui/index.d.ts +1 -0
  18. package/dist/cjs/filters/helpers/ui/index.js +1 -0
  19. package/dist/cjs/filters/interfaces/common/IFSValueRelativeDate.d.ts +1 -1
  20. package/dist/cjs/general/array/filterNestedTree.d.ts +5 -2
  21. package/dist/cjs/general/array/filterNestedTree.js +13 -5
  22. package/dist/cjs/general/mix/isEmpty.js +3 -1
  23. package/dist/cjs/general/mix/isNull.js +1 -1
  24. package/dist/cjs/general/mix/randomId.d.ts +6 -3
  25. package/dist/cjs/general/mix/randomId.js +24 -7
  26. package/dist/cjs/general/mix/size.d.ts +5 -5
  27. package/dist/cjs/general/mix/size.js +9 -6
  28. package/dist/cjs/general/object/get.d.ts +1 -1
  29. package/dist/cjs/general/object/getAttribute.d.ts +9 -2
  30. package/dist/cjs/general/object/getAttribute.js +39 -8
  31. package/dist/cjs/general/object/hasProperty.d.ts +1 -1
  32. package/dist/cjs/general/object/hasProperty.js +10 -2
  33. package/dist/cjs/general/object/index.d.ts +1 -0
  34. package/dist/cjs/general/object/index.js +1 -0
  35. package/dist/cjs/general/object/isObject.js +1 -1
  36. package/dist/cjs/general/object/objectCopy.d.ts +7 -0
  37. package/dist/cjs/general/object/objectCopy.js +32 -0
  38. package/dist/cjs/general/string/capitalize.d.ts +3 -3
  39. package/dist/cjs/general/string/capitalize.js +6 -3
  40. package/dist/cjs/qrvey/getPropertyLabel.d.ts +2 -0
  41. package/dist/cjs/qrvey/getPropertyLabel.js +14 -0
  42. package/dist/cjs/qrvey/index.d.ts +1 -0
  43. package/dist/cjs/qrvey/index.js +1 -0
  44. package/dist/constants/COLUMN_PROPERTY_VALUE.js +2 -2
  45. package/dist/date/constants/DATE_VALUES.js +1 -1
  46. package/dist/filters/adapters/FDToFlatUI.js +2 -1
  47. package/dist/filters/adapters/FDToUI.js +2 -1
  48. package/dist/filters/adapters/UIToFlatUI.js +2 -1
  49. package/dist/filters/adapters/UIToOldLogic.js +2 -1
  50. package/dist/filters/adapters/adaptFilterValues.d.ts +8 -0
  51. package/dist/filters/adapters/adaptFilterValues.js +14 -0
  52. package/dist/filters/adapters/flatUIToFD.js +2 -1
  53. package/dist/filters/adapters/flatUIToUI.js +2 -1
  54. package/dist/filters/adapters/logicToFlatUI.js +0 -3
  55. package/dist/filters/helpers/common/getFilterColumnLabel.js +2 -2
  56. package/dist/filters/helpers/common/getFiltersByParams.js +1 -1
  57. package/dist/filters/helpers/ui/getFilterPropertyLabel.d.ts +7 -0
  58. package/dist/filters/helpers/ui/getFilterPropertyLabel.js +9 -0
  59. package/dist/filters/helpers/ui/index.d.ts +1 -0
  60. package/dist/filters/helpers/ui/index.js +1 -0
  61. package/dist/filters/interfaces/common/IFSValueRelativeDate.d.ts +1 -1
  62. package/dist/general/array/filterNestedTree.d.ts +5 -2
  63. package/dist/general/array/filterNestedTree.js +13 -5
  64. package/dist/general/mix/isEmpty.js +3 -1
  65. package/dist/general/mix/isNull.js +1 -1
  66. package/dist/general/mix/randomId.d.ts +6 -3
  67. package/dist/general/mix/randomId.js +24 -7
  68. package/dist/general/mix/size.d.ts +5 -5
  69. package/dist/general/mix/size.js +9 -6
  70. package/dist/general/object/get.d.ts +1 -1
  71. package/dist/general/object/getAttribute.d.ts +9 -2
  72. package/dist/general/object/getAttribute.js +39 -8
  73. package/dist/general/object/hasProperty.d.ts +1 -1
  74. package/dist/general/object/hasProperty.js +8 -0
  75. package/dist/general/object/index.d.ts +1 -0
  76. package/dist/general/object/index.js +1 -0
  77. package/dist/general/object/isObject.js +1 -1
  78. package/dist/general/object/objectCopy.d.ts +7 -0
  79. package/dist/general/object/objectCopy.js +28 -0
  80. package/dist/general/string/capitalize.d.ts +3 -3
  81. package/dist/general/string/capitalize.js +6 -3
  82. package/dist/qrvey/getPropertyLabel.d.ts +2 -0
  83. package/dist/qrvey/getPropertyLabel.js +10 -0
  84. package/dist/qrvey/index.d.ts +1 -0
  85. package/dist/qrvey/index.js +1 -0
  86. package/package.json +1 -1
  87. package/src/constants/COLUMN_PROPERTY_VALUE.ts +2 -2
  88. package/src/date/constants/DATE_VALUES.ts +1 -1
  89. package/src/filters/adapters/FDToFlatUI.ts +2 -1
  90. package/src/filters/adapters/FDToUI.ts +2 -0
  91. package/src/filters/adapters/UIToFlatUI.ts +2 -1
  92. package/src/filters/adapters/UIToOldLogic.ts +2 -1
  93. package/src/filters/adapters/adaptFilterValues.ts +17 -0
  94. package/src/filters/adapters/flatUIToFD.ts +2 -1
  95. package/src/filters/adapters/flatUIToUI.ts +2 -1
  96. package/src/filters/adapters/logicToFlatUI.ts +0 -3
  97. package/src/filters/helpers/backend/getAggFiltersBySummaryIndex.ts +1 -1
  98. package/src/filters/helpers/common/getFilterColumnLabel.ts +2 -2
  99. package/src/filters/helpers/common/getFiltersByParams.ts +1 -1
  100. package/src/filters/helpers/ui/getFilterPropertyLabel.ts +11 -0
  101. package/src/filters/helpers/ui/index.ts +1 -0
  102. package/src/filters/interfaces/common/IFSValueRelativeDate.ts +1 -1
  103. package/src/general/array/filterNestedTree.ts +13 -4
  104. package/src/general/mix/getTag.ts +1 -1
  105. package/src/general/mix/isEmpty.ts +3 -1
  106. package/src/general/mix/isNull.ts +1 -1
  107. package/src/general/mix/randomId.ts +24 -7
  108. package/src/general/mix/size.ts +10 -6
  109. package/src/general/object/get.ts +1 -1
  110. package/src/general/object/getAttribute.ts +47 -9
  111. package/src/general/object/hasProperty.ts +10 -1
  112. package/src/general/object/index.ts +1 -0
  113. package/src/general/object/isObject.ts +1 -1
  114. package/src/general/object/objectCopy.ts +35 -0
  115. package/src/general/string/capitalize.ts +7 -3
  116. package/src/qrvey/getPropertyLabel.ts +9 -0
  117. package/src/qrvey/index.ts +1 -0
  118. package/test/general/array/filterNestedTree.test.js +115 -0
  119. package/test/general/mix/getTag.test.js +101 -0
  120. package/test/general/mix/isEmpty.test.js +24 -24
  121. package/test/general/mix/isNull.test.js +72 -0
  122. package/test/general/mix/randomId.test.js +134 -0
  123. package/test/general/mix/size.test.js +87 -0
  124. package/test/general/object/cloneDeep.test.js +8 -16
  125. package/test/general/object/getAttribute.test.js +316 -0
  126. package/test/general/object/hasProperty.test.js +103 -0
  127. package/test/general/object/objectCopy.test.js +105 -0
  128. package/test/general/string/capitalize.test.js +87 -0
@@ -0,0 +1,115 @@
1
+ const { filterNestedTree } = require('../../../dist/cjs');
2
+
3
+ const filters = [
4
+ {
5
+ expressions: [
6
+ {
7
+ expressions: {
8
+ id: '123',
9
+ values: [{
10
+ enabled: true,
11
+ value: 'Hello World',
12
+ }]
13
+ },
14
+ operator: 'OR'
15
+ },
16
+ {
17
+ expressions: {
18
+ id: '345',
19
+ values: [{
20
+ enabled: true,
21
+ value: 'Hello World 2',
22
+ }]
23
+ },
24
+ operator: 'OR'
25
+ }
26
+ ],
27
+ operator: 'AND'
28
+ }
29
+ ];
30
+
31
+ const condition = (expression) => expression.expressions.id === '123';
32
+ const noMatchCondition = (expression) => expression.expressions.id === '890';
33
+
34
+ describe('Testing Undefined arguments', function () {
35
+ const emptyVariable = undefined;
36
+ const emptyArray = [];
37
+
38
+ const emptyString = '';
39
+
40
+ test('No Arguments', function () {
41
+ const emptyFilter = filterNestedTree();
42
+ expect(emptyFilter).toEqual([]);
43
+ });
44
+
45
+ test('Undefined First argument', function () {
46
+ const emptyFilter = filterNestedTree(emptyVariable);
47
+ expect(emptyFilter).toEqual([]);
48
+ });
49
+
50
+ test('Empty First argument', function () {
51
+ const undefinedVariable = filterNestedTree(emptyArray);
52
+ expect(undefinedVariable).toBe(emptyArray);
53
+ });
54
+
55
+ test('Undefined first argument and undefined second argument', function () {
56
+ const undefinedVariable = filterNestedTree(emptyVariable, emptyVariable);
57
+ expect(undefinedVariable).toEqual([]);
58
+ });
59
+
60
+ test('Undefined first argument and empty second argument', function () {
61
+ const undefinedVariable = filterNestedTree(emptyVariable, emptyString);
62
+ expect(undefinedVariable).toEqual([]);
63
+ });
64
+
65
+ test('Empty first argument and empty second argument', function () {
66
+ const undefinedVariable = filterNestedTree(emptyArray, emptyString);
67
+ expect(undefinedVariable).toBe(emptyArray);
68
+ });
69
+
70
+ test('Undefined first argument, undefined second argument and undefined third argument', function () {
71
+ const undefinedVariable = filterNestedTree(emptyVariable, emptyVariable, emptyVariable);
72
+ expect(undefinedVariable).toEqual([]);
73
+ });
74
+ });
75
+
76
+ describe('Testing different arguments as expected', function () {
77
+ const first1 = 1;
78
+ const second1 = true;
79
+ const third1 = 'Hello';
80
+
81
+ test('Numeric first argument', function () {
82
+ const fNTfirst1 = filterNestedTree(first1, 'expressions', condition);
83
+ expect(fNTfirst1).toBe(first1);
84
+ });
85
+
86
+ test('Boolean second argument', function () {
87
+ const fNTSecond1 = filterNestedTree(filters, second1, condition);
88
+ expect(fNTSecond1).toBe(filters);
89
+ });
90
+
91
+ test('String Third argument', function () {
92
+ const fNTSecond1 = filterNestedTree(filters, 'expressions', third1);
93
+ expect(fNTSecond1).toBe(filters);
94
+ });
95
+ });
96
+
97
+ describe('Filtering array by condition', function () {
98
+ test('Regular scenario', function () {
99
+ const fNTfilters = filterNestedTree(filters, 'expressions', condition);
100
+ expect(fNTfilters).not.toEqual(expect.arrayContaining(filters));
101
+ expect(fNTfilters[0].expressions).toHaveLength(1);
102
+ expect(fNTfilters[0].expressions[1]).toBeUndefined();
103
+ });
104
+
105
+ test('No child is matched', function () {
106
+ const fNTfilters = filterNestedTree(filters, 'expressionss', condition);
107
+ expect(fNTfilters).toEqual([]);
108
+ });
109
+
110
+ test('No child is matched', function () {
111
+ const fNTfilters = filterNestedTree(filters, 'expressions', noMatchCondition);
112
+ expect(fNTfilters).not.toEqual(expect.arrayContaining(filters));
113
+ expect(fNTfilters[0].expressions).toHaveLength(0);
114
+ });
115
+ });
@@ -0,0 +1,101 @@
1
+ const { getTag } = require('../../../dist/cjs');
2
+
3
+ const tag1 = '[object Null]';
4
+ const tag2 = '[object Undefined]';
5
+ const tag3 = '[object Array]';
6
+ const tag4 = '[object Object]';
7
+ const tag5 = '[object String]';
8
+ const tag6 = '[object Date]';
9
+ const tag7 = '[object Boolean]';
10
+ const tag8 = '[object Number]';
11
+ const tag9 = '[object Map]';
12
+ const tag10 = '[object Set]';
13
+
14
+ describe('Testing with empty arguments', function () {
15
+ const empty1 = undefined;
16
+ const empty2 = [];
17
+ const empty3 = {};
18
+ const empty4 = '';
19
+ const empty5 = null;
20
+
21
+ test('No arguments', function () {
22
+ const tag = getTag();
23
+ expect(tag).toBe(tag2);
24
+ });
25
+
26
+ test('Undefined variable', function () {
27
+ const tag = getTag(empty1);
28
+ expect(tag).toBe(tag2);
29
+ });
30
+
31
+ test('Empty Array variable', function () {
32
+ const tag = getTag(empty2);
33
+ expect(tag).toBe(tag3);
34
+ });
35
+
36
+ test('Empty Object variable', function () {
37
+ const tag = getTag(empty3);
38
+ expect(tag).toBe(tag4);
39
+ });
40
+
41
+ test('Empty String variable', function () {
42
+ const tag = getTag(empty4);
43
+ expect(tag).toBe(tag5);
44
+ });
45
+
46
+ test('Null variable', function () {
47
+ const tag = getTag(empty5);
48
+ expect(tag).toBe(tag1);
49
+ });
50
+ });
51
+
52
+ describe('Regular scenarios', function () {
53
+ const variable1 = ['Hello', 'World'];
54
+ const variable2 = { tag1: 'Hello', tag2: 'World' };
55
+ const variable3 = 'Hello';
56
+ const variable4 = new Date('2021-10-01');
57
+ const variable5 = true;
58
+ const variable6 = 1;
59
+ const variable7 = new Map();
60
+ const variable8 = new Set();
61
+
62
+ test('Array type', function () {
63
+ const tag = getTag(variable1);
64
+ expect(tag).toBe(tag3);
65
+ });
66
+
67
+ test('Object type', function () {
68
+ const tag = getTag(variable2);
69
+ expect(tag).toBe(tag4);
70
+ });
71
+
72
+ test('String type' , function () {
73
+ const tag = getTag(variable3);
74
+ expect(tag).toBe(tag5);
75
+ });
76
+
77
+ test('Date Type' , function () {
78
+ const tag = getTag(variable4);
79
+ expect(tag).toBe(tag6);
80
+ });
81
+
82
+ test('Boolean Type' , function () {
83
+ const tag = getTag(variable5);
84
+ expect(tag).toBe(tag7);
85
+ });
86
+
87
+ test('Numeric Type' , function () {
88
+ const tag = getTag(variable6);
89
+ expect(tag).toBe(tag8);
90
+ });
91
+
92
+ test('Map Type' , function () {
93
+ const tag = getTag(variable7);
94
+ expect(tag).toBe(tag9);
95
+ });
96
+
97
+ test('Set Type' , function () {
98
+ const tag = getTag(variable8);
99
+ expect(tag).toBe(tag10);
100
+ });
101
+ });
@@ -9,27 +9,27 @@ describe('Validating the emptyness of the given argument', function () {
9
9
 
10
10
  test('Undefined', function () {
11
11
  const empty = isEmpty(empty1);
12
- expect(true).toEqual(empty);
12
+ expect(empty).toEqual(true);
13
13
  });
14
14
 
15
15
  test('Null type', function () {
16
16
  const empty = isEmpty(empty2);
17
- expect(true).toEqual(empty);
17
+ expect(empty).toEqual(true);
18
18
  });
19
19
 
20
20
  test('Empty string', function () {
21
21
  const empty = isEmpty(empty3);
22
- expect(true).toEqual(empty);
22
+ expect(empty).toEqual(true);
23
23
  });
24
24
 
25
25
  test('Array without items', function () {
26
26
  const empty = isEmpty(empty4);
27
- expect(true).toEqual(empty);
27
+ expect(empty).toEqual(true);
28
28
  });
29
29
 
30
30
  test('Object wihtout properties', function () {
31
31
  const empty = isEmpty(empty5);
32
- expect(true).toEqual(empty);
32
+ expect(empty).toEqual(true);
33
33
  });
34
34
  });
35
35
 
@@ -44,63 +44,63 @@ describe('Validating falsy arguments', function () {
44
44
 
45
45
  test('Zero number', function () {
46
46
  const empty = isEmpty(falsyEmpty1);
47
- expect(false).toEqual(empty);
47
+ expect(false).toEqual(false);
48
48
  });
49
49
 
50
50
  test('Zero number with Falsy', function () {
51
51
  const empty = isEmpty(falsyEmpty1, true);
52
- expect(true).toEqual(empty);
52
+ expect(empty).toEqual(true);
53
53
  });
54
54
 
55
55
  test('Zero floating number', function () {
56
56
  const empty = isEmpty(falsyEmpty2);
57
- expect(false).toEqual(empty);
57
+ expect(empty).toEqual(false);
58
58
  });
59
59
 
60
60
  test('Zero floating number with Falsy', function () {
61
61
  const empty = isEmpty(falsyEmpty2, true);
62
- expect(true).toEqual(empty);
62
+ expect(empty).toEqual(true);
63
63
  });
64
64
 
65
65
  test('Negative Zero number', function () {
66
66
  const empty = isEmpty(falsyEmpty3);
67
- expect(false).toEqual(empty);
67
+ expect(empty).toEqual(false);
68
68
  });
69
69
 
70
70
  test('Negative Zero number with Falsy', function () {
71
71
  const empty = isEmpty(falsyEmpty3, true);
72
- expect(true).toEqual(empty);
72
+ expect(empty).toEqual(true);
73
73
  });
74
74
 
75
75
  test('NaN', function () {
76
76
  const empty = isEmpty(falsyEmpty4);
77
- expect(false).toEqual(empty);
77
+ expect(empty).toEqual(false);
78
78
  });
79
79
 
80
80
  test('NaN with Falsy', function () {
81
81
  const empty = isEmpty(falsyEmpty4, true);
82
- expect(true).toEqual(empty);
82
+ expect(empty).toEqual(true);
83
83
  });
84
84
 
85
85
 
86
86
  test('Affirmative Boolean', function () {
87
87
  const empty = isEmpty(falsyEmpty5);
88
- expect(false).toEqual(empty);
88
+ expect(empty).toEqual(false);
89
89
  });
90
90
 
91
91
  test('Affirmative Boolean with Falsy', function () {
92
92
  const empty = isEmpty(falsyEmpty5, true);
93
- expect(false).toEqual(empty);
93
+ expect(empty).toEqual(false);
94
94
  });
95
95
 
96
96
  test('Negative Boolean', function () {
97
97
  const empty = isEmpty(falsyEmpty6);
98
- expect(false).toEqual(empty);
98
+ expect(empty).toEqual(false);
99
99
  });
100
100
 
101
101
  test('Negative Boolean with Falsy', function () {
102
102
  const empty = isEmpty(falsyEmpty6, true);
103
- expect(true).toEqual(empty);
103
+ expect(empty).toEqual(true);
104
104
  });
105
105
  });
106
106
 
@@ -115,36 +115,36 @@ describe('Validating non-empty arguments', function () {
115
115
 
116
116
  test('String type', function () {
117
117
  const empty = isEmpty(notEmpty1);
118
- expect(false).toEqual(empty);
118
+ expect(empty).toEqual(false);
119
119
  });
120
120
 
121
121
  test('Array type', function () {
122
122
  const empty = isEmpty(notEmpty2);
123
- expect(false).toEqual(empty);
123
+ expect(empty).toEqual(false);
124
124
  });
125
125
 
126
126
  test('Object type', function () {
127
127
  const empty = isEmpty(notEmpty3);
128
- expect(false).toEqual(empty);
128
+ expect(empty).toEqual(false);
129
129
  });
130
130
 
131
131
  test('Number different to zero', function () {
132
132
  const empty = isEmpty(notEmpty4);
133
- expect(false).toEqual(empty);
133
+ expect(empty).toEqual(false);
134
134
  });
135
135
 
136
136
  test('Zero Number in string', function () {
137
137
  const empty = isEmpty(notEmpty5);
138
- expect(false).toEqual(empty);
138
+ expect(empty).toEqual(false);
139
139
  });
140
140
 
141
141
  test('Function type', function () {
142
142
  const empty = isEmpty(notEmpty6);
143
- expect(false).toEqual(empty);
143
+ expect(empty).toEqual(false);
144
144
  });
145
145
 
146
146
  test('Date object type', function () {
147
147
  const empty = isEmpty(notEmpty7);
148
- expect(false).toEqual(empty);
148
+ expect(empty).toEqual(false);
149
149
  });
150
150
  });
@@ -0,0 +1,72 @@
1
+ const { isNull } = require('../../../dist/cjs');
2
+
3
+ describe('Testing empty arguments', function () {
4
+ const empty1 = undefined;
5
+ const empty2 = [];
6
+ const empty3 = {};
7
+ const empty4 = '';
8
+ const empty5 = null;
9
+
10
+ test('No arguments', function () {
11
+ const nullable = isNull();
12
+ expect(nullable).toBeTruthy();
13
+ });
14
+
15
+ test('Undefined variable', function () {
16
+ const nullable = isNull(empty1);
17
+ expect(nullable).toBeTruthy();
18
+ });
19
+
20
+ test('Empty Array variable', function () {
21
+ const nullable = isNull(empty2);
22
+ expect(nullable).toBeFalsy();
23
+ });
24
+
25
+ test('Empty Object variable', function () {
26
+ const nullable = isNull(empty3);
27
+ expect(nullable).toBeFalsy();
28
+ });
29
+
30
+ test('Empty String variable', function () {
31
+ const nullable = isNull(empty4);
32
+ expect(nullable).toBeFalsy();
33
+ });
34
+
35
+ test('Null variable', function () {
36
+ const nullable = isNull(empty5);
37
+ expect(nullable).toBeTruthy();
38
+ });
39
+ });
40
+
41
+ describe('Testing non-empty arguments', function () {
42
+ const variable1 = ['Hello', 'World'];
43
+ const variable2 = { tag1: 'Hello', tag2: 'World' };
44
+ const variable3 = 'Hello';
45
+ const variable4 = false;
46
+ const variable5 = 1;
47
+
48
+ test('Array type', function () {
49
+ const nullable = isNull(variable1);
50
+ expect(nullable).toBeFalsy();
51
+ });
52
+
53
+ test('Object type', function () {
54
+ const nullable = isNull(variable2);
55
+ expect(nullable).toBeFalsy();
56
+ });
57
+
58
+ test('String type' , function () {
59
+ const nullable = isNull(variable3);
60
+ expect(nullable).toBeFalsy();
61
+ });
62
+
63
+ test('Date Type' , function () {
64
+ const nullable = isNull(variable4);
65
+ expect(nullable).toBeFalsy();
66
+ });
67
+
68
+ test('Boolean Type' , function () {
69
+ const nullable = isNull(variable5);
70
+ expect(nullable).toBeFalsy();
71
+ });
72
+ });
@@ -0,0 +1,134 @@
1
+ const { randomId } = require('../../../dist/cjs');
2
+
3
+ describe('Testing empty arguments', function () {
4
+ const empty1 = undefined;
5
+
6
+ test('No arguments', function () {
7
+ const id = randomId();
8
+ expect(id).toHaveLength(8);
9
+ });
10
+
11
+ test('Undefined variable', function () {
12
+ const id = randomId(empty1);
13
+ expect(id).toHaveLength(8);
14
+ });
15
+ });
16
+
17
+ describe('Testing different type argument', function () {
18
+ const variable1 = ['Hello', 'World'];
19
+ const variable2 = { tag1: 'Hello', tag2: 'World' };
20
+ const variable3 = 'Hello';
21
+ const variable4 = false;
22
+ const variable5 = '1';
23
+ const variable6 = [false, 1, true, new Date()];
24
+
25
+ test('Array type', function () {
26
+ const id = randomId(variable1);
27
+ expect(id).toHaveLength(8);
28
+ });
29
+
30
+ test('Object type', function () {
31
+ const id = randomId(variable2);
32
+ expect(id).toHaveLength(8);
33
+ });
34
+
35
+ test('String type' , function () {
36
+ const id = randomId(variable3);
37
+ expect(id).toHaveLength(8);
38
+ });
39
+
40
+ test('Date Type' , function () {
41
+ const id = randomId(variable4);
42
+ expect(id).toHaveLength(8);
43
+ });
44
+
45
+ test('Boolean Type' , function () {
46
+ const id = randomId(variable5);
47
+ expect(id).toHaveLength(8);
48
+ });
49
+
50
+ test('Correct first argument but incorrect second one', function() {
51
+ const id = randomId(1, variable3);
52
+ expect(id).toHaveLength(1);
53
+ });
54
+
55
+ test('An array as second argument but incorrect item types', function() {
56
+ const id = randomId(1, variable6);
57
+ expect(id).toHaveLength(1);
58
+ });
59
+ });
60
+
61
+ describe('Regular scenarios', function () {
62
+ const length1 = 0;
63
+ const length2 = 1;
64
+ const length3 = 2;
65
+ const length4 = 3;
66
+ const length5 = 5;
67
+ const length6 = 8;
68
+ const length7 = 13;
69
+ const length8 = 21;
70
+ const length9 = 34;
71
+
72
+ test('0-lenght', function () {
73
+ const id = randomId(length1);
74
+ expect(id).toHaveLength(length1);
75
+ });
76
+
77
+ test('1-lenght', function () {
78
+ const id = randomId(length2);
79
+ expect(id).toHaveLength(length2);
80
+ });
81
+
82
+ test('2-lenght' , function () {
83
+ const id = randomId(length3);
84
+ expect(id).toHaveLength(length3);
85
+ });
86
+
87
+ test('3-lenght' , function () {
88
+ const id = randomId(length4);
89
+ expect(id).toHaveLength(length4);
90
+ });
91
+
92
+ test('5-lenght' , function () {
93
+ const id = randomId(length5);
94
+ expect(id).toHaveLength(length5);
95
+ });
96
+
97
+ test('8-lenght' , function () {
98
+ const id = randomId(length6);
99
+ expect(id).toHaveLength(length6);
100
+ });
101
+
102
+ test('13-lenght' , function () {
103
+ const id = randomId(length7);
104
+ expect(id).toHaveLength(length7);
105
+ });
106
+
107
+ test('21-lenght' , function () {
108
+ const id = randomId(length8);
109
+ expect(id).toHaveLength(length8);
110
+ });
111
+
112
+ test('34-lenght' , function () {
113
+ const id = randomId(length9);
114
+ expect(id).toHaveLength(length9);
115
+ });
116
+ });
117
+
118
+ describe('Excluding repeated ids', function () {
119
+ const length1 = 1;
120
+ const excludeAll = [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "_" ];
121
+ const excludeExcept9 = [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "_" ];
122
+
123
+ test('Excluding all excepts 9' , function () {
124
+ const id = randomId(length1, excludeExcept9);
125
+ expect(id).toHaveLength(length1);
126
+ expect(id).toBe("9");
127
+ });
128
+
129
+ test('Excluding all' , function () {
130
+ const id = randomId(length1, excludeAll);
131
+ expect(id).toHaveLength(0);
132
+ expect(id).toBe("");
133
+ });
134
+ });
@@ -0,0 +1,87 @@
1
+ const { size } = require('../../../dist/cjs');
2
+
3
+ describe('Testing empty arguments', function () {
4
+ const empty1 = undefined;
5
+ const empty2 = [];
6
+ const empty3 = {};
7
+ const empty4 = '';
8
+
9
+ test('No arguments', function () {
10
+ const _length = size();
11
+ expect(_length).toBe(0);
12
+ });
13
+
14
+ test('Undefined variable', function () {
15
+ const _length = size(empty1);
16
+ expect(_length).toBe(0);
17
+ });
18
+
19
+ test('Empty array variable', function () {
20
+ const _length = size(empty2);
21
+ expect(_length).toBe(0);
22
+ });
23
+
24
+ test('Empty object variable', function () {
25
+ const _length = size(empty3);
26
+ expect(_length).toBe(0);
27
+ });
28
+
29
+ test('Empty string variable', function () {
30
+ const _length = size(empty4);
31
+ expect(_length).toBe(0);
32
+ });
33
+ });
34
+
35
+ describe('Testing different object-type arguments', function () {
36
+ const variable1 = new Date();
37
+ const variable2 = false;
38
+ const variable3 = 1234;
39
+ const variable4 = (dig1 = 1, dig2 = 2) => dig1 + dig2;
40
+
41
+ test('Date type', function () {
42
+ const _length = size(variable1);
43
+ expect(_length).toBe(0);
44
+ });
45
+
46
+ test('Boolean type', function () {
47
+ const _length = size(variable2);
48
+ expect(_length).toBe(0);
49
+ });
50
+
51
+ test('Numeric type', function () {
52
+ const _length = size(variable3);
53
+ expect(_length).toBe(0);
54
+ });
55
+
56
+ test('Function type', function () {
57
+ const _length = size(variable4);
58
+ expect(_length).toBe(0);
59
+ });
60
+ });
61
+
62
+ describe('Regular scenarios', function () {
63
+ const variable1 = ['Hello', 'World'];
64
+ const variable2 = { tag1: 'Hello', tag2: 'World' };
65
+ const variable3 = [{ name: 'Jose' }, { name: 'David' }, { name: 'Eduardo' }];
66
+ const variable4 = "Hello World";
67
+
68
+ test('Array type', function () {
69
+ const _length = size(variable1);
70
+ expect(_length).toBe(2);
71
+ });
72
+
73
+ test('Object type', function () {
74
+ const _length = size(variable2);
75
+ expect(_length).toBe(2);
76
+ });
77
+
78
+ test('Object array type' , function () {
79
+ const _length = size(variable3);
80
+ expect(_length).toBe(3);
81
+ });
82
+
83
+ test('String Type' , function () {
84
+ const _length = size(variable4);
85
+ expect(_length).toBe(11);
86
+ });
87
+ });