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.mjs
CHANGED
|
@@ -385,76 +385,149 @@ const asInteger = (value) => {
|
|
|
385
385
|
return asNumber(Number.parseInt(asString(number), 10).toFixed(0));
|
|
386
386
|
};
|
|
387
387
|
|
|
388
|
-
const isAfter = (value, minDate, inclusive = false) => {
|
|
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 isArray = (value) =>
|
|
393
|
+
const isArray = (value, message) => {
|
|
394
|
+
const isValid = Array.isArray(value);
|
|
395
|
+
return isValid ? true : message || false;
|
|
396
|
+
};
|
|
393
397
|
|
|
394
|
-
const isBefore = (value, maxDate, inclusive = false) =>
|
|
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;
|
|
401
|
+
};
|
|
395
402
|
|
|
396
|
-
const isBoolean = (value) =>
|
|
403
|
+
const isBoolean = (value, message) => {
|
|
404
|
+
const isValid = typeof value === "boolean";
|
|
405
|
+
return isValid ? true : message || false;
|
|
406
|
+
};
|
|
397
407
|
|
|
398
|
-
const isDate = (value) =>
|
|
408
|
+
const isDate = (value, message) => {
|
|
409
|
+
const isValid = value instanceof Date && !Number.isNaN(value.getDate());
|
|
410
|
+
return isValid ? true : message || false;
|
|
411
|
+
};
|
|
399
412
|
|
|
400
|
-
const isDefined = (value) =>
|
|
413
|
+
const isDefined = (value, message) => {
|
|
414
|
+
const isValid = typeof value !== "undefined";
|
|
415
|
+
return isValid ? true : message || false;
|
|
416
|
+
};
|
|
401
417
|
|
|
402
|
-
const isString = (value) =>
|
|
418
|
+
const isString = (value, message) => {
|
|
419
|
+
const isValid = typeof value === "string";
|
|
420
|
+
return isValid ? true : message || false;
|
|
421
|
+
};
|
|
403
422
|
|
|
404
|
-
const isEmail = (value) =>
|
|
405
|
-
value
|
|
406
|
-
|
|
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
|
+
};
|
|
407
431
|
|
|
408
|
-
const isEmpty = (value) => {
|
|
409
|
-
|
|
410
|
-
if (
|
|
411
|
-
if (
|
|
412
|
-
if (value
|
|
413
|
-
if (
|
|
414
|
-
|
|
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;
|
|
415
441
|
};
|
|
416
442
|
|
|
417
|
-
const is = (value, valueB) =>
|
|
443
|
+
const is = (value, valueB, message) => {
|
|
444
|
+
const isValid = value === valueB;
|
|
445
|
+
return isValid ? true : message || false;
|
|
446
|
+
};
|
|
418
447
|
|
|
419
|
-
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
|
+
};
|
|
420
452
|
|
|
421
|
-
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
|
+
};
|
|
422
459
|
|
|
423
|
-
const isSafeNumeric = (value) => {
|
|
424
|
-
|
|
425
|
-
if (typeof value === "
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
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;
|
|
429
475
|
}
|
|
430
|
-
return false;
|
|
476
|
+
return isValid ? true : message || false;
|
|
431
477
|
};
|
|
432
478
|
|
|
433
|
-
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
|
+
};
|
|
434
483
|
|
|
435
|
-
const isOneOf = (value, options) =>
|
|
484
|
+
const isOneOf = (value, options, message) => {
|
|
485
|
+
const isValid = options.includes(value);
|
|
486
|
+
return isValid ? true : message || false;
|
|
487
|
+
};
|
|
436
488
|
|
|
437
|
-
const isPhoneNumber = (value) =>
|
|
438
|
-
value
|
|
439
|
-
|
|
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
|
+
};
|
|
440
495
|
|
|
441
|
-
const isRequired = (value) =>
|
|
496
|
+
const isRequired = (value, message) => {
|
|
497
|
+
const isValid = !!value;
|
|
498
|
+
return isValid ? true : message || false;
|
|
499
|
+
};
|
|
442
500
|
|
|
443
|
-
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
|
+
};
|
|
444
507
|
|
|
445
|
-
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
|
+
};
|
|
446
514
|
|
|
447
|
-
const isUrl = (value) => {
|
|
448
|
-
|
|
515
|
+
const isUrl = (value, message) => {
|
|
516
|
+
const stringResult = isString(value);
|
|
517
|
+
if (stringResult !== true) return message || false;
|
|
449
518
|
try {
|
|
450
519
|
new URL(value);
|
|
451
520
|
return true;
|
|
452
521
|
} catch (_) {
|
|
453
|
-
return false;
|
|
522
|
+
return message || false;
|
|
454
523
|
}
|
|
455
524
|
};
|
|
456
525
|
|
|
457
|
-
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
|
+
};
|
|
458
531
|
|
|
459
532
|
const getDateValue = (date) => ({
|
|
460
533
|
year: date.getFullYear(),
|
|
@@ -466,24 +539,110 @@ const getDateValue = (date) => ({
|
|
|
466
539
|
millisecond: date.getMilliseconds()
|
|
467
540
|
});
|
|
468
541
|
|
|
469
|
-
const isLongerThan = (value, minLength, includeEqual = false) => {
|
|
470
|
-
if (typeof value !== "string") return false;
|
|
471
|
-
|
|
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
|
+
}
|
|
472
584
|
};
|
|
473
585
|
|
|
474
|
-
const
|
|
475
|
-
|
|
476
|
-
return
|
|
586
|
+
const isInteger = (value, message) => {
|
|
587
|
+
const isValid = isSafeNumber(value) && Number.isInteger(value);
|
|
588
|
+
return isValid ? true : message || false;
|
|
477
589
|
};
|
|
478
590
|
|
|
479
|
-
const
|
|
480
|
-
|
|
481
|
-
return
|
|
591
|
+
const isEqual = (value, valueB, message) => {
|
|
592
|
+
const isValid = equalsJSON(value, valueB);
|
|
593
|
+
return isValid ? true : message || false;
|
|
482
594
|
};
|
|
483
595
|
|
|
484
|
-
const
|
|
596
|
+
const isTrue = (value, message) => {
|
|
597
|
+
const isValid = value === true;
|
|
598
|
+
return isValid ? true : message || false;
|
|
599
|
+
};
|
|
485
600
|
|
|
486
|
-
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
|
+
};
|
|
487
646
|
|
|
488
647
|
function preload(url, as = "image") {
|
|
489
648
|
const urls = Array.isArray(url) ? url : [url];
|
|
@@ -496,4 +655,4 @@ function preload(url, as = "image") {
|
|
|
496
655
|
});
|
|
497
656
|
}
|
|
498
657
|
|
|
499
|
-
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, isGreaterThan, isInteger, isLessThan, isLongerThan, isObject, isOneOf, isPathAccessor, isPhoneNumber, isRequired, isSafeNumber, isSafeNumeric, isShorterThan, isSlug, isString, 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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "defuss-runtime",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -20,13 +20,6 @@
|
|
|
20
20
|
"url": "git+https://github.com/kyr0/defuss.git",
|
|
21
21
|
"type": "git"
|
|
22
22
|
},
|
|
23
|
-
"scripts": {
|
|
24
|
-
"clean": "rm -rf ./node_modules/.pnpm",
|
|
25
|
-
"pretest": "pnpm run build",
|
|
26
|
-
"prebuild": "pnpm run clean",
|
|
27
|
-
"build": "pkgroll",
|
|
28
|
-
"test": "vitest --run --coverage"
|
|
29
|
-
},
|
|
30
23
|
"author": "Aron Homberg <info@aron-homberg.de>",
|
|
31
24
|
"sideEffects": false,
|
|
32
25
|
"exports": {
|
|
@@ -44,7 +37,9 @@
|
|
|
44
37
|
"main": "./dist/index.cjs",
|
|
45
38
|
"module": "./dist/index.mjs",
|
|
46
39
|
"types": "./dist/index.d.cts",
|
|
47
|
-
"files": [
|
|
40
|
+
"files": [
|
|
41
|
+
"dist"
|
|
42
|
+
],
|
|
48
43
|
"engines": {
|
|
49
44
|
"node": "^18.17.1 || ^20.3.0 || >=21.0.0"
|
|
50
45
|
},
|
|
@@ -54,5 +49,12 @@
|
|
|
54
49
|
"typescript": "^5.6.3",
|
|
55
50
|
"vitest": "^3.1.3",
|
|
56
51
|
"@vitest/coverage-v8": "^3.1.3"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"clean": "rm -rf ./node_modules/.pnpm",
|
|
55
|
+
"pretest": "pnpm run build",
|
|
56
|
+
"prebuild": "pnpm run clean",
|
|
57
|
+
"build": "pkgroll",
|
|
58
|
+
"test": "vitest --run --coverage"
|
|
57
59
|
}
|
|
58
|
-
}
|
|
60
|
+
}
|