Interface IsEqualOptions

Options interface for z.isEqual

interface IsEqualOptions {
    isEqual?: boolean;
    inherited?: boolean;
    exactValues?: boolean;
    exactKeys?: boolean;
    like?: boolean;
    path?: Any[];
    exclude?: Any[];
    unbox?: boolean;
    realObjectAsPojso?: boolean;
    customizer?: IsEqualCustomizerCallback;
    ctx?: any;
    strict?: boolean;
    props?: boolean | "all";
    string?: boolean;
    symbol?: boolean;
    own?: boolean;
    top?: boolean;
    hidden?: boolean;
    enumerables?: boolean;
    nonEnumerables?: boolean;
    dataViewType?: DataViewType;
}

Hierarchy (view full)

Properties

isEqual?: boolean

If true, it will use isEqual method of the objects (if they have one) for the ultimate decision of equality.

true
inherited?: boolean

If true, examine all (inherited) properties, not just own

false
exactValues?: boolean

If true, then all VALUES that are refs must point to the same objects (i.e strict === equality), not lookalike clones! It checks only root items, no reason to go deeper!

Effectively, it checks for a shallow clone, rather than a deep one (note: _.isEquals does deep only). You can have a clone oof the outer array/object/Set etc, but the values must be non-clones!

false
exactKeys?: boolean

If true, then all KEY refs must point to the same objects (i.e strict === equality), not lookalike clones!

It is like exact, but for KEYS:

  • the Set type has entries that are keys-only (i.e not values) and these can be object refs.
  • Similarly, Map has keys that can be objects/references.

The exactKeys options applies only to these keys, not to the values or object symbol props

Note: default behavior is adopted from lodash:

 _.isEqual(new Map([[{a:1}, 'one']]), new Map([[{a:1}, 'one'],])) // true
false
like?: boolean

If true, check only if all of the 1st arg's props are isEqual with the 2nd's, even if the 2nd arg has more properties.

For example, if a is {a: 1} and b is {a: 1, b: 2}, it will return true.

false
path?: Any[]

If you pass an array, it will become populated with the keys/indexes while objects/arrays are traversed. Useful for debugging (to see which prop path was the reason for non-equality)!

@todo: not working with ArrayBuffer & Error types

[]
exclude?: Any[]

If you pass an array of Tany, it will exclude those keys from the comparison.

@todo: if it is a Function, called with (key, val, ??), excludes key if true is returned (NOT IMPLEMENTED YET)

[]
unbox?: boolean

Allows unboxing of Boxed Primitives (eg new Number(1) & 1 are equal).

realObjectAsPojso?: boolean

If true, it will treat all objects as realObjects, even if they are not: Instances of any class & POJSOs are equal, if they have the same prop/values.

isEqual(new class(

@todo(213): what about different classes, but same values? What about inheritance? What should be allowed?

The customizer function can be optionally passed as an options property.

If undefined or if the function call returns undefined, comparisons are handled by z.isEqual.

The customizer can be the 3rd parameter (to maintain compatibility with lodash _.isEqualWith) and options can be the 5th, but you can pass customizer and ctx as properties of the options object being the 3rd arg. But if you pass them in both places, it throws an Error.

The customizer type is TisEqualcustomizer.

ctx?: any

The this binding (aka context) of customizer. If undefined, this is bound to the global object. If ctx is passed both as a property of the options object, an as the 4rth arg, it will throw.

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

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'