@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,1106 +0,0 @@
1
- import * as is from '../src/is'
2
- import * as stringUtils from '../src/string'
3
- import {
4
- trim,
5
- ltrim,
6
- rtrim,
7
- stripMultipleSpaces,
8
- noAccent,
9
- br2nl,
10
- nl2br,
11
- ucfirst,
12
- lcfirst,
13
- insertTag,
14
- isString,
15
- insert,
16
- substringIndex,
17
- reverse,
18
- thousandSeparator,
19
- numberFormat,
20
- toPrice,
21
- pad,
22
- rgb2hex,
23
- hex2rgb,
24
- parse_url,
25
- addUrlParam,
26
- decodeHtml,
27
- htmlquotes,
28
- htmlsimplequotes,
29
- repeat,
30
- stripTags,
31
- toUrl,
32
- escapeRegex,
33
- camelCase,
34
- format,
35
- toCssClassName,
36
- compareMixAlphaDigits,
37
- formatSize,
38
- hilite
39
- } from "../src/string";
40
- import {setLang} from "../src/i18n.js";
41
-
42
- describe('String methods', () => {
43
- const [str1, str2, str3, str4, str5, str6, str7] = [
44
- 'On en a gros !',
45
- ' Hello World ',
46
- 'aaHello Worldaa',
47
- 'Hello World',
48
- 'àäâèéêëîïíöôüùçÿÀÄÂÈÉÊËÎÏÍÖÔÜÙÇŸ',
49
- 'Hello<br>world<br/>!<br />',
50
- '&amp;&lt;&gt;&quot;&#039;',
51
- ]
52
-
53
- describe('trim(), ltrim(), rtrim()', () => {
54
- it('should remove spaces at the beginning and end of the string', () => {
55
- expect(trim(str2)).toBe('Hello World');
56
- })
57
-
58
- it('should remove characters "a" at the beginning and end of the string', () => {
59
- expect(trim(str3, 'a')).toBe('Hello World');
60
- })
61
-
62
- it('should remove spaces at the beginning of the string', () => {
63
- expect(ltrim(str2)).toBe('Hello World ');
64
- })
65
-
66
- it('should remove characters "a" at the end of the string', () => {
67
- expect(ltrim(str3, 'a')).toBe('Hello Worldaa');
68
- })
69
-
70
- it('should remove spaces at the end of the string', () => {
71
- expect(rtrim(str2)).toBe(' Hello World');
72
- })
73
-
74
- it('should remove characters "a" at the end of the string', () => {
75
- expect(rtrim(str3, 'a')).toBe('aaHello World');
76
- })
77
- })
78
-
79
- describe('stripMultipleSpaces()', () => {
80
- it('should replace multiple spaces in the string with a single space.', () => {
81
- expect(stripMultipleSpaces(str4)).toBe('Hello World');
82
- })
83
- })
84
-
85
- describe('noAccent()', () => {
86
- it('should replace accented characters with their unaccented equivalents.', () => {
87
- expect(noAccent(str5)).toBe('aaaeeeeiiioouucyAAAEEEEIIIOOUUCY');
88
- })
89
- })
90
-
91
- describe('br2nl(), nl2br()', () => {
92
- it('should replace br tags with \n', () => {
93
- expect(br2nl(str6)).toBe('Hello\nworld\n!\n');
94
- })
95
-
96
- it('should replace \\n with br tags', () => {
97
- expect(nl2br(br2nl(str6))).toBe('Hello<br>world<br>!<br>');
98
- })
99
- })
100
-
101
- describe('ucfirst(), lcfirst()', () => {
102
- it('should make a string\'s first character uppercase', () => {
103
- expect(ucfirst(str1.toLowerCase())).toBe('On en a gros !');
104
- expect(ucfirst('étienne')).toBe('Étienne');
105
- })
106
-
107
- it('should Make a string\'s first character lowercase', () => {
108
- expect(lcfirst(str1.toUpperCase())).toBe('oN EN A GROS !');
109
- expect(lcfirst('ÉTIENNE')).toBe('éTIENNE');
110
- })
111
- })
112
-
113
- describe('insertTag()', () => {
114
- it('should wrap a specified portion of a string with given opening and closing tags', () => {
115
- expect(insertTag(str1, 'b', 8, 4)).toBe('On en a <b>gros</b> !');
116
- expect(insertTag(str1, 'br', 8)).toBe('On en a <br/>gros !');
117
- expect(insertTag(str1, 'span')).toBe('<span></span>On en a gros !');
118
- })
119
- })
120
-
121
- describe('isString()', () => {
122
- it('should return true for a primitive string', () => {
123
- expect(is.isString('hello')).toBe(true);
124
- })
125
-
126
- it('should return true for a String object', () => {
127
- expect(is.isString(new String('hello'))).toBe(true);
128
- })
129
- })
130
-
131
- describe('insert()', () => {
132
- it('should insert the specified string at regular intervals in the input string', () => {
133
- expect(insert('abcdefghi', '-', 3)).toBe('abc-def-ghi');
134
- expect(insert('123456789', '/', 2)).toBe('12/34/56/78/9');
135
- })
136
-
137
- it('should handle cases where n is greater than or equal to the string length', () => {
138
- expect(insert('hello', '*', 10)).toBe('hello');
139
- expect(insert('hello', '*', 5)).toBe('hello');
140
- })
141
-
142
- it('should handle empty strings', () => {
143
- expect(insert('', '-', 2)).toBe('');
144
- })
145
-
146
- it('should handle n = 0', () => {
147
- expect(insert('abcdef', '-', 0)).toBe('abcdef');
148
- })
149
-
150
- it('should handle single-character strings', () => {
151
- expect(insert('a', '-', 1)).toBe('a');
152
- expect(insert('a', '-', 0)).toBe('a');
153
- })
154
-
155
- it('should insert correctly when n = 1', () => {
156
- expect(insert('abc', '-', 1)).toBe('a-b-c');
157
- })
158
-
159
- it('should handle special characters in the insertion string', () => {
160
- expect(insert('abcdef', '#@', 2)).toBe('ab#@cd#@ef'); // Insère "#@" toutes les 2 lettres
161
- })
162
-
163
- it('should handle large strings and intervals', () => {
164
- const input = 'a'.repeat(1000);
165
- const expected = 'a'.repeat(99) + '-a';
166
- expect(insert(input, '-', 100)).toContain(expected);
167
- })
168
- })
169
-
170
- describe('substringIndex()', () => {
171
- it('should return the substring up to the specified positive index', () => {
172
- expect(substringIndex('a-b-c-d-e', '-', 3)).toBe('a-b-c');
173
- expect(substringIndex('apple.orange.banana', '.', 2)).toBe('apple.orange');
174
- })
175
-
176
- it('should return the substring starting from the specified negative index', () => {
177
- expect(substringIndex('a-b-c-d-e', '-', -2)).toBe('d-e');
178
- expect(substringIndex('apple.orange.banana', '.', -1)).toBe('banana');
179
- })
180
-
181
- it('should handle index = 0 by returning the original string', () => {
182
- expect(substringIndex('a-b-c-d-e', '-', 0)).toBe('a-b-c-d-e');
183
- expect(substringIndex('apple.orange.banana', '.', 0)).toBe('apple.orange.banana');
184
- })
185
-
186
- it('should handle cases where the index exceeds the length of the string', () => {
187
- expect(substringIndex('a-b-c', '-', 10)).toBe('a-b-c');
188
- expect(substringIndex('apple.orange', '.', 5)).toBe('apple.orange');
189
- })
190
-
191
- it('should handle cases where the negative index exceeds the length of the string', () => {
192
- expect(substringIndex('a-b-c', '-', -10)).toBe('a-b-c');
193
- expect(substringIndex('apple.orange', '.', -5)).toBe('apple.orange');
194
- })
195
-
196
- it('should handle strings without delimiters', () => {
197
- expect(substringIndex('abcdef', '-', 2)).toBe('abcdef');
198
- expect(substringIndex('abcdef', '-', -2)).toBe('abcdef');
199
- })
200
-
201
- it('should handle empty strings', () => {
202
- expect(substringIndex('', '-', 2)).toBe(''); // Chaîne vide retourne vide
203
- expect(substringIndex('', '-', -2)).toBe(''); // Chaîne vide retourne vide
204
- })
205
-
206
- it('should handle edge cases with single character strings and delimiters', () => {
207
- expect(substringIndex('-', '-', 1)).toBe(''); // Délimiteur seul retourne vide
208
- expect(substringIndex('-', '-', -1)).toBe(''); // Délimiteur seul retourne vide
209
- expect(substringIndex('a', '-', 1)).toBe('a'); // Aucune modification si pas de délimiteur
210
- })
211
- })
212
-
213
- describe('reverse function', () => {
214
- it('should reverse a regular string', () => {
215
- expect(reverse('hello')).toBe('olleh');
216
- expect(reverse('abcdef')).toBe('fedcba');
217
- })
218
-
219
- it('should handle an empty string', () => {
220
- expect(reverse('')).toBe('');
221
- })
222
-
223
- it('should handle a string with a single character', () => {
224
- expect(reverse('a')).toBe('a');
225
- })
226
-
227
- it('should handle strings with spaces', () => {
228
- expect(reverse('hello world')).toBe('dlrow olleh');
229
- expect(reverse(' a b ')).toBe(' b a ');
230
- })
231
-
232
- it('should handle strings with special characters', () => {
233
- expect(reverse('!@#$')).toBe('$#@!');
234
- expect(reverse('1234!')).toBe('!4321');
235
- })
236
-
237
- it('should handle strings with numbers', () => {
238
- expect(reverse('12345')).toBe('54321');
239
- expect(reverse('1a2b3c')).toBe('c3b2a1');
240
- })
241
- })
242
-
243
- describe('thousandSeparator()', () => {
244
- it('should format numbers with default separator and decimal point', () => {
245
- expect(thousandSeparator(1234567.89)).toBe('1.234.567.89');
246
- expect(thousandSeparator(1234)).toBe('1.234');
247
- })
248
-
249
- it('should handle negative numbers correctly', () => {
250
- expect(thousandSeparator(-1234567.89)).toBe('-1.234.567.89');
251
- expect(thousandSeparator(-1234)).toBe('-1.234');
252
- })
253
-
254
- it('should handle values less than 1000 without adding separators', () => {
255
- expect(thousandSeparator(999)).toBe('999');
256
- expect(thousandSeparator(-999)).toBe('-999');
257
- })
258
-
259
- it('should replace decimal point with a custom character', () => {
260
- expect(thousandSeparator(1234567.89, '.', ',')).toBe('1.234.567,89');
261
- expect(thousandSeparator(1234.56, '.', ',')).toBe('1.234,56');
262
- })
263
-
264
- it('should handle custom thousand separators', () => {
265
- expect(thousandSeparator(1234567.89, ',', '.')).toBe('1,234,567.89');
266
- expect(thousandSeparator(1234, ',', '.')).toBe('1,234');
267
- })
268
-
269
- it('should handle strings as input and convert commas to dots', () => {
270
- expect(thousandSeparator('1234,56')).toBe('1.234.56');
271
- expect(thousandSeparator('1234567,89')).toBe('1.234.567.89');
272
- })
273
-
274
- it('should handle edge cases like zero and empty strings', () => {
275
- expect(thousandSeparator(0)).toBe('0');
276
- expect(thousandSeparator('')).toBe('');
277
- })
278
-
279
- it('should handle invalid or non-numeric input gracefully', () => {
280
- expect(thousandSeparator('abc')).toBe('abc');
281
- expect(thousandSeparator(undefined)).toBeUndefined();
282
- })
283
- })
284
-
285
- describe('numberFormat(), toPrice()', () => {
286
- it('should format numbers with default parameters', () => {
287
- expect(numberFormat('12345.678')).toBe('12345.68');
288
- expect(numberFormat(12345.678)).toBe('12345.68');
289
- })
290
-
291
- it('should handle zero decimals and no thousand separator', () => {
292
- expect(numberFormat('12345.678', 0)).toBe('12346');
293
- expect(numberFormat(12345.678, 0)).toBe('12346');
294
- expect(numberFormat(12345.00, 0)).toBe('12345');
295
- })
296
-
297
- it('should force centimes when requested', () => {
298
- expect(numberFormat('12345', 2, true)).toBe('12345.00');
299
- expect(numberFormat(12345, 3, true)).toBe('12345.000');
300
- })
301
-
302
- it('should handle custom thousand separators', () => {
303
- expect(numberFormat('12345.678', 2, false, ',')).toBe('12,345.68');
304
- expect(numberFormat('12345678.9', 1, false, ' ')).toBe('12 345 678.9');
305
- })
306
-
307
- it('should handle custom decimal points', () => {
308
- expect(numberFormat('12345.678', 2, false, '', ',')).toBe('12345,68');
309
- expect(numberFormat('12345.6', 2, true, '', ',')).toBe('12345,60');
310
- })
311
-
312
- it('should handle zero as input', () => {
313
- expect(numberFormat(0, 2, true)).toBe('0.00')
314
- expect(numberFormat(0, 0)).toBe('0');
315
- })
316
-
317
- it('should handle very small numbers correctly', () => {
318
- expect(numberFormat('0.0001234', 4)).toBe('0.0001');
319
- expect(numberFormat(0.0001234, 5)).toBe('0.00012');
320
- })
321
-
322
- it('should handle large numbers with custom formats', () => {
323
- expect(numberFormat('1234567890.12', 2, false, ',', '.')).toBe('1,234,567,890.12'); // Séparateur standard
324
- expect(numberFormat('1234567890.12', 0, false, ',')).toBe('1,234,567,890'); // Pas de décimales
325
- })
326
-
327
- it('should handle invalid inputs gracefully', () => {
328
- expect(numberFormat('notANumber')).toBe('NaN');
329
- expect(numberFormat(undefined)).toBe('0');
330
- })
331
-
332
- it('should handle edge cases with decimals greater than available digits', () => {
333
- expect(numberFormat('12345.6', 3, true)).toBe('12345.600');
334
- expect(numberFormat('12345', 2, true)).toBe('12345.00');
335
- })
336
-
337
- it('should be an alias of numberFormat', () => {
338
- expect(numberFormat === toPrice).toBe(true);
339
- })
340
-
341
- it('should handle numbers starting with a decimal point', () => {
342
- const result = numberFormat('.5', 2, true);
343
- expect(result).toBe('0.50');
344
-
345
- const result2 = numberFormat('.123', 2);
346
- expect(result2).toBe('0.12'); // Tronque à deux décimales
347
- })
348
-
349
- it('should handle numbers starting with a decimal point and no decimals specified', () => {
350
- const result = numberFormat('.5', 0);
351
- expect(result).toBe('1');
352
- })
353
- })
354
-
355
- describe('pad()', () => {
356
- it('should pad a string to the left by default', () => {
357
- expect(pad('42', 5)).toBe(' 42');
358
- })
359
-
360
- it('should pad a string to the left with a custom character', () => {
361
- expect(pad('42', 5, '0')).toBe('00042');
362
- })
363
-
364
- it('should pad a string to the right with a custom character', () => {
365
- expect(pad('42', 5, '0', 'right')).toBe('42000');
366
- })
367
-
368
- it('should not pad a string if its length is already equal to or greater than pad_length', () => {
369
- expect(pad('hello', 5)).toBe('hello');
370
- })
371
-
372
- it('should handle multi-character padding strings', () => {
373
- expect(pad('42', 8, '_+')).toBe('_+_+_+42');
374
- expect(pad('42', 8, '_+', 'right')).toBe('42_+_+_+');
375
- })
376
-
377
- it('should handle empty strings', () => {
378
- expect(pad('', 5)).toBe(' ');
379
- expect(pad('', 5, '0')).toBe('00000');
380
- })
381
-
382
- it('should handle invalid pad_length gracefully', () => {
383
- expect(pad('42', undefined)).toBe('42');
384
- expect(pad('42', null)).toBe('42');
385
- })
386
-
387
- it('should handle non-default pad_type values gracefully', () => {
388
- expect(pad('42', 5, '0', 'invalid')).toBe('42');
389
- })
390
-
391
- it('should handle long padding strings correctly', () => {
392
- expect(pad('42', 10, 'abcdef')).toBe('abcdefab42');
393
- expect(pad('42', 10, 'abcdef', 'right')).toBe('42abcdefab');
394
- })
395
-
396
- it('should handle special characters in padding string', () => {
397
- expect(pad('42', 5, '*')).toBe('***42');
398
- expect(pad('42', 5, ' ', 'right')).toBe('42 ');
399
- })
400
- })
401
-
402
- describe('rgb2hex()', () => {
403
- it('should convert numeric RGB values to a hexadecimal string', () => {
404
- expect(rgb2hex(255, 0, 0)).toBe('FF0000');
405
- expect(rgb2hex(0, 255, 0)).toBe('00FF00');
406
- expect(rgb2hex(0, 0, 255)).toBe('0000FF');
407
- expect(rgb2hex(255, 255, 255)).toBe('FFFFFF');
408
- expect(rgb2hex(0, 0, 0)).toBe('000000');
409
- })
410
-
411
- it('should handle an array of RGB values as input', () => {
412
- expect(rgb2hex([255, 0, 0])).toBe('FF0000');
413
- expect(rgb2hex([0, 255, 0])).toBe('00FF00');
414
- expect(rgb2hex([0, 0, 255])).toBe('0000FF');
415
- expect(rgb2hex([255, 255, 255])).toBe('FFFFFF');
416
- expect(rgb2hex([0, 0, 0])).toBe('000000');
417
- })
418
-
419
- it('should handle numeric strings as RGB values', () => {
420
- expect(rgb2hex('255', '0', '0')).toBe('FF0000');
421
- expect(rgb2hex('0', '255', '0')).toBe('00FF00');
422
- expect(rgb2hex('0', '0', '255')).toBe('0000FF');
423
- expect(rgb2hex('255', '255', '255')).toBe('FFFFFF');
424
- expect(rgb2hex('0', '0', '0')).toBe('000000');
425
- })
426
-
427
- it('should return an empty string for invalid inputs', () => {
428
- expect(rgb2hex(null)).toBe('');
429
- expect(rgb2hex(undefined)).toBe('');
430
- expect(rgb2hex('invalid', 255, 255)).toBe('');
431
- expect(rgb2hex(255, 'invalid', 255)).toBe('');
432
- expect(rgb2hex(255, 255, 'invalid')).toBe('');
433
- })
434
-
435
- it('should handle mixed input types', () => {
436
- expect(rgb2hex(255, '255', 255)).toBe('FFFFFF');
437
- expect(rgb2hex('0', 0, '0')).toBe('000000');
438
- })
439
-
440
- it('should handle edge cases like single-channel RGB', () => {
441
- expect(rgb2hex(0, 0, 0)).toBe('000000');
442
- expect(rgb2hex(255, 255, 255)).toBe('FFFFFF');
443
- })
444
- })
445
-
446
- describe('hex2rgb()', () => {
447
- it('should convert a valid hexadecimal color string to an RGB array', () => {
448
- expect(hex2rgb('#FF0000')).toEqual([255, 0, 0]);
449
- expect(hex2rgb('#00FF00')).toEqual([0, 255, 0]);
450
- expect(hex2rgb('#0000FF')).toEqual([0, 0, 255]);
451
- expect(hex2rgb('#FFFFFF')).toEqual([255, 255, 255]);
452
- expect(hex2rgb('#000000')).toEqual([0, 0, 0]);
453
- })
454
-
455
- it('should handle hexadecimal colors without the leading "#" character', () => {
456
- expect(hex2rgb('FF0000')).toEqual([255, 0, 0]);
457
- expect(hex2rgb('00FF00')).toEqual([0, 255, 0]);
458
- expect(hex2rgb('0000FF')).toEqual([0, 0, 255]);
459
- })
460
-
461
- it('should handle mixed-case hexadecimal strings', () => {
462
- expect(hex2rgb('#ff0000')).toEqual([255, 0, 0]);
463
- expect(hex2rgb('00FF00')).toEqual([0, 255, 0]);
464
- expect(hex2rgb('Aa00FF')).toEqual([170, 0, 255]);
465
- })
466
-
467
- it('should handle shorthand hexadecimal colors (e.g., #F00)', () => {
468
- expect(hex2rgb('#F00')).toEqual([255, 0, 0]);
469
- expect(hex2rgb('#0F0')).toEqual([0, 255, 0]);
470
- expect(hex2rgb('#00F')).toEqual([0, 0, 255]);
471
- })
472
-
473
- it('should return an empty array for invalid hexadecimal strings', () => {
474
- expect(hex2rgb('')).toEqual([]);
475
- expect(hex2rgb('#XYZ123')).toEqual([]);
476
- expect(hex2rgb('GGG')).toEqual([]);
477
- expect(hex2rgb('#FFFFFG')).toEqual([]);
478
- })
479
-
480
- it('should return an empty array for non-string inputs', () => {
481
- expect(hex2rgb(null)).toEqual([]);
482
- expect(hex2rgb(undefined)).toEqual([]);
483
- expect(hex2rgb(123)).toEqual([]);
484
- expect(hex2rgb({})).toEqual([]);
485
- expect(hex2rgb([])).toEqual([]);
486
- })
487
- })
488
-
489
- describe('parse_url()', () => {
490
- it('should parse a full URL into its components', () => {
491
- const url = 'https://user:pass@host.com:80/path/to?param=value#fragment';
492
- const result = parse_url(url);
493
-
494
- expect(result).toEqual({
495
- scheme: 'https',
496
- user: 'user',
497
- pass: 'pass',
498
- host: 'host.com',
499
- port: '80',
500
- path: '/path/to',
501
- query: 'param=value',
502
- fragment: 'fragment'
503
- })
504
- })
505
- })
506
-
507
- describe('addUrlParam()', () => {
508
- it('should add a single parameter to a URL without a query string', () => {
509
- const url = 'https://example.com';
510
- const result = addUrlParam(url, 'key', 'value');
511
- expect(result).toBe('https://example.com?key=value');
512
- })
513
-
514
- it('should add a single parameter to a URL with an existing query string', () => {
515
- const url = 'https://example.com?existing=param';
516
- const result = addUrlParam(url, 'key', 'value');
517
- expect(result).toBe('https://example.com?existing=param&key=value');
518
- })
519
-
520
- it('should overwrite an existing parameter with the same key', () => {
521
- const url = 'https://example.com?key=oldValue';
522
- const result = addUrlParam(url, 'key', 'newValue');
523
- expect(result).toBe('https://example.com?key=newValue');
524
- })
525
-
526
- it('should handle URLs with fragments (hashes)', () => {
527
- const url = 'https://example.com?existing=param#section';
528
- const result = addUrlParam(url, 'key', 'value');
529
- expect(result).toBe('https://example.com?existing=param&key=value#section');
530
- })
531
-
532
- it('should add multiple parameters from an object', () => {
533
- const url = 'https://example.com';
534
- const params = { key1: 'value1', key2: 'value2' };
535
- const result = addUrlParam(url, params);
536
- expect(result).toBe('https://example.com?key1=value1&key2=value2');
537
- })
538
-
539
- it('should handle a URL without a scheme and host', () => {
540
- const url = '/path/to/resource';
541
- const result = addUrlParam(url, 'key', 'value');
542
- expect(result).toBe('/path/to/resource?key=value');
543
- })
544
-
545
- it('should handle a URL with an existing parameter and without a scheme and host', () => {
546
- const url = '/path/to/resource?existing=param';
547
- const result = addUrlParam(url, 'key', 'value');
548
- expect(result).toBe('/path/to/resource?existing=param&key=value');
549
- })
550
-
551
- it('should handle a URL with an existing parameter and a new one', () => {
552
- const url = 'https://example.com?existing=param';
553
- const result = addUrlParam(url, { existing: 'newParam', another: 'value' })
554
- expect(result).toBe('https://example.com?existing=newParam&another=value');
555
- })
556
-
557
- it('should handle a null value for a parameter', () => {
558
- const url = 'https://example.com';
559
- const result = addUrlParam(url, 'key', null);
560
- expect(result).toBe('https://example.com?key=null');
561
- })
562
-
563
- it('should handle an empty string as a parameter value', () => {
564
- const url = 'https://example.com';
565
- const result = addUrlParam(url, 'key', '');
566
- expect(result).toBe('https://example.com?key=');
567
- })
568
-
569
- it('should not alter the original URL if no parameters are provided', () => {
570
- const url = 'https://example.com';
571
- const result = addUrlParam(url, {})
572
- expect(result).toBe('https://example.com');
573
- })
574
-
575
- it('should handle adding parameters to a relative URL with a hash', () => {
576
- const url = '/path/to/resource#section';
577
- const result = addUrlParam(url, 'key', 'value');
578
- expect(result).toBe('/path/to/resource?key=value#section');
579
- })
580
- })
581
-
582
- describe('decodeHtml(), htmlquotes(), htmlsimplequotes()', () => {
583
- it('should decode html entities', () => {
584
- expect(decodeHtml(str7)).toBe('&<>"\'');
585
- })
586
-
587
- it('should encode double and simple quotes', () => {
588
- expect(htmlquotes('"\'')).toBe('&quot;&#039;');
589
- })
590
-
591
- it('should encode simple quotes', () => {
592
- expect(htmlsimplequotes('"\'')).toBe('"&#039;');
593
- })
594
-
595
- it('should return an empty string when the string is null or undefined', () => {
596
- expect(decodeHtml(null)).toBe('');
597
- expect(htmlquotes(undefined)).toBe('');
598
- expect(htmlsimplequotes(null)).toBe('');
599
- expect(decodeHtml(undefined)).toBe('');
600
- expect(htmlquotes(null)).toBe('');
601
- expect(htmlsimplequotes(undefined)).toBe('');
602
- })
603
- })
604
-
605
- describe('repeat', () => {
606
- it('should repeat the string n times', () => {
607
- expect(repeat('abc', 3)).toBe('abcabcabc');
608
- })
609
-
610
- it('should return an empty string when n is 0', () => {
611
- expect(repeat('abc', 0)).toBe('');
612
- })
613
-
614
- it('should return an empty string when n is negative', () => {
615
- expect(repeat('abc', -1)).toBe('');
616
- })
617
-
618
- it('should work with an empty string', () => {
619
- expect(repeat('', 5)).toBe('');
620
- })
621
-
622
- it('should repeat single characters correctly', () => {
623
- expect(repeat('a', 5)).toBe('aaaaa');
624
- })
625
-
626
- it('should return an empty string when n is not a number', () => {
627
- expect(repeat('abc', null)).toBe('');
628
- expect(repeat('abc', undefined)).toBe('');
629
- expect(repeat('abc', 'not-a-number')).toBe('');
630
- })
631
-
632
- it('should handle n as a float by truncating it', () => {
633
- expect(repeat('abc', 3.7)).toBe('abcabcabc');
634
- })
635
-
636
- it('should return an empty string when the string is null or undefined', () => {
637
- expect(repeat(null, 3)).toBe('');
638
- expect(repeat(undefined, 3)).toBe('');
639
- })
640
- })
641
-
642
- describe('stripTags()', () => {
643
- it('should remove a specific tag and keep its content', () => {
644
- const input = '<p>Hello <b>world</b></p>';
645
- const result = stripTags(input, 'b');
646
- expect(result).toBe('<p>Hello world</p>');
647
- })
648
-
649
- it('should remove nested instances of a specific tag', () => {
650
- const input = '<div><span>Hello <span>world</span></span></div>';
651
- const result = stripTags(input, 'span');
652
- expect(result).toBe('<div>Hello world</div>');
653
- })
654
-
655
- it('should remove all tags if no specific tag is provided', () => {
656
- const input = '<p>Hello <b>world</b></p>';
657
- const result = stripTags(input);
658
- expect(result).toBe('Hello world');
659
- })
660
-
661
- it('should handle self-closing tags correctly', () => {
662
- const input = '<img src="image.jpg" /><p>Text</p>';
663
- const result = stripTags(input);
664
- expect(result).toBe('Text');
665
- })
666
-
667
- it('should handle tags with attributes', () => {
668
- const input = '<a href="https://example.com">Link</a>';
669
- const result = stripTags(input, 'a');
670
- expect(result).toBe('Link');
671
- })
672
-
673
- it('should handle invalid HTML gracefully', () => {
674
- const input = '<div><p>Unclosed div';
675
- const result = stripTags(input);
676
- expect(result).toBe('Unclosed div');
677
- })
678
-
679
- it('should return the string as-is if no tags are present', () => {
680
- const input = 'No tags here';
681
- const result = stripTags(input);
682
- expect(result).toBe('No tags here');
683
- })
684
-
685
- it('should remove multiple instances of the same tag', () => {
686
- const input = '<b>Hello</b> <b>world</b>';
687
- const result = stripTags(input, 'b');
688
- expect(result).toBe('Hello world');
689
- })
690
-
691
- it('should be case-insensitive for tags', () => {
692
- const input = '<B>Hello</B> <b>world</b>';
693
- const result = stripTags(input, 'b');
694
- expect(result).toBe('Hello world');
695
- })
696
-
697
- it('should handle empty strings gracefully', () => {
698
- const input = '';
699
- const result = stripTags(input);
700
- expect(result).toBe('');
701
- })
702
-
703
- it('should not throw an error if the tag is null or undefined', () => {
704
- const input = '<p>Hello</p>';
705
- expect(stripTags(input, null)).toBe('Hello');
706
- expect(stripTags(input, undefined)).toBe('Hello');
707
- })
708
-
709
- it('should not remove content when the tag does not match', () => {
710
- const input = '<p>Hello <b>world</b></p>';
711
- const result = stripTags(input, 'div');
712
- expect(result).toBe('<p>Hello <b>world</b></p>');
713
- })
714
- })
715
-
716
- describe('toUrl()', () => {
717
- it('should convert a string to lowercase', () => {
718
- expect(toUrl(str1)).toBe('on-en-a-gros');
719
- })
720
-
721
- it('should remove accents, special characters', () => {
722
- expect(toUrl('Élève')).toBe('eleve');
723
- expect(toUrl('Hello@World!')).toBe('hello-world');
724
- expect(toUrl('@@##$$')).toBe('');
725
- })
726
-
727
- it('should replace multiple consecutive dashes with a single dash', () => {
728
- expect(toUrl('Hello World')).toBe('hello-world');
729
- expect(toUrl('Hello---World')).toBe('hello-world');
730
- })
731
-
732
- it('should trim leading and trailing dashes', () => {
733
- expect(toUrl('-Hello World-')).toBe('hello-world');
734
- })
735
-
736
- it('should handle empty strings', () => {
737
- expect(toUrl('')).toBe('');
738
- })
739
-
740
- it('should handle strings with mixed cases, accents, and special characters', () => {
741
- expect(toUrl('Élève à l\'école')).toBe('eleve-a-l-ecole');
742
- })
743
-
744
- it('should handle numeric characters correctly', () => {
745
- expect(toUrl('Product 123')).toBe('product-123');
746
- })
747
-
748
- it('should handle strings with underscores and hyphens', () => {
749
- expect(toUrl('Hello_World')).toBe('hello-world');
750
- expect(toUrl('Hello-World')).toBe('hello-world');
751
- })
752
- })
753
-
754
- describe('escapeRegex()', () => {
755
- it('should escape special regex characters', () => {
756
- const input = '.*+?^${}()|[]\\';
757
- const output = '\\.\\*\\+\\?\\^\\$\\{\\}\\(\\)\\|\\[\\]\\\\';
758
- expect(escapeRegex(input)).toBe(output);
759
- })
760
-
761
- it('should escape spaces correctly', () => {
762
- const input = 'Hello World';
763
- const output = 'Hello\\ World';
764
- expect(escapeRegex(input)).toBe(output);
765
- })
766
-
767
- it('should handle strings with mixed characters', () => {
768
- const input = 'a+b*c?d.e^f|g(h)i[j]k\\l';
769
- const output = 'a\\+b\\*c\\?d\\.e\\^f\\|g\\(h\\)i\\[j\\]k\\\\l';
770
- expect(escapeRegex(input)).toBe(output);
771
- })
772
-
773
- it('should return the same string if no special characters are present', () => {
774
- const input = 'simpletext';
775
- expect(escapeRegex(input)).toBe(input);
776
- })
777
-
778
- it('should handle an empty string', () => {
779
- const input = '';
780
- const output = '';
781
- expect(escapeRegex(input)).toBe(output);
782
- })
783
-
784
- it('should escape special characters in numeric strings', () => {
785
- const input = '123$456';
786
- const output = '123\\$456';
787
- expect(escapeRegex(input)).toBe(output);
788
- })
789
-
790
- it('should escape multiple spaces', () => {
791
- const input = 'Hello World';
792
- const output = 'Hello\\ \\ \\ World';
793
- expect(escapeRegex(input)).toBe(output);
794
- })
795
-
796
- it('should handle special characters at the start and end of the string', () => {
797
- const input = '*Hello World?';
798
- const output = '\\*Hello\\ World\\?';
799
- expect(escapeRegex(input)).toBe(output);
800
- })
801
-
802
- it('should escape newlines and tabs as spaces', () => {
803
- const input = 'Hello\nWorld\t!';
804
- const output = 'Hello\\ World\\ !';
805
- expect(escapeRegex(input)).toBe(output);
806
- })
807
- })
808
-
809
- describe('camelCase()', () => {
810
- it('should convert a string with underscores to camelCase', () => {
811
- expect(camelCase('hello_world')).toBe('helloWorld');
812
- });
813
-
814
- it('should convert a string with dashes to camelCase', () => {
815
- expect(camelCase('hello-world')).toBe('helloWorld');
816
- });
817
-
818
- it('should convert a string with mixed dashes and underscores to camelCase', () => {
819
- expect(camelCase('hello-world_and_underscore')).toBe('helloWorldAndUnderscore');
820
- });
821
-
822
- it('should handle strings with multiple consecutive separators', () => {
823
- expect(camelCase('hello__world--test')).toBe('helloWorldTest');
824
- });
825
-
826
- it('should handle strings with leading separators', () => {
827
- expect(camelCase('_hello_world')).toBe('helloWorld');
828
- expect(camelCase('-hello-world')).toBe('helloWorld');
829
- });
830
-
831
- it('should handle strings with trailing separators', () => {
832
- expect(camelCase('hello_world_')).toBe('helloWorld');
833
- expect(camelCase('hello-world-')).toBe('helloWorld');
834
- });
835
-
836
- it('should convert a single word to lowercase', () => {
837
- expect(camelCase('HELLO')).toBe('hello');
838
- expect(camelCase('hello')).toBe('hello');
839
- });
840
-
841
- it('should handle empty strings', () => {
842
- expect(camelCase('')).toBe('');
843
- });
844
-
845
- it('should handle strings with no separators', () => {
846
- expect(camelCase('simpleword')).toBe('simpleword');
847
- });
848
-
849
- it('should handle strings with numeric characters', () => {
850
- expect(camelCase('version-1_2')).toBe('version12');
851
- });
852
-
853
- it('should handle strings with special characters outside separators', () => {
854
- expect(camelCase('hello@world')).toBe('hello@world');
855
- });
856
-
857
- it('should handle spaces', () => {
858
- expect(camelCase('hello world')).toBe('helloWorld');
859
- });
860
-
861
- it('should handle mixed case strings', () => {
862
- expect(camelCase('HeLLo-WoRLd')).toBe('helloWorld');
863
- });
864
- });
865
-
866
- describe('format()', () => {
867
- it('should replace indexed placeholders with corresponding arguments', () => {
868
- const result = format('Hello {0}, welcome to {1}!', 'Alice', 'Wonderland');
869
- expect(result).toBe('Hello Alice, welcome to Wonderland!');
870
- });
871
-
872
- it('should leave placeholders intact if no corresponding argument is provided', () => {
873
- const result = format('Hello {0}, welcome to {1}!', 'Alice');
874
- expect(result).toBe('Hello Alice, welcome to {1}!');
875
- });
876
-
877
- it('should handle objects as the first argument', () => {
878
- const result = format('Hello {name}, welcome to {place}!', { name: 'Alice', place: 'Wonderland' });
879
- expect(result).toBe('Hello Alice, welcome to Wonderland!');
880
- });
881
-
882
- it('should prioritize indexed placeholders over object replacements', () => {
883
- const result = format('Hello {0}, welcome to {place}!', 'Alice', { place: 'Wonderland' });
884
- expect(result).toBe('Hello Alice, welcome to Wonderland!');
885
- });
886
-
887
- it('should handle objects with numeric keys as placeholders', () => {
888
- const result = format('Values: {0}, {1}, {key}', { 0: 'zero', 1: 'one', key: 'value' });
889
- expect(result).toBe('Values: zero, one, value');
890
- });
891
-
892
- it('should leave unmatched placeholders intact', () => {
893
- const result = format('Hello {name}, welcome to {place}!', { name: 'Alice' });
894
- expect(result).toBe('Hello Alice, welcome to {place}!');
895
- });
896
-
897
- it('should handle empty strings', () => {
898
- const result = format('');
899
- expect(result).toBe('');
900
- });
901
-
902
- it('should return the original string if no replacements are provided', () => {
903
- const result = format('Hello {0}');
904
- expect(result).toBe('Hello {0}');
905
- });
906
-
907
- it('should handle undefined or null values in objects', () => {
908
- const result = format('Value: {key}', { key: undefined });
909
- expect(result).toBe('Value: {key}');
910
- });
911
-
912
- it('should handle special characters in object keys', () => {
913
- const result = format('Hello {user-name}!', { 'user-name': 'Alice' });
914
- expect(result).toBe('Hello Alice!');
915
- });
916
-
917
- it('should handle placeholders with numeric keys as strings', () => {
918
- const result = format('Value: {0}', { '0': 'zero' });
919
- expect(result).toBe('Value: zero');
920
- });
921
- });
922
-
923
- describe('toCssClassName()', () => {
924
- it('should replace spaces with hyphens', () => {
925
- expect(toCssClassName('hello world')).toBe('hello-world');
926
- });
927
-
928
- it('should encode special characters as hexadecimal', () => {
929
- expect(toCssClassName('hello@world')).toBe('hello__0040world');
930
- });
931
-
932
- it('should encode non-ASCII characters as hexadecimal', () => {
933
- expect(toCssClassName('café')).toBe('caf__00e9');
934
- });
935
-
936
- it('should return an empty string when input is empty', () => {
937
- expect(toCssClassName('')).toBe('');
938
- });
939
-
940
- it('should leave valid CSS characters unchanged', () => {
941
- expect(toCssClassName('valid-class_name')).toBe('valid-class_name');
942
- });
943
-
944
- it('should encode numbers as they are valid CSS class name characters', () => {
945
- expect(toCssClassName('123')).toBe('123');
946
- });
947
-
948
- it('should encode edge-case characters', () => {
949
- expect(toCssClassName('$hello&world')).toBe('__0024hello__0026world');
950
- });
951
-
952
- it('should handle strings with only special characters', () => {
953
- expect(toCssClassName('@@@')).toBe('__0040__0040__0040');
954
- });
955
-
956
- it('should handle a string with spaces only', () => {
957
- expect(toCssClassName(' ')).toBe('---');
958
- });
959
- });
960
-
961
- describe('compareMixAlphaDigits', () => {
962
- it('should compare purely alphabetic strings', () => {
963
- expect(compareMixAlphaDigits('abc', 'abd')).toBe(-1);
964
- expect(compareMixAlphaDigits('abd', 'abc')).toBe(1);
965
- expect(compareMixAlphaDigits('abc', 'abc')).toBe(0);
966
- });
967
-
968
- it('should compare strings with digits at the start', () => {
969
- expect(compareMixAlphaDigits('12abc', '9abc')).toBe(1);
970
- expect(compareMixAlphaDigits('9abc', '12abc')).toBe(-1);
971
- expect(compareMixAlphaDigits('12abc', '12abc')).toBe(0);
972
- });
973
-
974
- it('should compare strings with digits in the middle', () => {
975
- expect(compareMixAlphaDigits('abc12', 'abc9')).toBe(1);
976
- expect(compareMixAlphaDigits('abc9', 'abc12')).toBe(-1);
977
- expect(compareMixAlphaDigits('abc12', 'abc12')).toBe(0);
978
- });
979
-
980
- it('should compare strings with digits in different positions', () => {
981
- expect(compareMixAlphaDigits('a12bc', '12abc')).toBe(1);
982
- expect(compareMixAlphaDigits('12abc', 'a12bc')).toBe(-1);
983
- });
984
-
985
- it('should compare strings with digits and different alphabetic prefixes', () => {
986
- expect(compareMixAlphaDigits('abc12', 'abd12')).toBe(-1);
987
- expect(compareMixAlphaDigits('abd12', 'abc12')).toBe(1);
988
- });
989
-
990
- it('should handle empty strings', () => {
991
- expect(compareMixAlphaDigits('', 'abc')).toBe(-1);
992
- expect(compareMixAlphaDigits('abc', '')).toBe(1);
993
- expect(compareMixAlphaDigits('', '')).toBe(0);
994
- });
995
-
996
- it('should handle strings with digits', () => {
997
- expect(compareMixAlphaDigits('123a', '45')).toBe(1);
998
- expect(compareMixAlphaDigits('123', '123')).toBe(0);
999
- expect(compareMixAlphaDigits('1230', '421')).toBe(1);
1000
- expect(compareMixAlphaDigits('421', '1230')).toBe(-1);
1001
- expect(compareMixAlphaDigits('0421', '421')).toBe(0);
1002
- });
1003
-
1004
- it('should handle mixed cases with letters and digits', () => {
1005
- expect(compareMixAlphaDigits('45', '123a')).toBe(-1);
1006
- expect(compareMixAlphaDigits('a1b2', 'a1b10')).toBe(-1);
1007
- expect(compareMixAlphaDigits('a1b10', 'a1b2')).toBe(1);
1008
- expect(compareMixAlphaDigits('a1b2', 'a1b2')).toBe(0);
1009
- expect(compareMixAlphaDigits('a130b', 'a14a')).toBe(1);
1010
- });
1011
- });
1012
-
1013
- describe('formatSize', () => {
1014
- setLang('fr');
1015
-
1016
- it('should return size in kilobytes for values less than 1 kB', () => {
1017
- expect(formatSize(512)).toBe('0,5 ko');
1018
- });
1019
-
1020
- it('should return size in kilobytes for values >= 1 kB and < 1 MB', () => {
1021
- expect(formatSize(1536)).toBe('1,5 ko');
1022
- });
1023
-
1024
- it('should return size in megabytes for values >= 1 MB and < 1 GB', () => {
1025
- expect(formatSize(1048576)).toBe('1 Mo');
1026
- });
1027
-
1028
- it('should return size in gigabytes for values >= 1 GB', () => {
1029
- expect(formatSize(1073741824)).toBe('1 Go');
1030
- });
1031
-
1032
- it('should handle custom decimal point', () => {
1033
- expect(formatSize(1536, '.')).toBe('1.5 ko');
1034
- });
1035
-
1036
- it('should handle edge case of exactly 1024 bytes', () => {
1037
- expect(formatSize(1024)).toBe('1 ko');
1038
- });
1039
-
1040
- it('should handle 0 bytes', () => {
1041
- expect(formatSize(0)).toBe('0 ko');
1042
- });
1043
-
1044
- it('should use appropriate decimals for non-integers', () => {
1045
- expect(formatSize(1049600)).toBe('1,0 Mo');
1046
- });
1047
- });
1048
-
1049
- describe('hilite', () => {
1050
- it('should highlight a single match with default tag', () => {
1051
- const str = "Moi j'ai appris à lire, ben je souhaite ça à personne.";
1052
- const req = "appris à lire";
1053
- const result = hilite(str, req);
1054
- expect(result).toBe("Moi j'ai <strong>appris à lire</strong>, ben je souhaite ça à personne.");
1055
- });
1056
-
1057
- it('should highlight multiple matches with default tag', () => {
1058
- const str = "Hé ! Toi là-bas ! Avec ton casque à cornes … Présente-moi ta femme, comme ça tu sauras pourquoi t'as des cornes !";
1059
- const req = "cornes";
1060
- const result = hilite(str, req);
1061
- expect(result).toBe("Hé ! Toi là-bas ! Avec ton casque à <strong>cornes</strong> … Présente-moi ta femme, comme ça tu sauras pourquoi t'as des <strong>cornes</strong> !");
1062
- });
1063
-
1064
- it('should ignore case and accents', () => {
1065
- const str = "Vous vous étonnerez pas si vous ressentez une vive douleur sur le sommet du CrâNe. C'est sûrement que vous aurez pris le plat à gigot dans la tronche !";
1066
- const req = "crane";
1067
- const result = hilite(str, req);
1068
- expect(result).toBe("Vous vous étonnerez pas si vous ressentez une vive douleur sur le sommet du <strong>CrâNe</strong>. C'est sûrement que vous aurez pris le plat à gigot dans la tronche !");
1069
- });
1070
-
1071
- it('should allow a custom tag', () => {
1072
- const str = "Le gras, c'est la vie.";
1073
- const req = "gras";
1074
- const result = hilite(str, req, 'b');
1075
- expect(result).toBe("Le <b>gras</b>, c'est la vie.");
1076
- });
1077
-
1078
- it('should handle multiple words to highlight', () => {
1079
- const str = "J'irai me coucher quand vous m'aurez juré qu'il n'y a pas dans cette forêt d'animal plus dangereux que le lapin adulte !";
1080
- const req = ["coucher", "foret", "lapin"];
1081
- const result = hilite(str, req);
1082
- expect(result).toBe("J'irai me <strong>coucher</strong> quand vous m'aurez juré qu'il n'y a pas dans cette <strong>forêt</strong> d'animal plus dangereux que le <strong>lapin</strong> adulte !");
1083
- });
1084
-
1085
- it('should return the original string if no matches', () => {
1086
- const str = "La politique de l'autruche, c'est une politique qui court vite, une politique qui fait des gros oeufs.";
1087
- const req = "arthur";
1088
- const result = hilite(str, req);
1089
- expect(result).toBe("La politique de l'autruche, c'est une politique qui court vite, une politique qui fait des gros oeufs.");
1090
- });
1091
-
1092
- it('should return the original string if req is empty', () => {
1093
- const str = "On en a gros !";
1094
- const req = "";
1095
- const result = hilite(str, req);
1096
- expect(result).toBe("On en a gros !");
1097
- });
1098
-
1099
- it('should not break with special characters in req', () => {
1100
- const str = "c\'est pas faux";
1101
- const req = "c\'est";
1102
- const result = hilite(str, req);
1103
- expect(result).toBe("<strong>c\'est</strong> pas faux");
1104
- });
1105
- });
1106
- })