Interface IKeysOptions

Options interface for z.keys

interface IKeysOptions {
    strict?: boolean;
    props?: boolean | "all";
    string?: boolean;
    symbol?: boolean;
    own?: boolean;
    inherited?: boolean;
    top?: boolean;
    hidden?: boolean;
    enumerables?: boolean;
    nonEnumerables?: boolean;
    dataViewType?: DataViewType;
}

Hierarchy (view full)

Properties

strict?: boolean

If true, keys() only allows values passing _.isObject() / (i.e non Primitives), throws otherwise.

Note: in loop() and map() and other projection functions, strict only allows isMany() types, but in keys() it is allowed for all Object types.

default: false

props?: boolean | "all"

If true, consider ONLY the props, instead of Nested Keys for special objects (Arrays, TypedArrays, Maps & Sets) - mimics Object.keys() / _.keys() if so.

By default, z.keys() returns the "natural keys" for special objects with nested values:

  • indexes for Array & TypedArray (eg [0, 1, 2, 3, ...])
  • the actual keys of Map & Set (eg ['someMapKey', {anObjectUsedAsKey: true}, Symbol('aSymbolKey')] instead of their Object props.

Similarly, all other functions like loop() & map() (that extend these options), iterate on those "natural keys" for all of these special objects.

For all other objects (including realObject, all Iterators & Generators, Boxed Primitives etc),

  • their string/symbol props are returned in keys()
  • are iterated on props on loop() and family, also depending on their other function-specific options.

If props: true then the keys() & iterations are only against props, even for special objects, instead of Nested Keys.

This only affects the special objects: it makes no difference to non-special values, if props is true/false, as their props are always considered anyway.

Note that Object.keys() always returns props for ALL objects (i.e props: true always), and there is no way to grab natural keys (or symbol props for that matter). This is a special feature of z.keys(), and much more useful: why would you want the props of Map or an Array anyway, 99% of the time? But if you subclassed Array or Map and want to get the props of that instance (instead of their natural keys), then you use props: true.

Finally, if props: 'all', you get both the props (first), followed by Nested Keys. Useful for print/debugging, comparisons etc.

@default: false / undefined

string?: boolean

Whether to include normal string props

@default: true

symbol?: boolean

Whether to include Symbol props, when we're dealing with a realObject or props: true

@default: false

own?: boolean

Whether to include own object props.

Note: It refers to props only, not Nested Keys, for arrays specifically. We include naturalKeys (i.e array Indexes) even when { own: false, props: 'all' }, to keep consistent with other Inspectable Nested Keys holders (Map & Set). But in realObjects, { own: false, props: any } will return no own props, as it should.

@default: true

inherited?: boolean

If true, it walks the prototype chain & retrieves all keys of inherited objects.

@default: false

top?: boolean

If true (and nonEnumerables is also true), it includes top-level (i.e Object) props like 'constructor', 'toString', 'valueOf', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString' etc.

It also retrieves these hidden props (that have no types definitions): `'defineGetter', 'defineSetter', lookupGetter_', 'lookupSetter', 'proto'.

@default: false

hidden?: boolean

If hidden: true (and nonEnumerables & top are also true), it includes top-level (i.e Object) hidden props like `'defineGetter', 'defineSetter', lookupGetter_', 'lookupSetter', 'proto'. Note that these are hidden props, thus have no TypeScript definitions.

Also, if hidden: true, it un-hides user/custom props that start & end with __, eg __myHiddenProp__ (which are hidden otherwise by default) @todo(363): filter user/custom __hidden__ props in KeysT/Values types in typescript

Note: hidden is a.k.a as private in the JS/TS world, but we use hidden to avoid confusion with the private keyword in TS and possible different semantics. Will revisit in future versions.

@default: false

enumerables?: boolean

Whether to include enumerable keys

true
nonEnumerables?: boolean

Whether to include enumerable keys

false
dataViewType?: DataViewType

When you loop() over an ArrayBuffer (or request keys() or values()), you must provide the dataViewType option (eg Int16, Float32 etc). The type of the items in the ArrayBuffer is required by the internal DataView that reads/writes to the ArrayBuffer.

Throws if dataViewType is missing and z.type(input) === 'ArrayBuffer'