validateListOfType

Resolves the list if all elements in it are of type specified in the "type" parameter. The type parameter should be a string available in the PrimitiveType enum:
  • Either insert PrimitiveTypes.UNDEFINED or "undefined"
  • or PrimitiveTypes.BOOLEAN or "boolean"
  • or PrimitiveTypes.NUMBER or "number"
  • or PrimitiveTypes.STRING or "string"
  • or PrimitiveTypes.BIG_INT or "bigint"
  • or PrimitiveTypes.SYMBOL or "symbol"
  • or PrimitiveTypes.OBJECT or "object".
  • If using PrimitiveTypes enum, make sure to import: import { PrimitiveTypes } from "puddy-m/lib/enums". Note that this function will not resolve if the type parameter is any string that is not pre-defined in the PrimitiveTypes menu. In this case, it will reject ObjectWithExistingKeyValidationError.
    Parameter ListReturnsRejection Errors
    • type: string || PrimitiveTypes
    • list: Array<*>
    • tuple: Array (optional)
    Promise<Array<*> || Array>
    Related FunctionsFunction Signature
    function validateListOfType(type, list[, tuple]): Promise<Array<*> || Array>
    1 2 3 4 5 import { validateListOfType } from "puddy-m/lib/validators/listValidators"; validateListOfType("boolean", [true, false]).then((booleanList) => console.log(booleanList) ); // print [ true, false ]
    1 2 3 4 5 6 import { validateListOfType } from "puddy-m/lib/validators/listValidators"; import { validateString } from "puddy-m/lib/validators"; validateListOfType("string", ["foo", "bar"], []) .then((tuple) => validateString("string", tuple)) .then((tuple) => console.log(tuple)); // print [ 'foo', 'bar'], 'string' ]
    1 2 3 4 5 6 7 8 9 10 11 12 13 import { validateListOfType } from "puddy-m/lib/validators/listValidators"; const run = async () => { try { const validatedListOfObjects = await validateListOfType("object", [{}, {}]); console.log(validatedListOfObjects); // [ {}, {} ] } catch (e) { console.log(e); } }; run();
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 import { validateListOfType } from "puddy-m/lib/validators/listValidators"; const run = async () => { try { const validatedListOfObjects = await validateListOfType("object", ["", {}]); console.log(validatedListOfObjects); } catch (e) { // Throws ListOfTypeValidationError console.log(e); } }; run();