@ts-scratcher/array
Version:
array extension methods for TypeScript
306 lines (245 loc) • 23.8 kB
JavaScript
/*
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
* This devtool is neither made for production nor for readable output files.
* It uses "eval()" calls to create a separate source file in the browser devtools.
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
* or disable the default devtool with "devtool: false".
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
*/
/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({
/***/ "./node_modules/@ts-scratcher/object/dist/index.js":
/*!*********************************************************!*\
!*** ./node_modules/@ts-scratcher/object/dist/index.js ***!
\*********************************************************/
/***/ (() => {
eval("/*\n * ATTENTION: The \"eval\" devtool has been used (maybe by default in mode: \"development\").\n * This devtool is neither made for production nor for readable output files.\n * It uses \"eval()\" calls to create a separate source file in the browser devtools.\n * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)\n * or disable the default devtool with \"devtool: false\".\n * If you are looking for production-ready output files, see mode: \"production\" (https://webpack.js.org/configuration/mode/).\n */\n/******/ (() => { // webpackBootstrap\n/******/ \t\"use strict\";\n/******/ \tvar __webpack_modules__ = ({\n\n/***/ \"./index.ts\":\n/*!******************!*\\\n !*** ./index.ts ***!\n \\******************/\n/***/ (() => {\n\neval(\"\\r\\nObject.isNullOrUndefined = (obj) => {\\r\\n if (obj == null)\\r\\n return true;\\r\\n if (obj === null)\\r\\n return true;\\r\\n if (typeof obj === \\\"undefined\\\")\\r\\n return true;\\r\\n return false;\\r\\n};\\r\\nObject.nameOf = (exp) => {\\r\\n // hack no supported es5\\r\\n return exp\\r\\n .toString()\\r\\n .split(\\\".\\\")\\r\\n .slice(1)\\r\\n .map((x) => x.replace(\\\"?\\\", \\\"\\\"))\\r\\n .join(\\\".\\\");\\r\\n};\\r\\nObject.getValue = (obj, exp) => {\\r\\n const path = Object.nameOf(exp);\\r\\n const arr = path.split(\\\".\\\");\\r\\n let result = obj;\\r\\n for (let i = 0; i < arr.length; i++) {\\r\\n if (Object.isNullOrUndefined(result)) {\\r\\n return result;\\r\\n }\\r\\n const path = arr[i];\\r\\n result = result[path];\\r\\n }\\r\\n return result;\\r\\n};\\r\\nObject.setValue = (obj, exp, value) => {\\r\\n const path = Object.nameOf(exp);\\r\\n const arr = path.split(\\\".\\\");\\r\\n let result = obj;\\r\\n for (let i = 0; i < arr.length; i++) {\\r\\n if (Object.isNullOrUndefined(result)) {\\r\\n return false;\\r\\n }\\r\\n const path = arr[i];\\r\\n if (i === arr.length - 1) {\\r\\n result[path] = value;\\r\\n }\\r\\n else {\\r\\n result = result[path];\\r\\n }\\r\\n }\\r\\n return true;\\r\\n};\\r\\n\\n\\n//# sourceURL=webpack://@ts-scratcher/object/./index.ts?\");\n\n/***/ })\n\n/******/ \t});\n/************************************************************************/\n/******/ \t\n/******/ \t// startup\n/******/ \t// Load entry module and return exports\n/******/ \t// This entry module can't be inlined because the eval devtool is used.\n/******/ \tvar __webpack_exports__ = {};\n/******/ \t__webpack_modules__[\"./index.ts\"]();\n/******/ \t\n/******/ })()\n;\n\n//# sourceURL=webpack://@ts-scratcher/array/./node_modules/@ts-scratcher/object/dist/index.js?");
/***/ }),
/***/ "./index.ts":
/*!******************!*\
!*** ./index.ts ***!
\******************/
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
"use strict";
eval("\r\n__webpack_require__(/*! ./src/where */ \"./src/where.ts\");\r\n__webpack_require__(/*! ./src/select */ \"./src/select.ts\");\r\n__webpack_require__(/*! ./src/selectMany */ \"./src/selectMany.ts\");\r\n__webpack_require__(/*! ./src/add */ \"./src/add.ts\");\r\n__webpack_require__(/*! ./src/any */ \"./src/any.ts\");\r\n__webpack_require__(/*! ./src/orderBy */ \"./src/orderBy.ts\");\r\n__webpack_require__(/*! ./src/firstOrDefault */ \"./src/firstOrDefault.ts\");\r\n__webpack_require__(/*! ./src/lastOrDefault */ \"./src/lastOrDefault.ts\");\r\n__webpack_require__(/*! ./src/groupBy */ \"./src/groupBy.ts\");\r\n__webpack_require__(/*! ./src/sequenceEqual */ \"./src/sequenceEqual.ts\");\r\n__webpack_require__(/*! ./src/sum */ \"./src/sum.ts\");\r\n__webpack_require__(/*! ./src/max */ \"./src/max.ts\");\r\n__webpack_require__(/*! ./src/min */ \"./src/min.ts\");\r\n__webpack_require__(/*! ./src/chunk */ \"./src/chunk.ts\");\r\n__webpack_require__(/*! ./src/indexValue */ \"./src/indexValue.ts\");\r\n__webpack_require__(/*! ./src/shuffle */ \"./src/shuffle.ts\");\r\n__webpack_require__(/*! ./src/next_previous */ \"./src/next_previous.ts\");\r\n__webpack_require__(/*! ./src/take */ \"./src/take.ts\");\r\n\n\n//# sourceURL=webpack://@ts-scratcher/array/./index.ts?");
/***/ }),
/***/ "./src/add.ts":
/*!********************!*\
!*** ./src/add.ts ***!
\********************/
/***/ (() => {
"use strict";
eval("\r\nObject.defineProperty(Array.prototype, \"add\", {\r\n configurable: true,\r\n enumerable: false,\r\n writable: true,\r\n value: function (item) {\r\n const newMe = [...this];\r\n newMe.push(item);\r\n return newMe;\r\n },\r\n});\r\nObject.defineProperty(Array.prototype, \"addRange\", {\r\n configurable: true,\r\n enumerable: false,\r\n writable: true,\r\n value: function (item) {\r\n const newMe = [...this];\r\n for (let i = 0; i < item.length; i++) {\r\n newMe.push(item[i]);\r\n }\r\n return newMe;\r\n },\r\n});\r\n\n\n//# sourceURL=webpack://@ts-scratcher/array/./src/add.ts?");
/***/ }),
/***/ "./src/any.ts":
/*!********************!*\
!*** ./src/any.ts ***!
\********************/
/***/ (() => {
"use strict";
eval("\r\nObject.defineProperty(Array.prototype, \"any\", {\r\n configurable: true,\r\n enumerable: false,\r\n writable: true,\r\n value: function (predicate) {\r\n if (!predicate) {\r\n return this.length !== 0;\r\n }\r\n return this.some((x) => predicate(x));\r\n },\r\n});\r\n\n\n//# sourceURL=webpack://@ts-scratcher/array/./src/any.ts?");
/***/ }),
/***/ "./src/chunk.ts":
/*!**********************!*\
!*** ./src/chunk.ts ***!
\**********************/
/***/ (() => {
"use strict";
eval("\r\nObject.defineProperty(Array.prototype, \"chunk\", {\r\n configurable: true,\r\n enumerable: false,\r\n writable: true,\r\n value: function (size) {\r\n if (!size) {\r\n size = 1;\r\n }\r\n return this.reduce((chunks, el, i) => {\r\n if (i % size === 0) {\r\n chunks.push([el]);\r\n }\r\n else {\r\n chunks[chunks.length - 1].push(el);\r\n }\r\n return chunks;\r\n }, []);\r\n },\r\n});\r\n\n\n//# sourceURL=webpack://@ts-scratcher/array/./src/chunk.ts?");
/***/ }),
/***/ "./src/firstOrDefault.ts":
/*!*******************************!*\
!*** ./src/firstOrDefault.ts ***!
\*******************************/
/***/ (() => {
"use strict";
eval("\r\nObject.defineProperty(Array.prototype, \"firstOrDefault\", {\r\n configurable: true,\r\n enumerable: false,\r\n writable: true,\r\n value: function (predicate) {\r\n let me = this;\r\n if (predicate) {\r\n me = me.filter((x) => predicate(x));\r\n }\r\n return 0 < me.length ? me[0] : null;\r\n },\r\n});\r\n\n\n//# sourceURL=webpack://@ts-scratcher/array/./src/firstOrDefault.ts?");
/***/ }),
/***/ "./src/groupBy.ts":
/*!************************!*\
!*** ./src/groupBy.ts ***!
\************************/
/***/ (() => {
"use strict";
eval("\r\nObject.defineProperty(Array.prototype, \"groupBy\", {\r\n configurable: true,\r\n enumerable: false,\r\n writable: true,\r\n value: function (selector) {\r\n const result = new Array();\r\n this.forEach((value, i) => {\r\n const groupKey = selector(value);\r\n if (!result.some((x) => x.Key === groupKey)) {\r\n result.push({ Key: groupKey, Values: new Array() });\r\n }\r\n const item = result.firstOrDefault((x) => x.Key === groupKey);\r\n item.Values.push(value);\r\n });\r\n return result;\r\n },\r\n});\r\n\n\n//# sourceURL=webpack://@ts-scratcher/array/./src/groupBy.ts?");
/***/ }),
/***/ "./src/indexValue.ts":
/*!***************************!*\
!*** ./src/indexValue.ts ***!
\***************************/
/***/ (() => {
"use strict";
eval("\r\nObject.defineProperty(Array.prototype, \"indexValue\", {\r\n configurable: true,\r\n enumerable: false,\r\n writable: true,\r\n value: function (predicate) {\r\n const error = { index: -1 };\r\n for (let index = 0; index < this.length; index++) {\r\n const element = this[index];\r\n if (predicate(element)) {\r\n return { index: index, value: element };\r\n }\r\n }\r\n return error;\r\n },\r\n});\r\n\n\n//# sourceURL=webpack://@ts-scratcher/array/./src/indexValue.ts?");
/***/ }),
/***/ "./src/lastOrDefault.ts":
/*!******************************!*\
!*** ./src/lastOrDefault.ts ***!
\******************************/
/***/ (() => {
"use strict";
eval("\r\nObject.defineProperty(Array.prototype, \"lastOrDefault\", {\r\n configurable: true,\r\n enumerable: false,\r\n writable: true,\r\n value: function (predicate) {\r\n let me = this;\r\n if (predicate) {\r\n me = me.filter((x) => predicate(x));\r\n }\r\n return 0 < me.length ? me[me.length - 1] : null;\r\n },\r\n});\r\n\n\n//# sourceURL=webpack://@ts-scratcher/array/./src/lastOrDefault.ts?");
/***/ }),
/***/ "./src/max.ts":
/*!********************!*\
!*** ./src/max.ts ***!
\********************/
/***/ (() => {
"use strict";
eval("\r\nObject.defineProperty(Array.prototype, \"max\", {\r\n configurable: true,\r\n enumerable: false,\r\n writable: true,\r\n value: function (selector) {\r\n let value = 0;\r\n this.forEach((x) => {\r\n if (selector) {\r\n const each = selector(x);\r\n if (value < each) {\r\n value = each;\r\n }\r\n }\r\n else {\r\n if (value < x) {\r\n value = x;\r\n }\r\n }\r\n });\r\n return value;\r\n },\r\n});\r\n\n\n//# sourceURL=webpack://@ts-scratcher/array/./src/max.ts?");
/***/ }),
/***/ "./src/min.ts":
/*!********************!*\
!*** ./src/min.ts ***!
\********************/
/***/ (() => {
"use strict";
eval("\r\nObject.defineProperty(Array.prototype, \"min\", {\r\n configurable: true,\r\n enumerable: false,\r\n writable: true,\r\n value: function (selector) {\r\n let value = 999999999;\r\n this.forEach((x) => {\r\n if (selector) {\r\n const each = selector(x);\r\n if (value > each) {\r\n value = each;\r\n }\r\n }\r\n else {\r\n if (value > x) {\r\n value = x;\r\n }\r\n }\r\n });\r\n return value;\r\n },\r\n});\r\n\n\n//# sourceURL=webpack://@ts-scratcher/array/./src/min.ts?");
/***/ }),
/***/ "./src/next_previous.ts":
/*!******************************!*\
!*** ./src/next_previous.ts ***!
\******************************/
/***/ (() => {
"use strict";
eval("\r\nObject.defineProperty(Array.prototype, \"next\", {\r\n configurable: true,\r\n enumerable: false,\r\n writable: true,\r\n value: function (current, recursive = true) {\r\n let { index } = this.indexValue((x) => JSON.stringify(x) === JSON.stringify(current));\r\n if (index === -1) {\r\n return null;\r\n }\r\n if (this.length <= ++index) {\r\n if (recursive) {\r\n index = 0;\r\n }\r\n else {\r\n return null;\r\n }\r\n }\r\n return this[index];\r\n },\r\n});\r\nObject.defineProperty(Array.prototype, \"previous\", {\r\n configurable: true,\r\n enumerable: false,\r\n writable: true,\r\n value: function (current, recursive = true) {\r\n let { index } = this.indexValue((x) => JSON.stringify(x) === JSON.stringify(current));\r\n if (index === -1) {\r\n return null;\r\n }\r\n if (--index < 0) {\r\n if (recursive) {\r\n index = this.length - 1;\r\n }\r\n else {\r\n return null;\r\n }\r\n }\r\n return this[index];\r\n },\r\n});\r\n\n\n//# sourceURL=webpack://@ts-scratcher/array/./src/next_previous.ts?");
/***/ }),
/***/ "./src/orderBy.ts":
/*!************************!*\
!*** ./src/orderBy.ts ***!
\************************/
/***/ (() => {
"use strict";
eval("\r\nObject.defineProperty(Array.prototype, \"orderBy\", {\r\n configurable: true,\r\n enumerable: false,\r\n writable: true,\r\n value: function (selector) {\r\n return this.sort((x, y) => {\r\n const xx = selector(x);\r\n const yy = selector(y);\r\n if (typeof xx === \"string\" && typeof yy === \"string\") {\r\n return yy === xx ? 0 : yy < xx ? 1 : -1;\r\n }\r\n return xx - yy;\r\n });\r\n },\r\n});\r\nObject.defineProperty(Array.prototype, \"orderByDescending\", {\r\n configurable: true,\r\n enumerable: false,\r\n writable: true,\r\n value: function (selector) {\r\n return this.orderBy(selector).reverse();\r\n },\r\n});\r\n\n\n//# sourceURL=webpack://@ts-scratcher/array/./src/orderBy.ts?");
/***/ }),
/***/ "./src/select.ts":
/*!***********************!*\
!*** ./src/select.ts ***!
\***********************/
/***/ (() => {
"use strict";
eval("\r\nObject.defineProperty(Array.prototype, \"select\", {\r\n configurable: true,\r\n enumerable: false,\r\n writable: true,\r\n value: function (selector) {\r\n return this.map(x => selector(x));\r\n },\r\n});\r\n\n\n//# sourceURL=webpack://@ts-scratcher/array/./src/select.ts?");
/***/ }),
/***/ "./src/selectMany.ts":
/*!***************************!*\
!*** ./src/selectMany.ts ***!
\***************************/
/***/ (() => {
"use strict";
eval("\r\nObject.defineProperty(Array.prototype, \"selectMany\", {\r\n configurable: true,\r\n enumerable: false,\r\n writable: true,\r\n value: function (select) {\r\n let newArray = new Array();\r\n this.forEach((x) => {\r\n const arr = select(x);\r\n if (arr) {\r\n newArray = [...newArray, ...arr];\r\n }\r\n });\r\n return newArray;\r\n },\r\n});\r\n\n\n//# sourceURL=webpack://@ts-scratcher/array/./src/selectMany.ts?");
/***/ }),
/***/ "./src/sequenceEqual.ts":
/*!******************************!*\
!*** ./src/sequenceEqual.ts ***!
\******************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
"use strict";
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _ts_scratcher_object__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @ts-scratcher/object */ \"./node_modules/@ts-scratcher/object/dist/index.js\");\n/* harmony import */ var _ts_scratcher_object__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_ts_scratcher_object__WEBPACK_IMPORTED_MODULE_0__);\n\r\nObject.defineProperty(Array.prototype, \"sequenceEqual\", {\r\n configurable: true,\r\n enumerable: false,\r\n writable: true,\r\n value: function (target, predicate) {\r\n if (Object.isNullOrUndefined(this) || Object.isNullOrUndefined(target)) {\r\n return false;\r\n }\r\n if (this.length !== target.length)\r\n return false;\r\n let result = true;\r\n for (let i = 0; i < this.length; i++) {\r\n const x = this[i];\r\n const y = target[i];\r\n if (predicate) {\r\n if (!predicate(x, y)) {\r\n result = false;\r\n break;\r\n }\r\n }\r\n else {\r\n if (x !== y) {\r\n result = false;\r\n break;\r\n }\r\n }\r\n }\r\n return result;\r\n },\r\n});\r\n\n\n//# sourceURL=webpack://@ts-scratcher/array/./src/sequenceEqual.ts?");
/***/ }),
/***/ "./src/shuffle.ts":
/*!************************!*\
!*** ./src/shuffle.ts ***!
\************************/
/***/ (() => {
"use strict";
eval("\r\nObject.defineProperty(Array.prototype, \"shuffle\", {\r\n configurable: true,\r\n enumerable: false,\r\n writable: true,\r\n value: function () {\r\n return this.sort(() => Math.random() - 0.5);\r\n },\r\n});\r\nObject.defineProperty(Array.prototype, \"shuffleSlice\", {\r\n configurable: true,\r\n enumerable: false,\r\n writable: true,\r\n value: function (length) {\r\n return this.shuffle().slice(0, length);\r\n },\r\n});\r\n\n\n//# sourceURL=webpack://@ts-scratcher/array/./src/shuffle.ts?");
/***/ }),
/***/ "./src/sum.ts":
/*!********************!*\
!*** ./src/sum.ts ***!
\********************/
/***/ (() => {
"use strict";
eval("\r\nObject.defineProperty(Array.prototype, \"sum\", {\r\n configurable: true,\r\n enumerable: false,\r\n writable: true,\r\n value: function (selector) {\r\n let value = 0;\r\n this.forEach((x) => {\r\n if (selector) {\r\n value += selector(x);\r\n }\r\n else {\r\n value += x;\r\n }\r\n });\r\n return value;\r\n },\r\n});\r\n\n\n//# sourceURL=webpack://@ts-scratcher/array/./src/sum.ts?");
/***/ }),
/***/ "./src/take.ts":
/*!*********************!*\
!*** ./src/take.ts ***!
\*********************/
/***/ (() => {
"use strict";
eval("\r\nObject.defineProperty(Array.prototype, \"take\", {\r\n configurable: true,\r\n enumerable: false,\r\n writable: true,\r\n value: function (count) {\r\n if (this.length < count)\r\n count = this.length;\r\n const newArray = [];\r\n for (let i = 0; i < count; i++) {\r\n newArray.push(this[i]);\r\n }\r\n return newArray;\r\n },\r\n});\r\n\n\n//# sourceURL=webpack://@ts-scratcher/array/./src/take.ts?");
/***/ }),
/***/ "./src/where.ts":
/*!**********************!*\
!*** ./src/where.ts ***!
\**********************/
/***/ (() => {
"use strict";
eval("\r\nObject.defineProperty(Array.prototype, \"where\", {\r\n configurable: true,\r\n enumerable: false,\r\n writable: true,\r\n value: function (predicate) {\r\n return this.filter((value) => predicate(value));\r\n },\r\n});\r\nObject.defineProperty(Array.prototype, \"whereNot\", {\r\n configurable: true,\r\n enumerable: false,\r\n writable: true,\r\n value: function (predicate) {\r\n return this.where((value) => !predicate(value));\r\n },\r\n});\r\nObject.defineProperty(Array.prototype, \"whereNull\", {\r\n configurable: true,\r\n enumerable: false,\r\n writable: true,\r\n value: function (selector) {\r\n function predicateNullValue(v, selector) {\r\n const p = Object.getValue(v, selector);\r\n return Object.isNullOrUndefined(p);\r\n }\r\n return this.where((value) => predicateNullValue(value, selector));\r\n },\r\n});\r\nObject.defineProperty(Array.prototype, \"whereNotNull\", {\r\n configurable: true,\r\n enumerable: false,\r\n writable: true,\r\n value: function (selector) {\r\n function predicateNullValue(v, selector) {\r\n const p = Object.getValue(v, selector);\r\n return Object.isNullOrUndefined(p);\r\n }\r\n return this.where((value) => !predicateNullValue(value, selector));\r\n },\r\n});\r\n\n\n//# sourceURL=webpack://@ts-scratcher/array/./src/where.ts?");
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/compat get default export */
/******/ (() => {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = (module) => {
/******/ var getter = module && module.__esModule ?
/******/ () => (module['default']) :
/******/ () => (module);
/******/ __webpack_require__.d(getter, { a: getter });
/******/ return getter;
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/************************************************************************/
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module can't be inlined because the eval devtool is used.
/******/ var __webpack_exports__ = __webpack_require__("./index.ts");
/******/
/******/ })()
;