is-kit 1.16.0 → 1.16.2
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 +1 -1
- package/dist/index.js +29 -13
- package/dist/index.mjs +29 -13
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -547,6 +547,15 @@ const everyKeyValueEntry = (entries, predicate) => {
|
|
|
547
547
|
for (const [key, value] of entries) if (!predicate(key, value)) return false;
|
|
548
548
|
return true;
|
|
549
549
|
};
|
|
550
|
+
const hasTupleValues = (values, predicates) => {
|
|
551
|
+
if (values.length !== predicates.length) return false;
|
|
552
|
+
for (let index = 0; index < predicates.length; index += 1) {
|
|
553
|
+
const predicate = predicates[index];
|
|
554
|
+
if (!predicate(values[index])) return false;
|
|
555
|
+
}
|
|
556
|
+
return true;
|
|
557
|
+
};
|
|
558
|
+
const hasOwnEnumerableEntries = (values, keyPredicate, valuePredicate) => everyIterableValue(Object.keys(values), (key) => keyPredicate(key) && valuePredicate(values[key]));
|
|
550
559
|
/**
|
|
551
560
|
* Checks whether every array element satisfies the provided predicate.
|
|
552
561
|
*
|
|
@@ -575,14 +584,7 @@ const everyBrandedArrayValue = (values, predicate) => {
|
|
|
575
584
|
* @param predicates Predicates aligned to each tuple index.
|
|
576
585
|
* @returns Whether lengths match and each index passes.
|
|
577
586
|
*/
|
|
578
|
-
const everyTupleValue = (values, predicates) =>
|
|
579
|
-
if (values.length !== predicates.length) return false;
|
|
580
|
-
for (let index = 0; index < predicates.length; index += 1) {
|
|
581
|
-
const predicate = predicates[index];
|
|
582
|
-
if (!predicate(values[index])) return false;
|
|
583
|
-
}
|
|
584
|
-
return true;
|
|
585
|
-
};
|
|
587
|
+
const everyTupleValue = (values, predicates) => hasTupleValues(values, predicates);
|
|
586
588
|
/**
|
|
587
589
|
* Checks whether every set value satisfies the provided predicate.
|
|
588
590
|
*
|
|
@@ -625,7 +627,7 @@ const everyBrandedMapEntry = (values, keyPredicate, valuePredicate) => everyKeyV
|
|
|
625
627
|
* @param valuePredicate Predicate applied to each corresponding value.
|
|
626
628
|
* @returns Whether all enumerable entries satisfy their predicates.
|
|
627
629
|
*/
|
|
628
|
-
const everyOwnEnumerableEntry = (values, keyPredicate, valuePredicate) =>
|
|
630
|
+
const everyOwnEnumerableEntry = (values, keyPredicate, valuePredicate) => hasOwnEnumerableEntries(values, keyPredicate, valuePredicate);
|
|
629
631
|
//#endregion
|
|
630
632
|
//#region src/core/combinators/array.ts
|
|
631
633
|
/**
|
|
@@ -826,7 +828,7 @@ function oneOfValues(...args) {
|
|
|
826
828
|
* @returns Predicate narrowing to a readonly record with guarded key/value types.
|
|
827
829
|
*/
|
|
828
830
|
function recordOf(keyFunction, valueFunction) {
|
|
829
|
-
return define((input) => isPlainObject(input) &&
|
|
831
|
+
return define((input) => isPlainObject(input) && hasOwnEnumerableEntries(input, keyFunction, valueFunction));
|
|
830
832
|
}
|
|
831
833
|
//#endregion
|
|
832
834
|
//#region src/core/combinators/set.ts
|
|
@@ -872,8 +874,22 @@ const assertValidSchemaKeys = (schema) => {
|
|
|
872
874
|
if (!hasOnlyEnumerableOwnStringKeys(schema) || hasInheritedStringKeys(schema)) throw new TypeError("struct schema fields must be own enumerable string keys");
|
|
873
875
|
};
|
|
874
876
|
const isOptionalSchemaField = define((field) => isObject(field) && field.optional === true && isFunction(field.guard));
|
|
875
|
-
const hasRequiredKeys = (obj, entries) =>
|
|
876
|
-
|
|
877
|
+
const hasRequiredKeys = (obj, entries) => {
|
|
878
|
+
for (const entry of entries) {
|
|
879
|
+
const key = entry[0];
|
|
880
|
+
const guard = entry[1];
|
|
881
|
+
if (!hasOwnPropertyKey(obj, key) || !guard(obj[key])) return false;
|
|
882
|
+
}
|
|
883
|
+
return true;
|
|
884
|
+
};
|
|
885
|
+
const hasValidOptionalKeys = (obj, entries) => {
|
|
886
|
+
for (const entry of entries) {
|
|
887
|
+
const key = entry[0];
|
|
888
|
+
const guard = entry[1];
|
|
889
|
+
if (hasOwnPropertyKey(obj, key) && !guard(obj[key])) return false;
|
|
890
|
+
}
|
|
891
|
+
return true;
|
|
892
|
+
};
|
|
877
893
|
const hasOnlyAllowedKeys = (obj, allowed) => Object.keys(obj).every((key) => allowed.has(key));
|
|
878
894
|
const hasOnlyRequiredKeys = (obj, schemaKeys, allowed) => {
|
|
879
895
|
const keys = Object.keys(obj);
|
|
@@ -964,7 +980,7 @@ function typedStruct() {
|
|
|
964
980
|
* @returns Predicate that narrows to a readonly tuple of guarded element types.
|
|
965
981
|
*/
|
|
966
982
|
function tupleOf(...guards) {
|
|
967
|
-
return define((input) => Array.isArray(input) &&
|
|
983
|
+
return define((input) => Array.isArray(input) && hasTupleValues(input, guards));
|
|
968
984
|
}
|
|
969
985
|
//#endregion
|
|
970
986
|
//#region src/utils/to-boolean-predicates.ts
|
package/dist/index.mjs
CHANGED
|
@@ -546,6 +546,15 @@ const everyKeyValueEntry = (entries, predicate) => {
|
|
|
546
546
|
for (const [key, value] of entries) if (!predicate(key, value)) return false;
|
|
547
547
|
return true;
|
|
548
548
|
};
|
|
549
|
+
const hasTupleValues = (values, predicates) => {
|
|
550
|
+
if (values.length !== predicates.length) return false;
|
|
551
|
+
for (let index = 0; index < predicates.length; index += 1) {
|
|
552
|
+
const predicate = predicates[index];
|
|
553
|
+
if (!predicate(values[index])) return false;
|
|
554
|
+
}
|
|
555
|
+
return true;
|
|
556
|
+
};
|
|
557
|
+
const hasOwnEnumerableEntries = (values, keyPredicate, valuePredicate) => everyIterableValue(Object.keys(values), (key) => keyPredicate(key) && valuePredicate(values[key]));
|
|
549
558
|
/**
|
|
550
559
|
* Checks whether every array element satisfies the provided predicate.
|
|
551
560
|
*
|
|
@@ -574,14 +583,7 @@ const everyBrandedArrayValue = (values, predicate) => {
|
|
|
574
583
|
* @param predicates Predicates aligned to each tuple index.
|
|
575
584
|
* @returns Whether lengths match and each index passes.
|
|
576
585
|
*/
|
|
577
|
-
const everyTupleValue = (values, predicates) =>
|
|
578
|
-
if (values.length !== predicates.length) return false;
|
|
579
|
-
for (let index = 0; index < predicates.length; index += 1) {
|
|
580
|
-
const predicate = predicates[index];
|
|
581
|
-
if (!predicate(values[index])) return false;
|
|
582
|
-
}
|
|
583
|
-
return true;
|
|
584
|
-
};
|
|
586
|
+
const everyTupleValue = (values, predicates) => hasTupleValues(values, predicates);
|
|
585
587
|
/**
|
|
586
588
|
* Checks whether every set value satisfies the provided predicate.
|
|
587
589
|
*
|
|
@@ -624,7 +626,7 @@ const everyBrandedMapEntry = (values, keyPredicate, valuePredicate) => everyKeyV
|
|
|
624
626
|
* @param valuePredicate Predicate applied to each corresponding value.
|
|
625
627
|
* @returns Whether all enumerable entries satisfy their predicates.
|
|
626
628
|
*/
|
|
627
|
-
const everyOwnEnumerableEntry = (values, keyPredicate, valuePredicate) =>
|
|
629
|
+
const everyOwnEnumerableEntry = (values, keyPredicate, valuePredicate) => hasOwnEnumerableEntries(values, keyPredicate, valuePredicate);
|
|
628
630
|
//#endregion
|
|
629
631
|
//#region src/core/combinators/array.ts
|
|
630
632
|
/**
|
|
@@ -825,7 +827,7 @@ function oneOfValues(...args) {
|
|
|
825
827
|
* @returns Predicate narrowing to a readonly record with guarded key/value types.
|
|
826
828
|
*/
|
|
827
829
|
function recordOf(keyFunction, valueFunction) {
|
|
828
|
-
return define((input) => isPlainObject(input) &&
|
|
830
|
+
return define((input) => isPlainObject(input) && hasOwnEnumerableEntries(input, keyFunction, valueFunction));
|
|
829
831
|
}
|
|
830
832
|
//#endregion
|
|
831
833
|
//#region src/core/combinators/set.ts
|
|
@@ -871,8 +873,22 @@ const assertValidSchemaKeys = (schema) => {
|
|
|
871
873
|
if (!hasOnlyEnumerableOwnStringKeys(schema) || hasInheritedStringKeys(schema)) throw new TypeError("struct schema fields must be own enumerable string keys");
|
|
872
874
|
};
|
|
873
875
|
const isOptionalSchemaField = define((field) => isObject(field) && field.optional === true && isFunction(field.guard));
|
|
874
|
-
const hasRequiredKeys = (obj, entries) =>
|
|
875
|
-
|
|
876
|
+
const hasRequiredKeys = (obj, entries) => {
|
|
877
|
+
for (const entry of entries) {
|
|
878
|
+
const key = entry[0];
|
|
879
|
+
const guard = entry[1];
|
|
880
|
+
if (!hasOwnPropertyKey(obj, key) || !guard(obj[key])) return false;
|
|
881
|
+
}
|
|
882
|
+
return true;
|
|
883
|
+
};
|
|
884
|
+
const hasValidOptionalKeys = (obj, entries) => {
|
|
885
|
+
for (const entry of entries) {
|
|
886
|
+
const key = entry[0];
|
|
887
|
+
const guard = entry[1];
|
|
888
|
+
if (hasOwnPropertyKey(obj, key) && !guard(obj[key])) return false;
|
|
889
|
+
}
|
|
890
|
+
return true;
|
|
891
|
+
};
|
|
876
892
|
const hasOnlyAllowedKeys = (obj, allowed) => Object.keys(obj).every((key) => allowed.has(key));
|
|
877
893
|
const hasOnlyRequiredKeys = (obj, schemaKeys, allowed) => {
|
|
878
894
|
const keys = Object.keys(obj);
|
|
@@ -963,7 +979,7 @@ function typedStruct() {
|
|
|
963
979
|
* @returns Predicate that narrows to a readonly tuple of guarded element types.
|
|
964
980
|
*/
|
|
965
981
|
function tupleOf(...guards) {
|
|
966
|
-
return define((input) => Array.isArray(input) &&
|
|
982
|
+
return define((input) => Array.isArray(input) && hasTupleValues(input, guards));
|
|
967
983
|
}
|
|
968
984
|
//#endregion
|
|
969
985
|
//#region src/utils/to-boolean-predicates.ts
|
package/package.json
CHANGED