foreach-prop
Version:
Array-like methods for objects
3 lines (2 loc) • 4.69 kB
JavaScript
var t,n;t=this,n=function(t){function n(t,n){(null==n||n>t.length)&&(n=t.length);for(var r=0,o=new Array(n);r<n;r++)o[r]=t[r];return o}function r(t){return function(){const n=arguments;return new TypeError(t.replace(/\$(\d+)/g,((t,r)=>`${n[+r]}`)))}}const o=r("expected $1 arguments, got $0."),e=r("$0 is not an object."),i=r("$0 is not a function."),c=r("$0 is not an array."),f={}.hasOwnProperty;function l(t){return!!t&&"object"==typeof t}var u=Array.isArray,a=Object.prototype.toString,s=u||function(t){return!!t&&"[object Array]"==a.call(t)},h=function(t){if(!t)return!1;var n=w.call(t);return"[object Function]"===n||"function"==typeof t&&"[object RegExp]"!==n||"undefined"!=typeof window&&(t===window.setTimeout||t===window.alert||t===window.confirm||t===window.prompt)},w=Object.prototype.toString;function y(t,n){if(!function(t){if(!t)return!1;if(s(t))return!0;if(h(t)||function(t){if(null==t)return!1;var n=Object(t);return n===n.window}(t))return!1;var n="length"in(t=Object(t))&&t.length;return!(1!==t.nodeType||!n)||0===n||"number"==typeof n&&n>0&&n-1 in t}(t)&&""!==t)throw new TypeError("".concat(t," can't be converted to array."));if(null==n&&(n=0),"number"!=typeof n||!Number.isFinite(n))throw new TypeError("".concat(n," is not a valid start point."));var r=t.length;n<0&&(n+=r);for(var o=Object(t),e=new Array(r-n),i=n;i<r;i++)i in o&&(e[i-n]=o[i]);return e}function p(t,n,r,o,e){if(!h(t))throw i(t);if(2===e)return o=>t.call(n,r[o],o);if(3===e){const e=o[2];return o=>t.call(n,r[o],o,e)}const c=y(o,2);return o=>t.call(n,r[o],o,...c)}function d(t,n,r,o,e){if(!h(t))throw i(t);if(3===e)return(o,e)=>t.call(n,e,r[o],o);if(4===e){const e=o[3];return(o,i)=>t.call(n,i,r[o],o,e)}const c=y(o,3);return(o,e)=>t.call(n,e,r[o],o,...c)}function g(t,n){const r=arguments.length;if(r<2)throw o(r,2);if(!l(t))throw e(t);for(const r in t)if(f.call(t,r)&&t[r]===n)return r;return null}t.create=function(t,r){if(!Array.isArray(t))throw c(t);const o={};for(var e,i=function(t,r){var o="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(o)return(o=o.call(t)).next.bind(o);if(Array.isArray(t)||(o=function(t,r){if(t){if("string"==typeof t)return n(t,r);var o=Object.prototype.toString.call(t).slice(8,-1);return"Object"===o&&t.constructor&&(o=t.constructor.name),"Map"===o||"Set"===o?Array.from(t):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?n(t,r):void 0}}(t))||r&&t&&"number"==typeof t.length){o&&(t=o);var e=0;return function(){return e>=t.length?{done:!0}:{done:!1,value:t[e++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(t);!(e=i()).done;)o[e.value]=r;return o},t.every=function(t,n){const r=arguments,i=r.length;if(i<2)throw o(i,2);if(!l(t))throw e(t);const c=p(n,this,t,r,i);for(const n in t)if(f.call(t,n)&&!c(n))return!1;return!0},t.fill=function(t,n){const r=arguments.length;if(r<2)throw o(r,2);if(!l(t))throw e(t);const i={};for(const r in t)f.call(t,r)&&(i[r]=n);return i},t.filter=function(t,n){const r=arguments,i=r.length;if(i<2)throw o(i,2);if(!l(t))throw e(t);const c=p(n,this,t,r,i),u={};for(const n in t)f.call(t,n)&&c(n)&&(u[n]=t[n]);return u},t.find=function(t,n){const r=arguments,i=r.length;if(i<2)throw o(i,2);if(!l(t))throw e(t);const c=p(n,this,t,r,i);for(const n in t)if(f.call(t,n)&&c(n))return t[n]},t.findKey=function(t,n){const r=arguments,i=r.length;if(i<2)throw o(i,2);if(!l(t))throw e(t);const c=p(n,this,t,r,i);for(const n in t)if(f.call(t,n)&&c(n))return n;return null},t.forEach=function(t,n){const r=arguments,i=r.length;if(i<2)throw o(i,2);if(!l(t))throw e(t);const c=p(n,this,t,r,i);for(const n in t)f.call(t,n)&&c(n)},t.includes=function(t,n){return null!==g(t,n)},t.keyOf=g,t.lastKeyOf=function(t,n){const r=arguments.length;if(r<2)throw o(r,2);if(!l(t))throw e(t);let i=null;for(const r in t)f.call(t,r)&&t[r]===n&&(i=r);return i},t.map=function(t,n){const r=arguments,i=r.length;if(i<2)throw o(i,2);if(!l(t))throw e(t);const c=p(n,this,t,r,i),u={};for(const n in t)f.call(t,n)&&(u[n]=c(n));return u},t.reduce=function(t,n,r){const i=arguments,c=i.length;if(c<2)throw o(c,2);if(!l(t))throw e(t);const u=d(n,this,t,i,c);let a=r;for(const n in t)f.call(t,n)&&(a=u(n,a));return a},t.some=function(t,n){const r=arguments,i=r.length;if(i<2)throw o(i,2);if(!l(t))throw e(t);const c=p(n,this,t,r,i);for(const n in t)if(f.call(t,n)&&c(n))return!0;return!1}},"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).eachProp={});
//# sourceMappingURL=each-prop.umd.min.js.map