validateNotType

It ensures that the argument is not of the type specified and returns arg if the type passed don't match. It's the opposite of the validateType function.
Parameter ListReturnsRejection Errors
  • type: string
  • arg: *
  • tuple: Array (optional)
Promise<* || Array>
Related FunctionsFunction Signature
function validateNotType(type, arg[, tuple]): Promise<* || Array>
1 2 3 import { validateNotType } from "puddy-m/lib/validators"; validateNotType("boolean", 35).then(console.log); // prints 35
1 2 3 4 5 import { validateNotType, validateString } from "puddy-m/lib/validators"; validateNotType("string", false, []) .then((tuple) => validateString("foo", tuple)) .then(console.log);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 import { validateNotType } from "puddy-m/lib/validators"; const run = async () => { try { const notOfTypeBoolean = await validateNotType("boolean", 5); console.log(notOfTypeBoolean); // prints 5 } catch (e) { console.log(e); } }; run();
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import { validateNotType } from "puddy-m/lib/validators"; const run = async () => { try { const notOfTypeBoolean = await validateNotType("boolean", false); console.log(notOfTypeBoolean); // since arg is a bollean, function will throw } catch (e) { // Throws NotTypeValidationError console.log(e); } }; run();