Function isMany

Returns true if the data type is a natural holder of other items, also known as a "collection" (eg Array, Object, Set, Map) but Many is also Iterator, Generator, arguments etc, hence the name isMany instead of isCollection.

It's also the opposite of z.isSingle() in terms of naturally/normally having compound or many items (eg props, array items etc) nested inside it.

As defined in MANY_NAMES, they are:

  • 'object'
  • 'Array'
  • 'Set'
  • 'Map'
  • 'class' // see notes
  • 'arguments'
  • 'Generator'
  • 'Iterator'
  • 'AsyncGenerator'
  • 'AsyncIterator'

Not iterable at all, they don't reveal their items, but they are still "many" types

  • 'WeakSet'
  • 'WeakMap'

class types makes sense to be categorised as "Many", because a class can have interesting static props.

Normal 'function' is not normally a "Many" type (many values holder), although in theory it can hold props. Same applies to Boxed primitives like String, Number etc, which represent a single value (not many), but they can have properties (very rare & bad practice though). You need to enforce this check in your code.

@note: On all of these "Many" types (except WeakSet/WeakMap which aren't revealing their items), you can use z.loop(value) to get an IterableIterator of [keyOrIdx, value] pairs, which works the same way for all of them.

It also has an option allProps that deals with props on all _.isObject values.

  • z.isSingle() is the opposite of isMany
  • z.isPrimitive() for the most basic single types
  • z.loop(value) to iterate on isMany() values (that makes sense).
  • MANY_NAMES for the string list of types that are considered "Many" types.
  • Many the types that are considered "Many".
  • isManyType to check if a type (not a value) is a "Many" type.