defuss-runtime 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +210 -63
- package/dist/index.d.cts +347 -36
- package/dist/index.d.mts +347 -36
- package/dist/index.mjs +207 -64
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -387,92 +387,149 @@ const asInteger = (value) => {
|
|
|
387
387
|
return asNumber(Number.parseInt(asString(number), 10).toFixed(0));
|
|
388
388
|
};
|
|
389
389
|
|
|
390
|
-
const
|
|
391
|
-
|
|
390
|
+
const isAfter = (value, minDate, inclusive = false, message) => {
|
|
391
|
+
const isValid = value instanceof Date && (inclusive ? value.getTime() >= minDate.getTime() : value.getTime() > minDate.getTime());
|
|
392
|
+
return isValid ? true : message || false;
|
|
392
393
|
};
|
|
393
394
|
|
|
394
|
-
const
|
|
395
|
-
|
|
395
|
+
const isArray = (value, message) => {
|
|
396
|
+
const isValid = Array.isArray(value);
|
|
397
|
+
return isValid ? true : message || false;
|
|
396
398
|
};
|
|
397
399
|
|
|
398
|
-
const
|
|
399
|
-
|
|
400
|
+
const isBefore = (value, maxDate, inclusive = false, message) => {
|
|
401
|
+
const isValid = value instanceof Date && (inclusive ? value.getTime() <= maxDate.getTime() : value.getTime() < maxDate.getTime());
|
|
402
|
+
return isValid ? true : message || false;
|
|
400
403
|
};
|
|
401
404
|
|
|
402
|
-
const
|
|
403
|
-
|
|
405
|
+
const isBoolean = (value, message) => {
|
|
406
|
+
const isValid = typeof value === "boolean";
|
|
407
|
+
return isValid ? true : message || false;
|
|
404
408
|
};
|
|
405
409
|
|
|
406
|
-
const
|
|
407
|
-
|
|
410
|
+
const isDate = (value, message) => {
|
|
411
|
+
const isValid = value instanceof Date && !Number.isNaN(value.getDate());
|
|
412
|
+
return isValid ? true : message || false;
|
|
408
413
|
};
|
|
409
414
|
|
|
410
|
-
const
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
const isBoolean = (value) => typeof value === "boolean";
|
|
415
|
-
|
|
416
|
-
const isDate = (value) => value instanceof Date && !Number.isNaN(value.getDate());
|
|
417
|
-
|
|
418
|
-
const isDefined = (value) => typeof value !== "undefined";
|
|
415
|
+
const isDefined = (value, message) => {
|
|
416
|
+
const isValid = typeof value !== "undefined";
|
|
417
|
+
return isValid ? true : message || false;
|
|
418
|
+
};
|
|
419
419
|
|
|
420
|
-
const isString = (value) =>
|
|
420
|
+
const isString = (value, message) => {
|
|
421
|
+
const isValid = typeof value === "string";
|
|
422
|
+
return isValid ? true : message || false;
|
|
423
|
+
};
|
|
421
424
|
|
|
422
|
-
const isEmail = (value) =>
|
|
423
|
-
value
|
|
424
|
-
|
|
425
|
+
const isEmail = (value, message) => {
|
|
426
|
+
const stringResult = isString(value);
|
|
427
|
+
const isStringValid = stringResult === true;
|
|
428
|
+
const isValid = isStringValid && /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\\x01\-\\x08\\x0b\\x0c\\x0e\-\\x1f\\x21\\x23\-\\x5b\\x5d\-\\x7f]|\\[\\x01-\\x09\\x0b\\x0c\\x0e\-\\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01\-\\x08\\x0b\\x0c\\x0e\-\\x1f\\x21\-\\x5a\\x53\-\\x7f]|\\[\\x01\-\\x09\\x0b\\x0c\\x0e\-\\x7f])+)\])/.test(
|
|
429
|
+
value
|
|
430
|
+
);
|
|
431
|
+
return isValid ? true : message || false;
|
|
432
|
+
};
|
|
425
433
|
|
|
426
|
-
const isEmpty = (value) => {
|
|
427
|
-
|
|
428
|
-
if (
|
|
429
|
-
if (
|
|
430
|
-
if (value
|
|
431
|
-
if (
|
|
432
|
-
|
|
434
|
+
const isEmpty = (value, message) => {
|
|
435
|
+
let isValid = false;
|
|
436
|
+
if (value === null || value === void 0) isValid = true;
|
|
437
|
+
else if (typeof value === "string") isValid = value === "";
|
|
438
|
+
else if (Array.isArray(value)) isValid = value.length === 0;
|
|
439
|
+
else if (value instanceof Date) isValid = false;
|
|
440
|
+
else if (typeof value === "object") isValid = Object.keys(value).length === 0;
|
|
441
|
+
else isValid = false;
|
|
442
|
+
return isValid ? true : message || false;
|
|
433
443
|
};
|
|
434
444
|
|
|
435
|
-
const is = (value, valueB) =>
|
|
445
|
+
const is = (value, valueB, message) => {
|
|
446
|
+
const isValid = value === valueB;
|
|
447
|
+
return isValid ? true : message || false;
|
|
448
|
+
};
|
|
436
449
|
|
|
437
|
-
const isSafeNumber = (value) =>
|
|
450
|
+
const isSafeNumber = (value, message) => {
|
|
451
|
+
const isValid = typeof value === "number" && !Number.isNaN(value) && Number.isFinite(value);
|
|
452
|
+
return isValid ? true : message || false;
|
|
453
|
+
};
|
|
438
454
|
|
|
439
|
-
const isGreaterThan = (value, minValue, includeEqual = false) =>
|
|
455
|
+
const isGreaterThan = (value, minValue, includeEqual = false, message) => {
|
|
456
|
+
const safeNumberResult = isSafeNumber(value);
|
|
457
|
+
const isSafeNum = safeNumberResult === true;
|
|
458
|
+
const isValid = isSafeNum && (includeEqual ? value >= minValue : value > minValue);
|
|
459
|
+
return isValid ? true : message || false;
|
|
460
|
+
};
|
|
440
461
|
|
|
441
|
-
const isSafeNumeric = (value) => {
|
|
442
|
-
|
|
443
|
-
if (typeof value === "
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
462
|
+
const isSafeNumeric = (value, message) => {
|
|
463
|
+
let isValid = false;
|
|
464
|
+
if (typeof value === "number") {
|
|
465
|
+
const result = isSafeNumber(value);
|
|
466
|
+
isValid = result === true;
|
|
467
|
+
} else if (typeof value === "string") {
|
|
468
|
+
if (value.trim() === "") {
|
|
469
|
+
isValid = false;
|
|
470
|
+
} else {
|
|
471
|
+
const num = Number(value);
|
|
472
|
+
const result = isSafeNumber(num);
|
|
473
|
+
isValid = result === true;
|
|
474
|
+
}
|
|
475
|
+
} else {
|
|
476
|
+
isValid = false;
|
|
447
477
|
}
|
|
448
|
-
return false;
|
|
478
|
+
return isValid ? true : message || false;
|
|
449
479
|
};
|
|
450
480
|
|
|
451
|
-
const isObject = (value) =>
|
|
481
|
+
const isObject = (value, message) => {
|
|
482
|
+
const isValid = value !== null && typeof value === "object" && !Array.isArray(value);
|
|
483
|
+
return isValid ? true : message || false;
|
|
484
|
+
};
|
|
452
485
|
|
|
453
|
-
const isOneOf = (value, options) =>
|
|
486
|
+
const isOneOf = (value, options, message) => {
|
|
487
|
+
const isValid = options.includes(value);
|
|
488
|
+
return isValid ? true : message || false;
|
|
489
|
+
};
|
|
454
490
|
|
|
455
|
-
const isPhoneNumber = (value) =>
|
|
456
|
-
value
|
|
457
|
-
|
|
491
|
+
const isPhoneNumber = (value, message) => {
|
|
492
|
+
const isValid = isString(value) && /\+(9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|4[987654310]|3[9643210]|2[70]|7|1)\d{1,14}$/.test(
|
|
493
|
+
value
|
|
494
|
+
);
|
|
495
|
+
return isValid ? true : message || false;
|
|
496
|
+
};
|
|
458
497
|
|
|
459
|
-
const isRequired = (value) =>
|
|
498
|
+
const isRequired = (value, message) => {
|
|
499
|
+
const isValid = !!value;
|
|
500
|
+
return isValid ? true : message || false;
|
|
501
|
+
};
|
|
460
502
|
|
|
461
|
-
const isSlug = (value) =>
|
|
503
|
+
const isSlug = (value, message) => {
|
|
504
|
+
const stringResult = isString(value);
|
|
505
|
+
const isStringValid = stringResult === true;
|
|
506
|
+
const isValid = isStringValid && /^[a-z0-9-]+$/.test(value);
|
|
507
|
+
return isValid ? true : message || false;
|
|
508
|
+
};
|
|
462
509
|
|
|
463
|
-
const isLessThan = (value, maxValue, includeEqual = false) =>
|
|
510
|
+
const isLessThan = (value, maxValue, includeEqual = false, message) => {
|
|
511
|
+
const safeNumberResult = isSafeNumber(value);
|
|
512
|
+
const isSafeNum = safeNumberResult === true;
|
|
513
|
+
const isValid = isSafeNum && (includeEqual ? value <= maxValue : value < maxValue);
|
|
514
|
+
return isValid ? true : message || false;
|
|
515
|
+
};
|
|
464
516
|
|
|
465
|
-
const isUrl = (value) => {
|
|
466
|
-
|
|
517
|
+
const isUrl = (value, message) => {
|
|
518
|
+
const stringResult = isString(value);
|
|
519
|
+
if (stringResult !== true) return message || false;
|
|
467
520
|
try {
|
|
468
521
|
new URL(value);
|
|
469
522
|
return true;
|
|
470
523
|
} catch (_) {
|
|
471
|
-
return false;
|
|
524
|
+
return message || false;
|
|
472
525
|
}
|
|
473
526
|
};
|
|
474
527
|
|
|
475
|
-
const isUrlPath = (value) =>
|
|
528
|
+
const isUrlPath = (value, message) => {
|
|
529
|
+
const stringCheck = isString(value);
|
|
530
|
+
const isValid = stringCheck === true && value.length > 0 && /^[a-z0-9\-_\/]+$/.test(value);
|
|
531
|
+
return isValid ? true : message || false;
|
|
532
|
+
};
|
|
476
533
|
|
|
477
534
|
const getDateValue = (date) => ({
|
|
478
535
|
year: date.getFullYear(),
|
|
@@ -484,24 +541,110 @@ const getDateValue = (date) => ({
|
|
|
484
541
|
millisecond: date.getMilliseconds()
|
|
485
542
|
});
|
|
486
543
|
|
|
487
|
-
const isLongerThan = (value, minLength, includeEqual = false) => {
|
|
488
|
-
if (typeof value !== "string") return false;
|
|
489
|
-
|
|
544
|
+
const isLongerThan = (value, minLength, includeEqual = false, message) => {
|
|
545
|
+
if (typeof value !== "string") return message || false;
|
|
546
|
+
const isValid = includeEqual ? value.length >= minLength : value.length > minLength;
|
|
547
|
+
return isValid ? true : message || false;
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
const isShorterThan = (value, maxLength, includeEqual = false, message) => {
|
|
551
|
+
if (typeof value !== "string") return message || false;
|
|
552
|
+
const isValid = includeEqual ? value.length <= maxLength : value.length < maxLength;
|
|
553
|
+
return isValid ? true : message || false;
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
const hasPattern = (value, pattern, message) => {
|
|
557
|
+
if (typeof value !== "string") return message || false;
|
|
558
|
+
const isValid = pattern.test(value);
|
|
559
|
+
return isValid ? true : message || false;
|
|
560
|
+
};
|
|
561
|
+
|
|
562
|
+
const hasDateFormat = (value, message) => {
|
|
563
|
+
if (typeof value === "bigint" || typeof value === "symbol") {
|
|
564
|
+
return message || false;
|
|
565
|
+
}
|
|
566
|
+
if (typeof value === "number") {
|
|
567
|
+
try {
|
|
568
|
+
const date = new Date(value);
|
|
569
|
+
const isValid = !Number.isNaN(date.getTime());
|
|
570
|
+
return isValid ? true : message || false;
|
|
571
|
+
} catch {
|
|
572
|
+
return message || false;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
const str = asString(value);
|
|
576
|
+
if (!str) {
|
|
577
|
+
return message || false;
|
|
578
|
+
}
|
|
579
|
+
try {
|
|
580
|
+
const date = new Date(str);
|
|
581
|
+
const isValid = !Number.isNaN(date.getTime());
|
|
582
|
+
return isValid ? true : message || false;
|
|
583
|
+
} catch {
|
|
584
|
+
return message || false;
|
|
585
|
+
}
|
|
490
586
|
};
|
|
491
587
|
|
|
492
|
-
const
|
|
493
|
-
|
|
494
|
-
return
|
|
588
|
+
const isInteger = (value, message) => {
|
|
589
|
+
const isValid = isSafeNumber(value) && Number.isInteger(value);
|
|
590
|
+
return isValid ? true : message || false;
|
|
495
591
|
};
|
|
496
592
|
|
|
497
|
-
const
|
|
498
|
-
|
|
499
|
-
return
|
|
593
|
+
const isEqual = (value, valueB, message) => {
|
|
594
|
+
const isValid = equalsJSON(value, valueB);
|
|
595
|
+
return isValid ? true : message || false;
|
|
500
596
|
};
|
|
501
597
|
|
|
502
|
-
const
|
|
598
|
+
const isTrue = (value, message) => {
|
|
599
|
+
const isValid = value === true;
|
|
600
|
+
return isValid ? true : message || false;
|
|
601
|
+
};
|
|
503
602
|
|
|
504
|
-
const
|
|
603
|
+
const isFalse = (value, message) => {
|
|
604
|
+
const isValid = value === false;
|
|
605
|
+
return isValid ? true : message || false;
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
const isTruthy = (value, message) => {
|
|
609
|
+
const isValid = !!value;
|
|
610
|
+
return isValid ? true : message || false;
|
|
611
|
+
};
|
|
612
|
+
|
|
613
|
+
const isFalsy = (value, message) => {
|
|
614
|
+
const isValid = !value;
|
|
615
|
+
return isValid ? true : message || false;
|
|
616
|
+
};
|
|
617
|
+
|
|
618
|
+
const isInstanceOf = (value, someConstructorFunction, message) => {
|
|
619
|
+
if (typeof someConstructorFunction !== "function") {
|
|
620
|
+
throw new TypeError("Expected a constructor function");
|
|
621
|
+
}
|
|
622
|
+
const isValid = value instanceof someConstructorFunction && value.constructor === someConstructorFunction;
|
|
623
|
+
return isValid ? true : message || false;
|
|
624
|
+
};
|
|
625
|
+
|
|
626
|
+
const isTypeOf = (value, type, message) => {
|
|
627
|
+
let isValid = false;
|
|
628
|
+
if (type === "string") {
|
|
629
|
+
isValid = typeof value === "string";
|
|
630
|
+
} else if (type === "number") {
|
|
631
|
+
isValid = typeof value === "number";
|
|
632
|
+
} else if (type === "boolean") {
|
|
633
|
+
isValid = typeof value === "boolean";
|
|
634
|
+
} else if (type === "object") {
|
|
635
|
+
isValid = typeof value === "object" && value !== null;
|
|
636
|
+
} else if (type === "function") {
|
|
637
|
+
isValid = typeof value === "function";
|
|
638
|
+
} else if (type === "undefined") {
|
|
639
|
+
isValid = typeof value === "undefined";
|
|
640
|
+
}
|
|
641
|
+
return isValid ? true : message || false;
|
|
642
|
+
};
|
|
643
|
+
|
|
644
|
+
const isNull = (value, message) => {
|
|
645
|
+
const isValid = value === null;
|
|
646
|
+
return isValid ? true : message || false;
|
|
647
|
+
};
|
|
505
648
|
|
|
506
649
|
function preload(url, as = "image") {
|
|
507
650
|
const urls = Array.isArray(url) ? url : [url];
|
|
@@ -536,6 +679,7 @@ exports.equalsJSON = equalsJSON;
|
|
|
536
679
|
exports.getAllKeysFromPath = getAllKeysFromPath;
|
|
537
680
|
exports.getByPath = getByPath;
|
|
538
681
|
exports.getDateValue = getDateValue;
|
|
682
|
+
exports.hasDateFormat = hasDateFormat;
|
|
539
683
|
exports.hasPattern = hasPattern;
|
|
540
684
|
exports.hexToBinary = hexToBinary;
|
|
541
685
|
exports.is = is;
|
|
@@ -551,9 +695,11 @@ exports.isEqual = isEqual;
|
|
|
551
695
|
exports.isFalse = isFalse;
|
|
552
696
|
exports.isFalsy = isFalsy;
|
|
553
697
|
exports.isGreaterThan = isGreaterThan;
|
|
698
|
+
exports.isInstanceOf = isInstanceOf;
|
|
554
699
|
exports.isInteger = isInteger;
|
|
555
700
|
exports.isLessThan = isLessThan;
|
|
556
701
|
exports.isLongerThan = isLongerThan;
|
|
702
|
+
exports.isNull = isNull;
|
|
557
703
|
exports.isObject = isObject;
|
|
558
704
|
exports.isOneOf = isOneOf;
|
|
559
705
|
exports.isPathAccessor = isPathAccessor;
|
|
@@ -566,6 +712,7 @@ exports.isSlug = isSlug;
|
|
|
566
712
|
exports.isString = isString;
|
|
567
713
|
exports.isTrue = isTrue;
|
|
568
714
|
exports.isTruthy = isTruthy;
|
|
715
|
+
exports.isTypeOf = isTypeOf;
|
|
569
716
|
exports.isUrl = isUrl;
|
|
570
717
|
exports.isUrlPath = isUrlPath;
|
|
571
718
|
exports.omit = omit;
|