@akadenia/helpers 1.7.1 → 1.7.3
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/README.MD +20 -6
- package/dist/text.js +27 -4
- package/package.json +1 -1
package/README.MD
CHANGED
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
- [Contributing to this package](#contributing-to-this-package)
|
|
51
51
|
- [License](#license)
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
## DateHelpers
|
|
54
54
|
|
|
55
55
|
Import the DateHelpers utility.
|
|
56
56
|
|
|
@@ -137,7 +137,7 @@ Arguments
|
|
|
137
137
|
|--|--|--|--|
|
|
138
138
|
|`coordinates`|`object`|`true`|An object containing the start and end coordinates. i.e. `{startCoordinate: [lat, lng], endCoordinate: [lat, lng]}`|
|
|
139
139
|
|
|
140
|
-
|
|
140
|
+
## TextHelpers
|
|
141
141
|
|
|
142
142
|
Import the TextHelpers utility.
|
|
143
143
|
|
|
@@ -355,6 +355,7 @@ Arguments
|
|
|
355
355
|
|`number`|`number`|`true`|The number to be abbreviated|
|
|
356
356
|
|
|
357
357
|
Examples
|
|
358
|
+
|
|
358
359
|
- Numbers below 1,000 are displayed without abbreviation
|
|
359
360
|
- Numbers between 1,000 and 1,000,000 are displayed in thousands (e.g. 1.23K)
|
|
360
361
|
- Numbers between 1,000,000 and 1,000,000,000 are displayed in millions (e.g. 1.23M)
|
|
@@ -362,7 +363,7 @@ Examples
|
|
|
362
363
|
|
|
363
364
|
Note: If the input `number` is null or undefined, the function returns null.
|
|
364
365
|
|
|
365
|
-
|
|
366
|
+
## ObjectHelpers
|
|
366
367
|
|
|
367
368
|
Import the ObjectHelpers utility.
|
|
368
369
|
|
|
@@ -392,7 +393,10 @@ Filter an array of objects based on a specific property and its corresponding va
|
|
|
392
393
|
Returns an array containing all objects that have the specified property with the given value.
|
|
393
394
|
|
|
394
395
|
Template
|
|
396
|
+
|
|
397
|
+
```typescript
|
|
395
398
|
T extends Record<string, any>
|
|
399
|
+
```
|
|
396
400
|
|
|
397
401
|
Arguments
|
|
398
402
|
|Name|Type|Required|Description|
|
|
@@ -407,7 +411,10 @@ It compares the key-value pairs of the sub-object with the corresponding key-val
|
|
|
407
411
|
Returns true If all key-value pairs in the sub-object are found in the main object; otherwise, it returns false.
|
|
408
412
|
|
|
409
413
|
Template
|
|
414
|
+
|
|
415
|
+
```typescript
|
|
410
416
|
T extends Record<string, any>
|
|
417
|
+
```
|
|
411
418
|
|
|
412
419
|
Arguments
|
|
413
420
|
|Name|Type|Required|Description|
|
|
@@ -422,7 +429,10 @@ Returns the first object found in the array that contains the sub-object or null
|
|
|
422
429
|
if no match is found.
|
|
423
430
|
|
|
424
431
|
Template
|
|
432
|
+
|
|
433
|
+
```typescript
|
|
425
434
|
T extends Record<string, any>
|
|
435
|
+
```
|
|
426
436
|
|
|
427
437
|
Arguments
|
|
428
438
|
|Name|Type|Required|Description|
|
|
@@ -436,7 +446,10 @@ Filters an array of objects based on the presence of a specific sub-object withi
|
|
|
436
446
|
Returns an array containing all objects from the input array that contain the specified sub-object.
|
|
437
447
|
|
|
438
448
|
Template
|
|
449
|
+
|
|
450
|
+
```typescript
|
|
439
451
|
T extends Record<string, any>
|
|
452
|
+
```
|
|
440
453
|
|
|
441
454
|
Arguments
|
|
442
455
|
|Name|Type|Required|Description|
|
|
@@ -465,7 +478,7 @@ Arguments
|
|
|
465
478
|
|`array`|`Array<any>`|`true`|The array of entries to search|
|
|
466
479
|
|`predicate`|`(item: any) => boolean`|`true`|The predicate function to use to search the array|
|
|
467
480
|
|
|
468
|
-
|
|
481
|
+
## GenericHelpers
|
|
469
482
|
|
|
470
483
|
Import the GenericHelpers utility.
|
|
471
484
|
|
|
@@ -489,7 +502,7 @@ Arguments
|
|
|
489
502
|
|--|--|--|--|
|
|
490
503
|
|`host`|`string`|`true`|An IP address or a domain name|
|
|
491
504
|
|
|
492
|
-
|
|
505
|
+
## FileHelpers
|
|
493
506
|
|
|
494
507
|
## `FileHelpers.checkFileExtension(filePath, validExtensions)`
|
|
495
508
|
|
|
@@ -522,7 +535,8 @@ Common types according to [commitlint-config-conventional (based on the Angular
|
|
|
522
535
|
- revert
|
|
523
536
|
- style
|
|
524
537
|
- test
|
|
525
|
-
|
|
538
|
+
|
|
539
|
+
if you introduce a breaking change, please add BREAKING CHANGE in the pull request description
|
|
526
540
|
|
|
527
541
|
## License
|
|
528
542
|
|
package/dist/text.js
CHANGED
|
@@ -240,9 +240,32 @@ exports.enforceCharacterLimit = enforceCharacterLimit;
|
|
|
240
240
|
* @returns The boolean value when the condition is met
|
|
241
241
|
*/
|
|
242
242
|
const isValidEmail = (email) => {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
243
|
+
// First check for null/undefined
|
|
244
|
+
if (!email) {
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
// Check if the email has an @ symbol and the length of the email tokens is exactly 2
|
|
248
|
+
const parts = email.split("@");
|
|
249
|
+
if (parts.length !== 2) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
const [local, domain] = parts;
|
|
253
|
+
// Check local part rules
|
|
254
|
+
if (!local || local.length === 0) {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
if (local.startsWith(".") || local.endsWith(".")) {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
if (local.includes("..")) {
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9._+-]*$/.test(local)) {
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
// Check domain part rules
|
|
267
|
+
const domainRegex = /^[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?)*\.[a-zA-Z]{2,}$/;
|
|
268
|
+
return domainRegex.test(domain);
|
|
246
269
|
};
|
|
247
270
|
exports.isValidEmail = isValidEmail;
|
|
248
271
|
/**
|
|
@@ -304,7 +327,7 @@ const abbreviateNumber = (number) => {
|
|
|
304
327
|
{ value: 1e6, symbol: "M" },
|
|
305
328
|
{ value: 1e3, symbol: "K" },
|
|
306
329
|
];
|
|
307
|
-
if (
|
|
330
|
+
if (number === null || number === undefined || isNaN(number))
|
|
308
331
|
return null;
|
|
309
332
|
const abbreviated = abbreviations.find(({ value }) => Math.abs(number) >= value);
|
|
310
333
|
if (abbreviated) {
|