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.mjs
CHANGED
|
@@ -385,92 +385,149 @@ const asInteger = (value) => {
|
|
|
385
385
|
return asNumber(Number.parseInt(asString(number), 10).toFixed(0));
|
|
386
386
|
};
|
|
387
387
|
|
|
388
|
-
const
|
|
389
|
-
|
|
388
|
+
const isAfter = (value, minDate, inclusive = false, message) => {
|
|
389
|
+
const isValid = value instanceof Date && (inclusive ? value.getTime() >= minDate.getTime() : value.getTime() > minDate.getTime());
|
|
390
|
+
return isValid ? true : message || false;
|
|
390
391
|
};
|
|
391
392
|
|
|
392
|
-
const
|
|
393
|
-
|
|
393
|
+
const isArray = (value, message) => {
|
|
394
|
+
const isValid = Array.isArray(value);
|
|
395
|
+
return isValid ? true : message || false;
|
|
394
396
|
};
|
|
395
397
|
|
|
396
|
-
const
|
|
397
|
-
|
|
398
|
+
const isBefore = (value, maxDate, inclusive = false, message) => {
|
|
399
|
+
const isValid = value instanceof Date && (inclusive ? value.getTime() <= maxDate.getTime() : value.getTime() < maxDate.getTime());
|
|
400
|
+
return isValid ? true : message || false;
|
|
398
401
|
};
|
|
399
402
|
|
|
400
|
-
const
|
|
401
|
-
|
|
403
|
+
const isBoolean = (value, message) => {
|
|
404
|
+
const isValid = typeof value === "boolean";
|
|
405
|
+
return isValid ? true : message || false;
|
|
402
406
|
};
|
|
403
407
|
|
|
404
|
-
const
|
|
405
|
-
|
|
408
|
+
const isDate = (value, message) => {
|
|
409
|
+
const isValid = value instanceof Date && !Number.isNaN(value.getDate());
|
|
410
|
+
return isValid ? true : message || false;
|
|
406
411
|
};
|
|
407
412
|
|
|
408
|
-
const
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
const isBoolean = (value) => typeof value === "boolean";
|
|
413
|
-
|
|
414
|
-
const isDate = (value) => value instanceof Date && !Number.isNaN(value.getDate());
|
|
415
|
-
|
|
416
|
-
const isDefined = (value) => typeof value !== "undefined";
|
|
413
|
+
const isDefined = (value, message) => {
|
|
414
|
+
const isValid = typeof value !== "undefined";
|
|
415
|
+
return isValid ? true : message || false;
|
|
416
|
+
};
|
|
417
417
|
|
|
418
|
-
const isString = (value) =>
|
|
418
|
+
const isString = (value, message) => {
|
|
419
|
+
const isValid = typeof value === "string";
|
|
420
|
+
return isValid ? true : message || false;
|
|
421
|
+
};
|
|
419
422
|
|
|
420
|
-
const isEmail = (value) =>
|
|
421
|
-
value
|
|
422
|
-
|
|
423
|
+
const isEmail = (value, message) => {
|
|
424
|
+
const stringResult = isString(value);
|
|
425
|
+
const isStringValid = stringResult === true;
|
|
426
|
+
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(
|
|
427
|
+
value
|
|
428
|
+
);
|
|
429
|
+
return isValid ? true : message || false;
|
|
430
|
+
};
|
|
423
431
|
|
|
424
|
-
const isEmpty = (value) => {
|
|
425
|
-
|
|
426
|
-
if (
|
|
427
|
-
if (
|
|
428
|
-
if (value
|
|
429
|
-
if (
|
|
430
|
-
|
|
432
|
+
const isEmpty = (value, message) => {
|
|
433
|
+
let isValid = false;
|
|
434
|
+
if (value === null || value === void 0) isValid = true;
|
|
435
|
+
else if (typeof value === "string") isValid = value === "";
|
|
436
|
+
else if (Array.isArray(value)) isValid = value.length === 0;
|
|
437
|
+
else if (value instanceof Date) isValid = false;
|
|
438
|
+
else if (typeof value === "object") isValid = Object.keys(value).length === 0;
|
|
439
|
+
else isValid = false;
|
|
440
|
+
return isValid ? true : message || false;
|
|
431
441
|
};
|
|
432
442
|
|
|
433
|
-
const is = (value, valueB) =>
|
|
443
|
+
const is = (value, valueB, message) => {
|
|
444
|
+
const isValid = value === valueB;
|
|
445
|
+
return isValid ? true : message || false;
|
|
446
|
+
};
|
|
434
447
|
|
|
435
|
-
const isSafeNumber = (value) =>
|
|
448
|
+
const isSafeNumber = (value, message) => {
|
|
449
|
+
const isValid = typeof value === "number" && !Number.isNaN(value) && Number.isFinite(value);
|
|
450
|
+
return isValid ? true : message || false;
|
|
451
|
+
};
|
|
436
452
|
|
|
437
|
-
const isGreaterThan = (value, minValue, includeEqual = false) =>
|
|
453
|
+
const isGreaterThan = (value, minValue, includeEqual = false, message) => {
|
|
454
|
+
const safeNumberResult = isSafeNumber(value);
|
|
455
|
+
const isSafeNum = safeNumberResult === true;
|
|
456
|
+
const isValid = isSafeNum && (includeEqual ? value >= minValue : value > minValue);
|
|
457
|
+
return isValid ? true : message || false;
|
|
458
|
+
};
|
|
438
459
|
|
|
439
|
-
const isSafeNumeric = (value) => {
|
|
440
|
-
|
|
441
|
-
if (typeof value === "
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
460
|
+
const isSafeNumeric = (value, message) => {
|
|
461
|
+
let isValid = false;
|
|
462
|
+
if (typeof value === "number") {
|
|
463
|
+
const result = isSafeNumber(value);
|
|
464
|
+
isValid = result === true;
|
|
465
|
+
} else if (typeof value === "string") {
|
|
466
|
+
if (value.trim() === "") {
|
|
467
|
+
isValid = false;
|
|
468
|
+
} else {
|
|
469
|
+
const num = Number(value);
|
|
470
|
+
const result = isSafeNumber(num);
|
|
471
|
+
isValid = result === true;
|
|
472
|
+
}
|
|
473
|
+
} else {
|
|
474
|
+
isValid = false;
|
|
445
475
|
}
|
|
446
|
-
return false;
|
|
476
|
+
return isValid ? true : message || false;
|
|
447
477
|
};
|
|
448
478
|
|
|
449
|
-
const isObject = (value) =>
|
|
479
|
+
const isObject = (value, message) => {
|
|
480
|
+
const isValid = value !== null && typeof value === "object" && !Array.isArray(value);
|
|
481
|
+
return isValid ? true : message || false;
|
|
482
|
+
};
|
|
450
483
|
|
|
451
|
-
const isOneOf = (value, options) =>
|
|
484
|
+
const isOneOf = (value, options, message) => {
|
|
485
|
+
const isValid = options.includes(value);
|
|
486
|
+
return isValid ? true : message || false;
|
|
487
|
+
};
|
|
452
488
|
|
|
453
|
-
const isPhoneNumber = (value) =>
|
|
454
|
-
value
|
|
455
|
-
|
|
489
|
+
const isPhoneNumber = (value, message) => {
|
|
490
|
+
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(
|
|
491
|
+
value
|
|
492
|
+
);
|
|
493
|
+
return isValid ? true : message || false;
|
|
494
|
+
};
|
|
456
495
|
|
|
457
|
-
const isRequired = (value) =>
|
|
496
|
+
const isRequired = (value, message) => {
|
|
497
|
+
const isValid = !!value;
|
|
498
|
+
return isValid ? true : message || false;
|
|
499
|
+
};
|
|
458
500
|
|
|
459
|
-
const isSlug = (value) =>
|
|
501
|
+
const isSlug = (value, message) => {
|
|
502
|
+
const stringResult = isString(value);
|
|
503
|
+
const isStringValid = stringResult === true;
|
|
504
|
+
const isValid = isStringValid && /^[a-z0-9-]+$/.test(value);
|
|
505
|
+
return isValid ? true : message || false;
|
|
506
|
+
};
|
|
460
507
|
|
|
461
|
-
const isLessThan = (value, maxValue, includeEqual = false) =>
|
|
508
|
+
const isLessThan = (value, maxValue, includeEqual = false, message) => {
|
|
509
|
+
const safeNumberResult = isSafeNumber(value);
|
|
510
|
+
const isSafeNum = safeNumberResult === true;
|
|
511
|
+
const isValid = isSafeNum && (includeEqual ? value <= maxValue : value < maxValue);
|
|
512
|
+
return isValid ? true : message || false;
|
|
513
|
+
};
|
|
462
514
|
|
|
463
|
-
const isUrl = (value) => {
|
|
464
|
-
|
|
515
|
+
const isUrl = (value, message) => {
|
|
516
|
+
const stringResult = isString(value);
|
|
517
|
+
if (stringResult !== true) return message || false;
|
|
465
518
|
try {
|
|
466
519
|
new URL(value);
|
|
467
520
|
return true;
|
|
468
521
|
} catch (_) {
|
|
469
|
-
return false;
|
|
522
|
+
return message || false;
|
|
470
523
|
}
|
|
471
524
|
};
|
|
472
525
|
|
|
473
|
-
const isUrlPath = (value) =>
|
|
526
|
+
const isUrlPath = (value, message) => {
|
|
527
|
+
const stringCheck = isString(value);
|
|
528
|
+
const isValid = stringCheck === true && value.length > 0 && /^[a-z0-9\-_\/]+$/.test(value);
|
|
529
|
+
return isValid ? true : message || false;
|
|
530
|
+
};
|
|
474
531
|
|
|
475
532
|
const getDateValue = (date) => ({
|
|
476
533
|
year: date.getFullYear(),
|
|
@@ -482,24 +539,110 @@ const getDateValue = (date) => ({
|
|
|
482
539
|
millisecond: date.getMilliseconds()
|
|
483
540
|
});
|
|
484
541
|
|
|
485
|
-
const isLongerThan = (value, minLength, includeEqual = false) => {
|
|
486
|
-
if (typeof value !== "string") return false;
|
|
487
|
-
|
|
542
|
+
const isLongerThan = (value, minLength, includeEqual = false, message) => {
|
|
543
|
+
if (typeof value !== "string") return message || false;
|
|
544
|
+
const isValid = includeEqual ? value.length >= minLength : value.length > minLength;
|
|
545
|
+
return isValid ? true : message || false;
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
const isShorterThan = (value, maxLength, includeEqual = false, message) => {
|
|
549
|
+
if (typeof value !== "string") return message || false;
|
|
550
|
+
const isValid = includeEqual ? value.length <= maxLength : value.length < maxLength;
|
|
551
|
+
return isValid ? true : message || false;
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
const hasPattern = (value, pattern, message) => {
|
|
555
|
+
if (typeof value !== "string") return message || false;
|
|
556
|
+
const isValid = pattern.test(value);
|
|
557
|
+
return isValid ? true : message || false;
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
const hasDateFormat = (value, message) => {
|
|
561
|
+
if (typeof value === "bigint" || typeof value === "symbol") {
|
|
562
|
+
return message || false;
|
|
563
|
+
}
|
|
564
|
+
if (typeof value === "number") {
|
|
565
|
+
try {
|
|
566
|
+
const date = new Date(value);
|
|
567
|
+
const isValid = !Number.isNaN(date.getTime());
|
|
568
|
+
return isValid ? true : message || false;
|
|
569
|
+
} catch {
|
|
570
|
+
return message || false;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
const str = asString(value);
|
|
574
|
+
if (!str) {
|
|
575
|
+
return message || false;
|
|
576
|
+
}
|
|
577
|
+
try {
|
|
578
|
+
const date = new Date(str);
|
|
579
|
+
const isValid = !Number.isNaN(date.getTime());
|
|
580
|
+
return isValid ? true : message || false;
|
|
581
|
+
} catch {
|
|
582
|
+
return message || false;
|
|
583
|
+
}
|
|
488
584
|
};
|
|
489
585
|
|
|
490
|
-
const
|
|
491
|
-
|
|
492
|
-
return
|
|
586
|
+
const isInteger = (value, message) => {
|
|
587
|
+
const isValid = isSafeNumber(value) && Number.isInteger(value);
|
|
588
|
+
return isValid ? true : message || false;
|
|
493
589
|
};
|
|
494
590
|
|
|
495
|
-
const
|
|
496
|
-
|
|
497
|
-
return
|
|
591
|
+
const isEqual = (value, valueB, message) => {
|
|
592
|
+
const isValid = equalsJSON(value, valueB);
|
|
593
|
+
return isValid ? true : message || false;
|
|
498
594
|
};
|
|
499
595
|
|
|
500
|
-
const
|
|
596
|
+
const isTrue = (value, message) => {
|
|
597
|
+
const isValid = value === true;
|
|
598
|
+
return isValid ? true : message || false;
|
|
599
|
+
};
|
|
501
600
|
|
|
502
|
-
const
|
|
601
|
+
const isFalse = (value, message) => {
|
|
602
|
+
const isValid = value === false;
|
|
603
|
+
return isValid ? true : message || false;
|
|
604
|
+
};
|
|
605
|
+
|
|
606
|
+
const isTruthy = (value, message) => {
|
|
607
|
+
const isValid = !!value;
|
|
608
|
+
return isValid ? true : message || false;
|
|
609
|
+
};
|
|
610
|
+
|
|
611
|
+
const isFalsy = (value, message) => {
|
|
612
|
+
const isValid = !value;
|
|
613
|
+
return isValid ? true : message || false;
|
|
614
|
+
};
|
|
615
|
+
|
|
616
|
+
const isInstanceOf = (value, someConstructorFunction, message) => {
|
|
617
|
+
if (typeof someConstructorFunction !== "function") {
|
|
618
|
+
throw new TypeError("Expected a constructor function");
|
|
619
|
+
}
|
|
620
|
+
const isValid = value instanceof someConstructorFunction && value.constructor === someConstructorFunction;
|
|
621
|
+
return isValid ? true : message || false;
|
|
622
|
+
};
|
|
623
|
+
|
|
624
|
+
const isTypeOf = (value, type, message) => {
|
|
625
|
+
let isValid = false;
|
|
626
|
+
if (type === "string") {
|
|
627
|
+
isValid = typeof value === "string";
|
|
628
|
+
} else if (type === "number") {
|
|
629
|
+
isValid = typeof value === "number";
|
|
630
|
+
} else if (type === "boolean") {
|
|
631
|
+
isValid = typeof value === "boolean";
|
|
632
|
+
} else if (type === "object") {
|
|
633
|
+
isValid = typeof value === "object" && value !== null;
|
|
634
|
+
} else if (type === "function") {
|
|
635
|
+
isValid = typeof value === "function";
|
|
636
|
+
} else if (type === "undefined") {
|
|
637
|
+
isValid = typeof value === "undefined";
|
|
638
|
+
}
|
|
639
|
+
return isValid ? true : message || false;
|
|
640
|
+
};
|
|
641
|
+
|
|
642
|
+
const isNull = (value, message) => {
|
|
643
|
+
const isValid = value === null;
|
|
644
|
+
return isValid ? true : message || false;
|
|
645
|
+
};
|
|
503
646
|
|
|
504
647
|
function preload(url, as = "image") {
|
|
505
648
|
const urls = Array.isArray(url) ? url : [url];
|
|
@@ -512,4 +655,4 @@ function preload(url, as = "image") {
|
|
|
512
655
|
});
|
|
513
656
|
}
|
|
514
657
|
|
|
515
|
-
export { PATH_ACCESSOR_SYMBOL, _BASE64_CHARS, _HEX_PREFIX, _base64LookupMap, _getBase64LookupMap, access, asArray, asBoolean, asDate, asInteger, asNumber, asString, base64ToBinary, binaryToBase64, binaryToHex, binaryToText, createTimeoutPromise, debounce, ensureKey, equalsJSON, getAllKeysFromPath, getByPath, getDateValue, hasPattern, hexToBinary, is, isAfter, isArray, isBefore, isBoolean, isDate, isDefined, isEmail, isEmpty, isEqual, isFalse, isFalsy, isGreaterThan, isInteger, isLessThan, isLongerThan, isObject, isOneOf, isPathAccessor, isPhoneNumber, isRequired, isSafeNumber, isSafeNumeric, isShorterThan, isSlug, isString, isTrue, isTruthy, isUrl, isUrlPath, omit, pick, preload, setByPath, textToBinary, throttle, unique, wait, waitForRef, waitForWithPolling };
|
|
658
|
+
export { PATH_ACCESSOR_SYMBOL, _BASE64_CHARS, _HEX_PREFIX, _base64LookupMap, _getBase64LookupMap, access, asArray, asBoolean, asDate, asInteger, asNumber, asString, base64ToBinary, binaryToBase64, binaryToHex, binaryToText, createTimeoutPromise, debounce, ensureKey, equalsJSON, getAllKeysFromPath, getByPath, getDateValue, hasDateFormat, hasPattern, hexToBinary, is, isAfter, isArray, isBefore, isBoolean, isDate, isDefined, isEmail, isEmpty, isEqual, isFalse, isFalsy, isGreaterThan, isInstanceOf, isInteger, isLessThan, isLongerThan, isNull, isObject, isOneOf, isPathAccessor, isPhoneNumber, isRequired, isSafeNumber, isSafeNumeric, isShorterThan, isSlug, isString, isTrue, isTruthy, isTypeOf, isUrl, isUrlPath, omit, pick, preload, setByPath, textToBinary, throttle, unique, wait, waitForRef, waitForWithPolling };
|