UNPKG

array-includes-polyfill

Version:

Exposing a richer set of Array features for JavaScript

111 lines (87 loc) 3.03 kB
"use strict"; var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Lookup = (function () { function Lookup() { _classCallCheck(this, Lookup); } _createClass(Lookup, [{ key: "lookup", value: function lookup(obj, withIndex) { var O = Object(this); var result = []; O.map(function (object, index) { if (_isFlat(object)) { if (_compareObjs(obj, object)) { if (withIndex) _define$$index(object, index); result.push(object); } } if (!_isFlat(object)) { var tempObj1 = _flattenObjs(object, withIndex, index); var tempObj2 = _flattenObjs(obj, withIndex, index); if (_compareObjs(tempObj2, tempObj1)) { _define$$index(object, index); result.push(object); } } }); var x = result; result = []; if (x.length === 1) x = x[0]; if (x === undefined || x === null || x == '') x = false; return x; } }]); return Lookup; })(); function _define$$index(object, index) { Object.defineProperty(object, "_$$index_", { enumerable: true, configurable: true, writable: false, value: index }); } function _compareObjs(obj1, obj2) { var validate = []; var keys = Object.keys(obj1); var state; keys.map(function (key) { if (obj1[key] === obj2[key]) validate.push(true); }); validate.length === keys.length ? state = true : state = false; return state; } var _flattend = {}; var _recursion = false; function _flattenObjs(object, withIndex, index) { if (!_recursion) _flattend = {}; var keys = Object.keys(object); keys.map(function (key) { if (!_isObject(object[key])) _flattend[key] = object[key]; if (_isObject(object[key])) { _recursion = true; _flattenObjs(object[key]); } }); _recursion = false; if (withIndex) _define$$index(_flattend, index); return _flattend; } function _isFlat(object) { var validate = []; if (object instanceof Object) { var keys = Object.keys(object); keys.map(function (key) { if (object[key] instanceof Object) validate.push(true); }); } if (validate.length > 0) return false; return true; } function _isObject(object) { if (object instanceof Object) return true; return false; } module.exports = Lookup;