arrayOfShape

arrayOfShape :: { k: Function } → [ a ] → Boolean

Takes an object of validators defining the possible shape of an object and returns a new function that reports whether the received array matches that shape for every of its elements.

import arrayOfShape form 'deep-waters/arrayOfShape';
import isString form 'deep-waters/isString';
import isNumber form 'deep-waters/isNumber';

const areValidUsers = arrayOfShape({
    name: isString,
    age: isNumber,
}); 

areValidUsers([
    { name: 'Topolino', age: 21 },
    { name: 'Paperino', age: 22 },
    { name: 'Pluto', age: 14 },
); // → true

areValidUsers([{ name: 'Topolino', age: 21 }, { foo: 'bar' }]); // → false

The created validator areValidUser only makes sure the received array has items matching the defined shape un-strictly, meaning it will return true even if one or more objects has additional properties.

arrayOfShape is actually a semantic shortcut to every.

arrayOfeveryhasShape

Last updated