Cascading predicates
Cascading predicate don't contribute to refining the value type, but are handful to assert that the value itself follows a particular pattern. You would compose them using cascade (cf the Examples section).
hasExactLength​
tsconstvalidate =t .hasExactLength (length );
tsconstvalidate =t .hasExactLength (length );
Ensure that the values all have a length property exactly equal to the specified value.
hasForbiddenKeys​
tsconstvalidate =t .hasForbiddenKeys ([forbiddenKey1 ,forbiddenKey2 , ...forbiddenKeyN ],options );
tsconstvalidate =t .hasForbiddenKeys ([forbiddenKey1 ,forbiddenKey2 , ...forbiddenKeyN ],options );
Ensure that the objects don't contain any of the specified keys. (cf hasMutuallyExclusiveKeys for the options parameter)
hasKeyRelationship​
tsconstvalidate =t .hasKeyRelationship (subjectKey ,relationship ,otherKeys , {ignore });
tsconstvalidate =t .hasKeyRelationship (subjectKey ,relationship ,otherKeys , {ignore });
Ensure that when the subject key is found, the specified relationship (one of t.KeyRelationship.Forbids or t.KeyRelationship.Requires) is true. Values listed in ignore will lead their properties to be considered missing for the purpose of this check.
hasMaxLength​
tsconstvalidate =t .hasMaxLength (length );
tsconstvalidate =t .hasMaxLength (length );
Ensure that the values all have a length property at most equal to the specified value.
hasMinLength​
tsconstvalidate =t .hasMinLength (length );
tsconstvalidate =t .hasMinLength (length );
Ensure that the values all have a length property at least equal to the specified value.
hasMutuallyExclusiveKeys​
tsconstvalidate =t .hasMutuallyExclusiveKeys (keys ,options );
tsconstvalidate =t .hasMutuallyExclusiveKeys (keys ,options );
Ensure that the objects don't contain more than one of the specified keys. Keys will be considered missing based on options.missingIf.
Options:
missingIf:missing(default): the key isn't present.undefined: the key isundefined.nil: the key is eitherundefinedornull.falsy: the key has a falsy value (ex:0,false,undefined,null)
hasRequiredKeys​
tsconstvalidate =t .hasRequiredKeys (keys ,options );
tsconstvalidate =t .hasRequiredKeys (keys ,options );
Ensure that the objects contain all of the specified keys. (cf hasMutuallyExclusiveKeys for the options parameter)
hasAtLeastOneKey​
tsconstvalidate =t .hasAtLeastOneKey (keys ,options );
tsconstvalidate =t .hasAtLeastOneKey (keys ,options );
Ensure that the objects contain at least one of the specified keys. (cf hasMutuallyExclusiveKeys for the options parameter)
hasUniqueItems​
tsconst validate = t.hasUniqueItems({map?});
tsconst validate = t.hasUniqueItems({map?});
Ensure that the values only have unique items (map will transform before comparing).
isAtLeast​
tsconst validate = t.isAtLeast(n);
tsconst validate = t.isAtLeast(n);
Ensure that the values compare positively with the specified value.
isAtMost​
tsconst validate = t.isAtMost(n);
tsconst validate = t.isAtMost(n);
Ensure that the values compare positively with the specified value.
isBase64​
tsconst validate = t.isBase64();
tsconst validate = t.isBase64();
Ensure that the values are valid base 64 data.
isHexColor​
tsconst validate = t.isHexColor({alpha?});
tsconst validate = t.isHexColor({alpha?});
Ensure that the values are hexadecimal colors (enabling alpha will allow an additional channel).
isInExclusiveRange​
tsconst validate = t.isInExclusiveRange(a, b);
tsconst validate = t.isInExclusiveRange(a, b);
Ensure that the values compare positively with the specified value.
isInInclusiveRange​
tsconst validate = t.isInInclusiveRange(a, b);
tsconst validate = t.isInInclusiveRange(a, b);
Ensure that the values compare positively with the specified value.
isInteger​
tsconst validate = t.isInteger(n, {unsafe?});
tsconst validate = t.isInteger(n, {unsafe?});
Ensure that the values are round safe integers (enabling unsafe will allow unsafe ones).
isJSON​
tsconst validate = t.isJSON(schema?);
tsconst validate = t.isJSON(schema?);
Ensure that the values are valid JSON, and optionally match them against a nested schema. Because it's a cascading predicate, it has no bearing on the type inference, and as a result doesn't support coercion. For a JSON predicate that supports coercion, check isPayload.
isLowerCase​
tsconst validate = t.isLowerCase();
tsconst validate = t.isLowerCase();
Ensure that the values only contain lowercase characters.
isNegative​
tsconst validate = t.isNegative();
tsconst validate = t.isNegative();
Ensure that the values are at most 0.
isPositive​
tsconst validate = t.isPositive();
tsconst validate = t.isPositive();
Ensure that the values are at least 0.
isISO8601​
tsconst validate = t.isISO8601();
tsconst validate = t.isISO8601();
Ensure that the values are dates following the ISO 8601 standard.
isUpperCase​
tsconst validate = t.isUpperCase();
tsconst validate = t.isUpperCase();
Ensure that the values only contain uppercase characters.
isUUID4​
tsconst validate = t.isUUID4();
tsconst validate = t.isUUID4();
Ensure that the values are valid UUID 4 strings.
matchesRegExp​
tsconst validate = t.matchesRegExp();
tsconst validate = t.matchesRegExp();
Ensure that the values all match the given regular expression.