The named parameters
Optionalcount?: numberChecks the v parameter function signature to ensure the appropriate number of parameters are specified.
The parameter to be checked.
Optionalshould_throw?: booleanWhether to throw instead of returning a value upon failure.
true if it meets the expectations, false otherwise.
// Check if data is an expected type
let is_expected = json_check_type({type: "string", data: some_data});
if (is_expected) {
// Do your processing
}
// Throw if not an expected type
json_check_type({type: "string", data: some_data, should_throw: true});
// Check complex data type
let is_expected = json_check_type({
type: Uint8Array,
data: some_data,
});
// Check callback function follows expectations of 2 parameters.
json_check_type({
type: "function",
data: some_callback,
count: 2,
should_throw: true,
});
Utility to check parameters of a function to ensure they are of an expected type.