defuss-runtime 1.0.4 → 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 +218 -51
- package/dist/index.d.cts +355 -22
- package/dist/index.d.mts +355 -22
- package/dist/index.mjs +211 -52
- package/package.json +12 -10
package/dist/index.cjs
CHANGED
|
@@ -387,76 +387,149 @@ const asInteger = (value) => {
|
|
|
387
387
|
return asNumber(Number.parseInt(asString(number), 10).toFixed(0));
|
|
388
388
|
};
|
|
389
389
|
|
|
390
|
-
const isAfter = (value, minDate, inclusive = false) => {
|
|
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 isArray = (value) =>
|
|
395
|
+
const isArray = (value, message) => {
|
|
396
|
+
const isValid = Array.isArray(value);
|
|
397
|
+
return isValid ? true : message || false;
|
|
398
|
+
};
|
|
395
399
|
|
|
396
|
-
const isBefore = (value, maxDate, inclusive = false) =>
|
|
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;
|
|
403
|
+
};
|
|
397
404
|
|
|
398
|
-
const isBoolean = (value) =>
|
|
405
|
+
const isBoolean = (value, message) => {
|
|
406
|
+
const isValid = typeof value === "boolean";
|
|
407
|
+
return isValid ? true : message || false;
|
|
408
|
+
};
|
|
399
409
|
|
|
400
|
-
const isDate = (value) =>
|
|
410
|
+
const isDate = (value, message) => {
|
|
411
|
+
const isValid = value instanceof Date && !Number.isNaN(value.getDate());
|
|
412
|
+
return isValid ? true : message || false;
|
|
413
|
+
};
|
|
401
414
|
|
|
402
|
-
const isDefined = (value) =>
|
|
415
|
+
const isDefined = (value, message) => {
|
|
416
|
+
const isValid = typeof value !== "undefined";
|
|
417
|
+
return isValid ? true : message || false;
|
|
418
|
+
};
|
|
403
419
|
|
|
404
|
-
const isString = (value) =>
|
|
420
|
+
const isString = (value, message) => {
|
|
421
|
+
const isValid = typeof value === "string";
|
|
422
|
+
return isValid ? true : message || false;
|
|
423
|
+
};
|
|
405
424
|
|
|
406
|
-
const isEmail = (value) =>
|
|
407
|
-
value
|
|
408
|
-
|
|
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
|
+
};
|
|
409
433
|
|
|
410
|
-
const isEmpty = (value) => {
|
|
411
|
-
|
|
412
|
-
if (
|
|
413
|
-
if (
|
|
414
|
-
if (value
|
|
415
|
-
if (
|
|
416
|
-
|
|
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;
|
|
417
443
|
};
|
|
418
444
|
|
|
419
|
-
const is = (value, valueB) =>
|
|
445
|
+
const is = (value, valueB, message) => {
|
|
446
|
+
const isValid = value === valueB;
|
|
447
|
+
return isValid ? true : message || false;
|
|
448
|
+
};
|
|
420
449
|
|
|
421
|
-
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
|
+
};
|
|
422
454
|
|
|
423
|
-
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
|
+
};
|
|
424
461
|
|
|
425
|
-
const isSafeNumeric = (value) => {
|
|
426
|
-
|
|
427
|
-
if (typeof value === "
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
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;
|
|
431
477
|
}
|
|
432
|
-
return false;
|
|
478
|
+
return isValid ? true : message || false;
|
|
433
479
|
};
|
|
434
480
|
|
|
435
|
-
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
|
+
};
|
|
436
485
|
|
|
437
|
-
const isOneOf = (value, options) =>
|
|
486
|
+
const isOneOf = (value, options, message) => {
|
|
487
|
+
const isValid = options.includes(value);
|
|
488
|
+
return isValid ? true : message || false;
|
|
489
|
+
};
|
|
438
490
|
|
|
439
|
-
const isPhoneNumber = (value) =>
|
|
440
|
-
value
|
|
441
|
-
|
|
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
|
+
};
|
|
442
497
|
|
|
443
|
-
const isRequired = (value) =>
|
|
498
|
+
const isRequired = (value, message) => {
|
|
499
|
+
const isValid = !!value;
|
|
500
|
+
return isValid ? true : message || false;
|
|
501
|
+
};
|
|
444
502
|
|
|
445
|
-
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
|
+
};
|
|
446
509
|
|
|
447
|
-
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
|
+
};
|
|
448
516
|
|
|
449
|
-
const isUrl = (value) => {
|
|
450
|
-
|
|
517
|
+
const isUrl = (value, message) => {
|
|
518
|
+
const stringResult = isString(value);
|
|
519
|
+
if (stringResult !== true) return message || false;
|
|
451
520
|
try {
|
|
452
521
|
new URL(value);
|
|
453
522
|
return true;
|
|
454
523
|
} catch (_) {
|
|
455
|
-
return false;
|
|
524
|
+
return message || false;
|
|
456
525
|
}
|
|
457
526
|
};
|
|
458
527
|
|
|
459
|
-
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
|
+
};
|
|
460
533
|
|
|
461
534
|
const getDateValue = (date) => ({
|
|
462
535
|
year: date.getFullYear(),
|
|
@@ -468,24 +541,110 @@ const getDateValue = (date) => ({
|
|
|
468
541
|
millisecond: date.getMilliseconds()
|
|
469
542
|
});
|
|
470
543
|
|
|
471
|
-
const isLongerThan = (value, minLength, includeEqual = false) => {
|
|
472
|
-
if (typeof value !== "string") return false;
|
|
473
|
-
|
|
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
|
+
}
|
|
474
586
|
};
|
|
475
587
|
|
|
476
|
-
const
|
|
477
|
-
|
|
478
|
-
return
|
|
588
|
+
const isInteger = (value, message) => {
|
|
589
|
+
const isValid = isSafeNumber(value) && Number.isInteger(value);
|
|
590
|
+
return isValid ? true : message || false;
|
|
479
591
|
};
|
|
480
592
|
|
|
481
|
-
const
|
|
482
|
-
|
|
483
|
-
return
|
|
593
|
+
const isEqual = (value, valueB, message) => {
|
|
594
|
+
const isValid = equalsJSON(value, valueB);
|
|
595
|
+
return isValid ? true : message || false;
|
|
484
596
|
};
|
|
485
597
|
|
|
486
|
-
const
|
|
598
|
+
const isTrue = (value, message) => {
|
|
599
|
+
const isValid = value === true;
|
|
600
|
+
return isValid ? true : message || false;
|
|
601
|
+
};
|
|
487
602
|
|
|
488
|
-
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
|
+
};
|
|
489
648
|
|
|
490
649
|
function preload(url, as = "image") {
|
|
491
650
|
const urls = Array.isArray(url) ? url : [url];
|
|
@@ -520,6 +679,7 @@ exports.equalsJSON = equalsJSON;
|
|
|
520
679
|
exports.getAllKeysFromPath = getAllKeysFromPath;
|
|
521
680
|
exports.getByPath = getByPath;
|
|
522
681
|
exports.getDateValue = getDateValue;
|
|
682
|
+
exports.hasDateFormat = hasDateFormat;
|
|
523
683
|
exports.hasPattern = hasPattern;
|
|
524
684
|
exports.hexToBinary = hexToBinary;
|
|
525
685
|
exports.is = is;
|
|
@@ -532,10 +692,14 @@ exports.isDefined = isDefined;
|
|
|
532
692
|
exports.isEmail = isEmail;
|
|
533
693
|
exports.isEmpty = isEmpty;
|
|
534
694
|
exports.isEqual = isEqual;
|
|
695
|
+
exports.isFalse = isFalse;
|
|
696
|
+
exports.isFalsy = isFalsy;
|
|
535
697
|
exports.isGreaterThan = isGreaterThan;
|
|
698
|
+
exports.isInstanceOf = isInstanceOf;
|
|
536
699
|
exports.isInteger = isInteger;
|
|
537
700
|
exports.isLessThan = isLessThan;
|
|
538
701
|
exports.isLongerThan = isLongerThan;
|
|
702
|
+
exports.isNull = isNull;
|
|
539
703
|
exports.isObject = isObject;
|
|
540
704
|
exports.isOneOf = isOneOf;
|
|
541
705
|
exports.isPathAccessor = isPathAccessor;
|
|
@@ -546,6 +710,9 @@ exports.isSafeNumeric = isSafeNumeric;
|
|
|
546
710
|
exports.isShorterThan = isShorterThan;
|
|
547
711
|
exports.isSlug = isSlug;
|
|
548
712
|
exports.isString = isString;
|
|
713
|
+
exports.isTrue = isTrue;
|
|
714
|
+
exports.isTruthy = isTruthy;
|
|
715
|
+
exports.isTypeOf = isTypeOf;
|
|
549
716
|
exports.isUrl = isUrl;
|
|
550
717
|
exports.isUrlPath = isUrlPath;
|
|
551
718
|
exports.omit = omit;
|