🌊
Deep Waters
  • What is Deep Waters
  • 📌Getting started
    • Installation
  • 🍰Composition
    • compose
    • when
    • or
    • not
  • 👁️ Validators
    • arrayOf
    • arrayOfShape
    • between
    • biggerThan
    • contains
    • equals
    • every
    • hasProp
    • hasShape
    • isCreditCard
      • isVISA
      • isMastercard
      • isAmericanExpress
      • isDinersClub
      • isDiscover
      • isJCB
    • isDateFormat [TD]
    • isDivisibleBy [TD]
    • isEmail [TD]
    • isEmpty [TD]
    • isEmptyString [TD]
    • isIP [TD]
      • isIPv6 [TD]
      • isIPv4 [TD]
    • isNumeric [TD]
    • isPhone [TD]
    • isPrimitive [TD]
    • isRequired [TD]
    • isURL [TD]
    • matchesPattern [TD]
    • maxLenght [TD]
    • minLength [TD]
    • ofLength [TD]
    • ofUniqueItems [TD]
    • ofClass
    • oneOfValues [TD]
    • smallerThan
  • ✅Type validators
    • isBigInt
    • isBoolean
    • isBuffer
    • isDate
    • isError
    • isFunction
    • isInt8Array
    • isMap
    • isNull
    • isNumber
    • isObject
    • isRegExp
    • isSet
    • isString
    • isSymbol
    • isUint8Array
    • isUndefined
    • isWeakMap
    • isWeakSet
  • github repository
Powered by GitBook
On this page

Was this helpful?

  1. 👁️ Validators

arrayOfShape

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

PreviousarrayOfNextbetween

Last updated 5 years ago

Was this helpful?

Takes an object of validators defining the possible 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 .

Related validators

shape
every
arrayOf
every
hasShape