Returns true if the data type is a "single" or "plain" value, in terms of NOT naturally/normally having compound or "Many" items (eg props, array items etc) inside it that we can iterate over.
z.isSingle also includes extras as "singles" (eg Date & RegExp), as they are not considered as having arbitrary props or contents (days months minutes etc in Date don't count as user-defined props).
z.isSingle also includes boxed values of primitives (eg. new Boolean(true)), unlike z.isPrimitive() which only allows for really primitive unboxed values.
Think of it as lodash's negated_.isObject(), which unfortunately can't be used as such cause it fails in few cases:
For reference, isSingle(value) correctly recognises all of these value types:
'string',
'number',
'boolean',
'undefined',
'null',
'symbol',
'bigint',
// extra to `isPrimitive()`:
'Date',
'RegExp',
'function',
'Promise'
'NaN'
'Boolean',
'String',
'Number'
'Error'
// Special cases, as they might have many items internally, but practically they are not iterable, hence not "many" nor "single":
WeakSet
WeakMap
irrespective of how these values are created (literal/primitive or new Xxx).
Returns
true
if the data type is a "single" or "plain" value, in terms of NOT naturally/normally having compound or "Many" items (eg props, array items etc) inside it that we can iterate over.Aka and similar to Scalar or Primitive, but there are distinctions - see this answer https://stackoverflow.com/a/6628566/799502 for context.
See
z.isSingle
is similar toz.isPrimitive()
, but :z.isSingle
also includes extras as "singles" (egDate
&RegExp
), as they are not considered as having arbitrary props or contents (days months minutes etc in Date don't count as user-defined props).z.isSingle
also includes boxed values of primitives (eg.new Boolean(true)
), unlikez.isPrimitive()
which only allows for really primitive unboxed values.Think of it as lodash's negated
_.isObject()
, which unfortunately can't be used as such cause it fails in few cases:but
For reference,
isSingle(value)
correctly recognises all of these value types:irrespective of how these values are created (literal/primitive or new Xxx).
z.isMany()
is the opposite ofisSingle
z.isPrimitive()
for the most basic single typesSINGLE_NAMES
for the string list of types that are considered "Single" types.Single
the types that are considered "Single".isSingleType
to check if a type (not a value) is a "Single" type.