assert-match
Version:
assert + matchers <3
49 lines (33 loc) • 1.3 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof2 = require('babel-runtime/helpers/typeof');
var _typeof3 = _interopRequireDefault(_typeof2);
exports.default = pickMatching;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function pickMatching(obj, obj2) {
if (!obj2 || (typeof obj2 === 'undefined' ? 'undefined' : (0, _typeof3.default)(obj2)) !== 'object') {
return obj;
}
if (!obj || (typeof obj === 'undefined' ? 'undefined' : (0, _typeof3.default)(obj)) !== 'object') {
return null;
}
return pickMatchingProps(obj, obj2);
}
function pickMatchingProps(obj, obj2) {
if (!obj || (typeof obj === 'undefined' ? 'undefined' : (0, _typeof3.default)(obj)) !== 'object' || !obj2 || (typeof obj2 === 'undefined' ? 'undefined' : (0, _typeof3.default)(obj2)) !== 'object') {
return obj;
}
var result = {};
if (Array.isArray(obj)) {
result = [];
}
for (var key in obj2) {
if (Object.prototype.hasOwnProperty.call(obj2, key) && Object.prototype.hasOwnProperty.call(obj, key)) {
result[key] = pickMatchingProps(obj[key], obj2[key]);
}
}
return result;
}
module.exports = exports['default'];
;