validateArray

It resolves the supposedArray parameter if it is an array.
Parameter ListReturnsRejection Errors
  • supposedArray: Array<*>
  • tuple: Array (optional)
Promise<Array<*> || Array<Array<*>>>
Related FunctionsFunction Signature
function validateArray(supposedArray[, tuple]): Promise<Array<*> || Array<Array<*>>>
1 2 3 import { validatedArray } from "puddy-m/lib/validators"; validateArray([]).then((arr) => console.log(arr)); // []
1 2 3 4 5 import { validatedArray } from "puddy-m/lib/validators"; validateArray([1, 2, 3], []) .then((tuple) => validateString("string", tuple)) .then((tuple) => console.log(tuple)); // [[1,2,3], 'string']
1 2 3 4 5 6 7 8 9 10 11 12 13 import { validatedArray } from "puddy-m/lib/validators"; const run = async () => { try { const validatedArray = await validateArray([]); console.log(validatedArray); // prints [] } catch (e) { console.log(e); } }; run();
1 2 3 4 5 6 7 8 9 10 11 12 import { validatedArray } from "puddy-m/lib/validators"; const run = async () => { try { const validatedArray = await validateArray("This is not an array"); } catch (e) { //Throws ArrayValidationError console.log(e); } }; run();