UNPKG

find-and

Version:

Find nested objects and: appendProps / replaceObject / changeProps / removeObject / returnFound / insertObjectBefore / insertObjectAfter

33 lines (32 loc) 1.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Local helper function. * Returns true if the prototype for the `item` param solely comes from `Object`. * * @param item */ exports.isObject = function (item) { return !!item && Object.prototype.toString.call(item) === '[object Object]'; }; /** * Local helper function. * Returns true if the prototype for the `item` param solely comes from `Object`, and it has no keys. * * @param item */ exports.isEmpty = function (item) { return exports.isObject(item) && Object.keys(item).length === 0; }; /** * Local helper function. * Returns true if __all__ props of the given `predicate` exist and are equal to props of the given `source` item. * * @param sourceItem * @param predicate */ exports.checkAgainstPredicate = function (sourceItem, predicate) { return exports.isObject(sourceItem) && exports.isObject(predicate) && Object.keys(predicate).every(function (key) { return Object.prototype.hasOwnProperty.call(sourceItem, key) && predicate[key] === sourceItem[key]; }); };