UNPKG

filter-object

Version:

Filter an object by its keys or values. Returns a copy of an object filtered to have only keys or values that match the given glob patterns.

22 lines (16 loc) 436 B
'use strict'; var filterValues = require('filter-values'); var isObject = require('isobject'); var glob = require('glob-object'); module.exports = function(obj, patterns, options) { if (!isObject(obj)) { throw new TypeError('expected an object'); } if (!patterns) { return obj; } if (typeof patterns === 'function') { return filterValues(obj, patterns, options); } return glob(patterns, obj, options); };