@webalternatif/js-core 1.0.0 → 1.1.1

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 (80) hide show
  1. package/package.json +14 -3
  2. package/.babelrc +0 -12
  3. package/.idea/inspectionProfiles/Project_Default.xml +0 -12
  4. package/.idea/js-core.iml +0 -8
  5. package/.idea/modules.xml +0 -8
  6. package/.idea/php.xml +0 -20
  7. package/.idea/vcs.xml +0 -6
  8. package/i18n/agenda/en.js +0 -73
  9. package/i18n/agenda/fr.js +0 -73
  10. package/i18n/agenda/index.js +0 -2
  11. package/i18n/ajaxform/en.js +0 -5
  12. package/i18n/ajaxform/fr.js +0 -5
  13. package/i18n/ajaxform/index.js +0 -2
  14. package/i18n/ajaxupload/en.js +0 -12
  15. package/i18n/ajaxupload/fr.js +0 -12
  16. package/i18n/ajaxupload/index.js +0 -2
  17. package/i18n/autocomplete/en.js +0 -3
  18. package/i18n/autocomplete/fr.js +0 -3
  19. package/i18n/autocomplete/index.js +0 -2
  20. package/i18n/confirm/en.js +0 -5
  21. package/i18n/confirm/fr.js +0 -5
  22. package/i18n/confirm/index.js +0 -2
  23. package/i18n/core/en.js +0 -4
  24. package/i18n/core/fr.js +0 -4
  25. package/i18n/core/index.js +0 -2
  26. package/i18n/datagrid/en.js +0 -8
  27. package/i18n/datagrid/fr.js +0 -8
  28. package/i18n/datagrid/index.js +0 -2
  29. package/i18n/date/en.js +0 -51
  30. package/i18n/date/fr.js +0 -51
  31. package/i18n/date/index.js +0 -2
  32. package/i18n/datetimepicker/en.js +0 -30
  33. package/i18n/datetimepicker/fr.js +0 -30
  34. package/i18n/datetimepicker/index.js +0 -2
  35. package/i18n/dialog/en.js +0 -3
  36. package/i18n/dialog/fr.js +0 -3
  37. package/i18n/dialog/index.js +0 -2
  38. package/i18n/fulldayeventagenda/en.js +0 -73
  39. package/i18n/fulldayeventagenda/fr.js +0 -73
  40. package/i18n/fulldayeventagenda/index.js +0 -2
  41. package/i18n/index.d.ts +0 -4
  42. package/i18n/index.js +0 -15
  43. package/i18n/richtexteditor/en.js +0 -58
  44. package/i18n/richtexteditor/fr.js +0 -58
  45. package/i18n/richtexteditor/index.js +0 -2
  46. package/i18n/select/en.js +0 -3
  47. package/i18n/select/fr.js +0 -3
  48. package/i18n/select/index.js +0 -2
  49. package/i18n/timepicker/en.js +0 -3
  50. package/i18n/timepicker/fr.js +0 -3
  51. package/i18n/timepicker/index.js +0 -2
  52. package/i18n/useragenda/en.js +0 -74
  53. package/i18n/useragenda/fr.js +0 -73
  54. package/i18n/useragenda/index.js +0 -2
  55. package/jest.config.js +0 -14
  56. package/src/array.js +0 -124
  57. package/src/dom.js +0 -569
  58. package/src/eventDispatcher.js +0 -118
  59. package/src/i18n.js +0 -55
  60. package/src/index.js +0 -33
  61. package/src/is.js +0 -89
  62. package/src/math.js +0 -109
  63. package/src/random.js +0 -40
  64. package/src/string.js +0 -576
  65. package/src/stringPrototype.js +0 -15
  66. package/src/traversal.js +0 -134
  67. package/src/utils.js +0 -130
  68. package/tests/array.test.js +0 -326
  69. package/tests/dom.test.js +0 -239
  70. package/tests/eventdispatcher.test.js +0 -177
  71. package/tests/i18n.test.js +0 -132
  72. package/tests/index.test.js +0 -29
  73. package/tests/is.test.js +0 -354
  74. package/tests/math.test.js +0 -221
  75. package/tests/random.test.js +0 -72
  76. package/tests/string.test.js +0 -1106
  77. package/tests/traversal.test.js +0 -517
  78. package/tests/utils.test.js +0 -371
  79. package/tsconfig.json +0 -16
  80. package/webpack.config.cjs +0 -31
@@ -1,371 +0,0 @@
1
- import {
2
- equals,
3
- sizeOf,
4
- flatten, noop,
5
- strParseFloat, throttle, debounce
6
- } from "../src/utils";
7
-
8
- describe('utils methods', () => {
9
- describe('equals()', () => {
10
- it('should return true for strictly equal primitive values', () => {
11
- expect(equals(42, 42)).toBe(true);
12
- expect(equals('hello', 'hello')).toBe(true);
13
- expect(equals(true, true)).toBe(true);
14
- })
15
-
16
- it('should return false for different primitive values', () => {
17
- expect(equals(42, 24)).toBe(false);
18
- expect(equals('hello', 'world')).toBe(false);
19
- expect(equals(true, false)).toBe(false);
20
- })
21
-
22
- it('should return false if types are different', () => {
23
- expect(equals(42, '42')).toBe(false);
24
- expect(equals(true, 'true')).toBe(false);
25
- })
26
-
27
- it('should return false if one value is null or undefined', () => {
28
- expect(equals(null, {})).toBe(false);
29
- expect(equals({}, null)).toBe(false);
30
- expect(equals(undefined, {})).toBe(false);
31
- })
32
-
33
- it('should return true for deeply equal objects', () => {
34
- const obj1 = { a: 1, b: { c: 2 } };
35
- const obj2 = { a: 1, b: { c: 2 } };
36
-
37
- expect(equals(obj1, obj2)).toBe(true);
38
- })
39
-
40
- it('should return false for objects with different structures', () => {
41
- const obj1 = { a: 1, b: { c: 2 } };
42
- const obj2 = { a: 1, b: { d: 3 } };
43
-
44
- expect(equals(obj1, obj2)).toBe(false);
45
- })
46
-
47
- it('should return false for objects with different keys', () => {
48
- const obj1 = { a: 1, b: 2 };
49
- const obj2 = { a: 1, c: 3 };
50
-
51
- expect(equals(obj1, obj2)).toBe(false);
52
- })
53
-
54
- it('should return true for deeply nested empty objects', () => {
55
- const obj1 = {};
56
- const obj2 = {};
57
-
58
- expect(equals(obj1, obj2)).toBe(true);
59
- })
60
-
61
- it('should handle circular references gracefully', () => {
62
- const obj1 = {};
63
- const obj2 = {};
64
- obj1.self = obj1;
65
- obj2.self = obj2;
66
-
67
- expect(equals(obj1, obj2)).toBe(true);
68
- })
69
-
70
- it('should return true for empty objects', () => {
71
- const obj1 = {};
72
- const obj2 = {};
73
-
74
- expect(equals(obj1, obj2)).toBe(true);
75
- })
76
-
77
- it('should return false for objects with different lengths', () => {
78
- const obj1 = { a: 1 };
79
- const obj2 = { a: 1, b: 2 };
80
-
81
- expect(equals(obj1, obj2)).toBe(false);
82
- })
83
- })
84
-
85
- describe('sizeOf()', () => {
86
- it('should return the length of an array, object', () => {
87
- expect(sizeOf([1, 2, 3])).toBe(3);
88
- expect(sizeOf({ a: 1, b: 2, c: 3 })).toBe(3);
89
- })
90
-
91
- it('should return 0 for an empty array, empty object, null, undefined', () => {
92
- expect(sizeOf([])).toBe(0);
93
- expect(sizeOf({})).toBe(0);
94
- expect(sizeOf(null)).toBe(0);
95
- expect(sizeOf(undefined)).toBe(0);
96
- })
97
- })
98
-
99
- describe('flatten()', () => {
100
- it('should flatten a nested array', () => {
101
- const input = [1, [2, [3, [4, 5]]], 6];
102
- const result = flatten(input);
103
- expect(result).toEqual([1, 2, 3, 4, 5, 6]);
104
- })
105
-
106
- it('should flatten an object into an array', () => {
107
- const input = { a: 1, b: [2, { c: 3 }], d: 4 };
108
- const result = flatten(input);
109
- expect(result).toEqual([1, 2, 3, 4]);
110
- })
111
-
112
- it('should return a flat array when input is already flat', () => {
113
- const input = [1, 2, 3, 4, 5];
114
- const result = flatten(input);
115
- expect(result).toEqual([1, 2, 3, 4, 5]);
116
- })
117
-
118
- it('should return the input unchanged if it is not an object or array', () => {
119
- const input = 42;
120
- const result = flatten(input);
121
- expect(result).toBe(42);
122
-
123
- const inputString = 'hello';
124
- const resultString = flatten(inputString);
125
- expect(resultString).toBe('hello');
126
- })
127
-
128
- it('should handle null or undefined inputs', () => {
129
- expect(flatten(null)).toBe(null);
130
- expect(flatten(undefined)).toBe(undefined);
131
- })
132
-
133
- it('should handle an empty array', () => {
134
- const input = [];
135
- const result = flatten(input);
136
- expect(result).toEqual([]);
137
- })
138
-
139
- it('should handle an empty object', () => {
140
- const input = {};
141
- const result = flatten(input);
142
- expect(result).toEqual([]);
143
- })
144
- })
145
-
146
- describe('noop()', () => {
147
- it('should not perform any operation', () => {
148
- const spy = jest.fn(noop);
149
- spy();
150
- expect(spy).toHaveBeenCalledTimes(1);
151
- })
152
- })
153
-
154
- describe('strParseFloat()', () => {
155
- it('should parse a valid float string', () => {
156
- expect(strParseFloat('123.45')).toBe(123.45);
157
- })
158
-
159
- it('should parse a string with commas as decimal separator', () => {
160
- expect(strParseFloat('123,45')).toBe(123.45);
161
- })
162
-
163
- it('should parse a string with spaces', () => {
164
- expect(strParseFloat(' 123.45 ')).toBe(123.45);
165
- })
166
-
167
- it('should handle a string with mixed spaces and commas', () => {
168
- expect(strParseFloat(' 1 234,56 ')).toBe(1234.56);
169
- })
170
-
171
- it('should handle null input and return 0', () => {
172
- expect(strParseFloat(null)).toBe(0);
173
- })
174
-
175
- it('should handle undefined input and return 0', () => {
176
- expect(strParseFloat(undefined)).toBe(0);
177
- })
178
-
179
- it('should handle an empty string and return 0', () => {
180
- expect(strParseFloat('')).toBe(0);
181
- })
182
-
183
- it('should handle input that is already a number', () => {
184
- expect(strParseFloat(123.45)).toBe(123.45);
185
- })
186
-
187
- it('should handle input with extra characters gracefully', () => {
188
- expect(strParseFloat('123.45abc')).toBe(123.45);
189
- })
190
-
191
- it('should handle strings with no numeric values and return NaN', () => {
192
- expect(strParseFloat('abc')).toBeNaN();
193
- })
194
- })
195
-
196
- describe('throttle', () => {
197
- jest.useFakeTimers();
198
-
199
- it('should call the function immediately if leading is true', () => {
200
- const mockfunc = jest.fn();
201
- const throttled = throttle(mockfunc, 1000, true, false);
202
-
203
- throttled();
204
- expect(mockfunc).toHaveBeenCalledTimes(1);
205
-
206
- throttled();
207
- expect(mockfunc).toHaveBeenCalledTimes(1);
208
-
209
- jest.advanceTimersByTime(1000);
210
- throttled();
211
- expect(mockfunc).toHaveBeenCalledTimes(2);
212
- })
213
-
214
- it('should not call the function immediately if leading is false', () => {
215
- const mockfunc = jest.fn();
216
- const throttled = throttle(mockfunc, 1000, false, true);
217
-
218
- throttled();
219
- expect(mockfunc).toHaveBeenCalledTimes(0);
220
-
221
- jest.advanceTimersByTime(1000);
222
- expect(mockfunc).toHaveBeenCalledTimes(1);
223
- })
224
-
225
- it('should call the function at the end if trailing is true', () => {
226
- const mockfunc = jest.fn();
227
- const throttled = throttle(mockfunc, 1000, false, true);
228
-
229
- throttled();
230
- jest.advanceTimersByTime(500);
231
- throttled();
232
- jest.advanceTimersByTime(500);
233
- expect(mockfunc).toHaveBeenCalledTimes(1);
234
- })
235
-
236
- it('should not call the function at the end if trailing is false', () => {
237
- const func = jest.fn();
238
- const throttled = throttle(func, 1000, true, false);
239
-
240
- throttled();
241
- jest.advanceTimersByTime(500);
242
- throttled();
243
- jest.advanceTimersByTime(500);
244
- expect(func).toHaveBeenCalledTimes(1);
245
- })
246
-
247
- it('should respect the wait time between calls', () => {
248
- const func = jest.fn();
249
- const throttled = throttle(func, 1000);
250
-
251
- throttled();
252
- expect(func).toHaveBeenCalledTimes(1);
253
-
254
- jest.advanceTimersByTime(500);
255
- throttled();
256
- expect(func).toHaveBeenCalledTimes(1);
257
-
258
- jest.advanceTimersByTime(500);
259
- throttled();
260
- expect(func).toHaveBeenCalledTimes(2);
261
- })
262
-
263
- it('should use the provided context', () => {
264
- const context = { value: 42 };
265
- const func = jest.fn(function() {
266
- expect(this.value).toBe(42);
267
- })
268
-
269
- const throttled = throttle(func, 1000, true, true, context);
270
- throttled();
271
- })
272
-
273
- it('should handle multiple calls within the wait period', () => {
274
- const func = jest.fn();
275
- const throttled = throttle(func, 1000);
276
-
277
- throttled();
278
- throttled();
279
- throttled();
280
- expect(func).toHaveBeenCalledTimes(1);
281
-
282
- jest.advanceTimersByTime(1000);
283
- expect(func).toHaveBeenCalledTimes(2);
284
- })
285
- })
286
-
287
- describe('debounce', () => {
288
- jest.useFakeTimers();
289
-
290
- it('should call the function after the wait time', () => {
291
- const func = jest.fn();
292
- const debounced = debounce(func, 1000);
293
-
294
- debounced();
295
- expect(func).not.toHaveBeenCalled();
296
-
297
- jest.advanceTimersByTime(1000);
298
- expect(func).toHaveBeenCalledTimes(1);
299
- })
300
-
301
- it('should reset the timer if called again within the wait time', () => {
302
- const func = jest.fn();
303
- const debounced = debounce(func, 1000);
304
-
305
- debounced();
306
- jest.advanceTimersByTime(500);
307
- debounced();
308
- jest.advanceTimersByTime(500);
309
-
310
- expect(func).not.toHaveBeenCalled();
311
-
312
- jest.advanceTimersByTime(500);
313
- expect(func).toHaveBeenCalledTimes(1);
314
- })
315
-
316
- it('should call the function immediately if immediate is true', () => {
317
- const func = jest.fn();
318
- const debounced = debounce(func, 1000, true);
319
-
320
- debounced();
321
- expect(func).toHaveBeenCalledTimes(1);
322
-
323
- debounced();
324
- expect(func).toHaveBeenCalledTimes(1);
325
-
326
- jest.advanceTimersByTime(1000);
327
- debounced();
328
- expect(func).toHaveBeenCalledTimes(2);
329
- })
330
-
331
- it('should use the provided context', () => {
332
- const context = { value: 42 };
333
- const func = jest.fn(function () {
334
- expect(this.value).toBe(42);
335
- })
336
-
337
- const debounced = debounce(func, 1000, false, context);
338
- debounced();
339
-
340
- jest.advanceTimersByTime(1000);
341
- expect(func).toHaveBeenCalledTimes(1);
342
- })
343
-
344
- it('should use the provided context', () => {
345
- const context = { value: 42 };
346
- const func = jest.fn(function () {
347
- expect(this.value).toBe(42);
348
- })
349
- const debounced = debounce(func, 1000, true, context);
350
-
351
- debounced();
352
- expect(func).toHaveBeenCalledTimes(1);
353
-
354
- debounced();
355
- expect(func).toHaveBeenCalledTimes(1);
356
-
357
- jest.advanceTimersByTime(1000);
358
- debounced();
359
- expect(func).toHaveBeenCalledTimes(2);
360
- })
361
-
362
- it('should not call the function if never invoked after the delay', () => {
363
- const func = jest.fn();
364
- const debounced = debounce(func, 1000);
365
-
366
- debounced();
367
- jest.advanceTimersByTime(500);
368
- expect(func).not.toHaveBeenCalled();
369
- })
370
- })
371
- })
package/tsconfig.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "lib": ["esnext", "dom"],
4
- "declaration": true,
5
- "emitDeclarationOnly": true,
6
- "outDir": "types",
7
- "allowJs": true,
8
- "checkJs": false,
9
- "strict": true,
10
- "esModuleInterop": true,
11
- "skipLibCheck": true,
12
- "baseUrl": "./",
13
- },
14
- "include": ["src/**/*.js"],
15
- "exclude": ["i18n", "index.js"]
16
- }
@@ -1,31 +0,0 @@
1
- const path = require('path');
2
-
3
- module.exports = {
4
- mode: 'production',
5
- entry: './src/index.js',
6
- output: {
7
- path: path.resolve(__dirname, 'dist'),
8
- library: 'webf',
9
- libraryTarget: 'umd',
10
- globalObject: 'this',
11
- filename: "index.js",
12
- publicPath: "/dist/",
13
- },
14
- optimization: {
15
- minimize: true,
16
- },
17
- module: {
18
- rules: [
19
- {
20
- test: /\.js$/,
21
- exclude: /node_modules/,
22
- use: {
23
- loader: 'babel-loader',
24
- options: {
25
- presets: ['@babel/preset-env'],
26
- },
27
- },
28
- },
29
- ],
30
- },
31
- };