MarkosKon / compare-object-field

A small library with a function that compares an object's field with a value and two others that use the previous to filter arrays of objects.
MIT License
1 stars 0 forks source link

Check if parameter is undefined in some operations #2

Open MarkosKon opened 5 years ago

MarkosKon commented 5 years ago

The operations that use match or includes need to check if the first parameter exists.

For example:

The includes operation at the moment is defined as:

const includes = (a, b) => a.includes(b);

In order to avoid runtime errors if a is undefined (usually a is the object property e.g product.name) it should be refactored to:

const includes = (a, b) => a && a.includes(b);
MarkosKon commented 5 years ago

We need the same for non strings, arrays. Maybe something like runtime typechecking?