abp-utils.umd.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('just-compare')) :
  3. typeof define === 'function' && define.amd ? define('@abp/utils', ['exports', 'just-compare'], factory) :
  4. (global = global || self, factory((global.abp = global.abp || {}, global.abp.utils = global.abp.utils || {}, global.abp.utils.common = {}), global.compare));
  5. }(this, (function (exports, compare) { 'use strict';
  6. compare = compare && Object.prototype.hasOwnProperty.call(compare, 'default') ? compare['default'] : compare;
  7. /*! *****************************************************************************
  8. Copyright (c) Microsoft Corporation.
  9. Permission to use, copy, modify, and/or distribute this software for any
  10. purpose with or without fee is hereby granted.
  11. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  12. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  13. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  14. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  15. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  16. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. PERFORMANCE OF THIS SOFTWARE.
  18. ***************************************************************************** */
  19. /* global Reflect, Promise */
  20. var extendStatics = function (d, b) {
  21. extendStatics = Object.setPrototypeOf ||
  22. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  23. function (d, b) { for (var p in b)
  24. if (b.hasOwnProperty(p))
  25. d[p] = b[p]; };
  26. return extendStatics(d, b);
  27. };
  28. function __extends(d, b) {
  29. extendStatics(d, b);
  30. function __() { this.constructor = d; }
  31. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  32. }
  33. var __assign = function () {
  34. __assign = Object.assign || function __assign(t) {
  35. for (var s, i = 1, n = arguments.length; i < n; i++) {
  36. s = arguments[i];
  37. for (var p in s)
  38. if (Object.prototype.hasOwnProperty.call(s, p))
  39. t[p] = s[p];
  40. }
  41. return t;
  42. };
  43. return __assign.apply(this, arguments);
  44. };
  45. function __rest(s, e) {
  46. var t = {};
  47. for (var p in s)
  48. if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  49. t[p] = s[p];
  50. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  51. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  52. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  53. t[p[i]] = s[p[i]];
  54. }
  55. return t;
  56. }
  57. function __decorate(decorators, target, key, desc) {
  58. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  59. if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
  60. r = Reflect.decorate(decorators, target, key, desc);
  61. else
  62. for (var i = decorators.length - 1; i >= 0; i--)
  63. if (d = decorators[i])
  64. r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  65. return c > 3 && r && Object.defineProperty(target, key, r), r;
  66. }
  67. function __param(paramIndex, decorator) {
  68. return function (target, key) { decorator(target, key, paramIndex); };
  69. }
  70. function __metadata(metadataKey, metadataValue) {
  71. if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
  72. return Reflect.metadata(metadataKey, metadataValue);
  73. }
  74. function __awaiter(thisArg, _arguments, P, generator) {
  75. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  76. return new (P || (P = Promise))(function (resolve, reject) {
  77. function fulfilled(value) { try {
  78. step(generator.next(value));
  79. }
  80. catch (e) {
  81. reject(e);
  82. } }
  83. function rejected(value) { try {
  84. step(generator["throw"](value));
  85. }
  86. catch (e) {
  87. reject(e);
  88. } }
  89. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  90. step((generator = generator.apply(thisArg, _arguments || [])).next());
  91. });
  92. }
  93. function __generator(thisArg, body) {
  94. var _ = { label: 0, sent: function () { if (t[0] & 1)
  95. throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  96. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
  97. function verb(n) { return function (v) { return step([n, v]); }; }
  98. function step(op) {
  99. if (f)
  100. throw new TypeError("Generator is already executing.");
  101. while (_)
  102. try {
  103. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
  104. return t;
  105. if (y = 0, t)
  106. op = [op[0] & 2, t.value];
  107. switch (op[0]) {
  108. case 0:
  109. case 1:
  110. t = op;
  111. break;
  112. case 4:
  113. _.label++;
  114. return { value: op[1], done: false };
  115. case 5:
  116. _.label++;
  117. y = op[1];
  118. op = [0];
  119. continue;
  120. case 7:
  121. op = _.ops.pop();
  122. _.trys.pop();
  123. continue;
  124. default:
  125. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
  126. _ = 0;
  127. continue;
  128. }
  129. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
  130. _.label = op[1];
  131. break;
  132. }
  133. if (op[0] === 6 && _.label < t[1]) {
  134. _.label = t[1];
  135. t = op;
  136. break;
  137. }
  138. if (t && _.label < t[2]) {
  139. _.label = t[2];
  140. _.ops.push(op);
  141. break;
  142. }
  143. if (t[2])
  144. _.ops.pop();
  145. _.trys.pop();
  146. continue;
  147. }
  148. op = body.call(thisArg, _);
  149. }
  150. catch (e) {
  151. op = [6, e];
  152. y = 0;
  153. }
  154. finally {
  155. f = t = 0;
  156. }
  157. if (op[0] & 5)
  158. throw op[1];
  159. return { value: op[0] ? op[1] : void 0, done: true };
  160. }
  161. }
  162. var __createBinding = Object.create ? (function (o, m, k, k2) {
  163. if (k2 === undefined)
  164. k2 = k;
  165. Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
  166. }) : (function (o, m, k, k2) {
  167. if (k2 === undefined)
  168. k2 = k;
  169. o[k2] = m[k];
  170. });
  171. function __exportStar(m, exports) {
  172. for (var p in m)
  173. if (p !== "default" && !exports.hasOwnProperty(p))
  174. __createBinding(exports, m, p);
  175. }
  176. function __values(o) {
  177. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  178. if (m)
  179. return m.call(o);
  180. if (o && typeof o.length === "number")
  181. return {
  182. next: function () {
  183. if (o && i >= o.length)
  184. o = void 0;
  185. return { value: o && o[i++], done: !o };
  186. }
  187. };
  188. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  189. }
  190. function __read(o, n) {
  191. var m = typeof Symbol === "function" && o[Symbol.iterator];
  192. if (!m)
  193. return o;
  194. var i = m.call(o), r, ar = [], e;
  195. try {
  196. while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
  197. ar.push(r.value);
  198. }
  199. catch (error) {
  200. e = { error: error };
  201. }
  202. finally {
  203. try {
  204. if (r && !r.done && (m = i["return"]))
  205. m.call(i);
  206. }
  207. finally {
  208. if (e)
  209. throw e.error;
  210. }
  211. }
  212. return ar;
  213. }
  214. function __spread() {
  215. for (var ar = [], i = 0; i < arguments.length; i++)
  216. ar = ar.concat(__read(arguments[i]));
  217. return ar;
  218. }
  219. function __spreadArrays() {
  220. for (var s = 0, i = 0, il = arguments.length; i < il; i++)
  221. s += arguments[i].length;
  222. for (var r = Array(s), k = 0, i = 0; i < il; i++)
  223. for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
  224. r[k] = a[j];
  225. return r;
  226. }
  227. ;
  228. function __await(v) {
  229. return this instanceof __await ? (this.v = v, this) : new __await(v);
  230. }
  231. function __asyncGenerator(thisArg, _arguments, generator) {
  232. if (!Symbol.asyncIterator)
  233. throw new TypeError("Symbol.asyncIterator is not defined.");
  234. var g = generator.apply(thisArg, _arguments || []), i, q = [];
  235. return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
  236. function verb(n) { if (g[n])
  237. i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
  238. function resume(n, v) { try {
  239. step(g[n](v));
  240. }
  241. catch (e) {
  242. settle(q[0][3], e);
  243. } }
  244. function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
  245. function fulfill(value) { resume("next", value); }
  246. function reject(value) { resume("throw", value); }
  247. function settle(f, v) { if (f(v), q.shift(), q.length)
  248. resume(q[0][0], q[0][1]); }
  249. }
  250. function __asyncDelegator(o) {
  251. var i, p;
  252. return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
  253. function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
  254. }
  255. function __asyncValues(o) {
  256. if (!Symbol.asyncIterator)
  257. throw new TypeError("Symbol.asyncIterator is not defined.");
  258. var m = o[Symbol.asyncIterator], i;
  259. return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
  260. function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
  261. function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
  262. }
  263. function __makeTemplateObject(cooked, raw) {
  264. if (Object.defineProperty) {
  265. Object.defineProperty(cooked, "raw", { value: raw });
  266. }
  267. else {
  268. cooked.raw = raw;
  269. }
  270. return cooked;
  271. }
  272. ;
  273. var __setModuleDefault = Object.create ? (function (o, v) {
  274. Object.defineProperty(o, "default", { enumerable: true, value: v });
  275. }) : function (o, v) {
  276. o["default"] = v;
  277. };
  278. function __importStar(mod) {
  279. if (mod && mod.__esModule)
  280. return mod;
  281. var result = {};
  282. if (mod != null)
  283. for (var k in mod)
  284. if (Object.hasOwnProperty.call(mod, k))
  285. __createBinding(result, mod, k);
  286. __setModuleDefault(result, mod);
  287. return result;
  288. }
  289. function __importDefault(mod) {
  290. return (mod && mod.__esModule) ? mod : { default: mod };
  291. }
  292. function __classPrivateFieldGet(receiver, privateMap) {
  293. if (!privateMap.has(receiver)) {
  294. throw new TypeError("attempted to get private field on non-instance");
  295. }
  296. return privateMap.get(receiver);
  297. }
  298. function __classPrivateFieldSet(receiver, privateMap, value) {
  299. if (!privateMap.has(receiver)) {
  300. throw new TypeError("attempted to set private field on non-instance");
  301. }
  302. privateMap.set(receiver, value);
  303. return value;
  304. }
  305. var ListNode = /** @class */ (function () {
  306. function ListNode(value) {
  307. this.value = value;
  308. }
  309. return ListNode;
  310. }());
  311. var LinkedList = /** @class */ (function () {
  312. function LinkedList() {
  313. this.size = 0;
  314. }
  315. Object.defineProperty(LinkedList.prototype, "head", {
  316. get: function () {
  317. return this.first;
  318. },
  319. enumerable: false,
  320. configurable: true
  321. });
  322. Object.defineProperty(LinkedList.prototype, "tail", {
  323. get: function () {
  324. return this.last;
  325. },
  326. enumerable: false,
  327. configurable: true
  328. });
  329. Object.defineProperty(LinkedList.prototype, "length", {
  330. get: function () {
  331. return this.size;
  332. },
  333. enumerable: false,
  334. configurable: true
  335. });
  336. LinkedList.prototype.attach = function (value, previousNode, nextNode) {
  337. if (!previousNode)
  338. return this.addHead(value);
  339. if (!nextNode)
  340. return this.addTail(value);
  341. var node = new ListNode(value);
  342. node.previous = previousNode;
  343. previousNode.next = node;
  344. node.next = nextNode;
  345. nextNode.previous = node;
  346. this.size++;
  347. return node;
  348. };
  349. LinkedList.prototype.attachMany = function (values, previousNode, nextNode) {
  350. if (!values.length)
  351. return [];
  352. if (!previousNode)
  353. return this.addManyHead(values);
  354. if (!nextNode)
  355. return this.addManyTail(values);
  356. var list = new LinkedList();
  357. list.addManyTail(values);
  358. list.first.previous = previousNode;
  359. previousNode.next = list.first;
  360. list.last.next = nextNode;
  361. nextNode.previous = list.last;
  362. this.size += values.length;
  363. return list.toNodeArray();
  364. };
  365. LinkedList.prototype.detach = function (node) {
  366. if (!node.previous)
  367. return this.dropHead();
  368. if (!node.next)
  369. return this.dropTail();
  370. node.previous.next = node.next;
  371. node.next.previous = node.previous;
  372. this.size--;
  373. return node;
  374. };
  375. LinkedList.prototype.add = function (value) {
  376. var _this = this;
  377. return {
  378. after: function () {
  379. var _a;
  380. var params = [];
  381. for (var _i = 0; _i < arguments.length; _i++) {
  382. params[_i] = arguments[_i];
  383. }
  384. return (_a = _this.addAfter).call.apply(_a, __spread([_this, value], params));
  385. },
  386. before: function () {
  387. var _a;
  388. var params = [];
  389. for (var _i = 0; _i < arguments.length; _i++) {
  390. params[_i] = arguments[_i];
  391. }
  392. return (_a = _this.addBefore).call.apply(_a, __spread([_this, value], params));
  393. },
  394. byIndex: function (position) { return _this.addByIndex(value, position); },
  395. head: function () { return _this.addHead(value); },
  396. tail: function () { return _this.addTail(value); },
  397. };
  398. };
  399. LinkedList.prototype.addMany = function (values) {
  400. var _this = this;
  401. return {
  402. after: function () {
  403. var _a;
  404. var params = [];
  405. for (var _i = 0; _i < arguments.length; _i++) {
  406. params[_i] = arguments[_i];
  407. }
  408. return (_a = _this.addManyAfter).call.apply(_a, __spread([_this, values], params));
  409. },
  410. before: function () {
  411. var _a;
  412. var params = [];
  413. for (var _i = 0; _i < arguments.length; _i++) {
  414. params[_i] = arguments[_i];
  415. }
  416. return (_a = _this.addManyBefore).call.apply(_a, __spread([_this, values], params));
  417. },
  418. byIndex: function (position) { return _this.addManyByIndex(values, position); },
  419. head: function () { return _this.addManyHead(values); },
  420. tail: function () { return _this.addManyTail(values); },
  421. };
  422. };
  423. LinkedList.prototype.addAfter = function (value, previousValue, compareFn) {
  424. if (compareFn === void 0) { compareFn = compare; }
  425. var previous = this.find(function (node) { return compareFn(node.value, previousValue); });
  426. return previous ? this.attach(value, previous, previous.next) : this.addTail(value);
  427. };
  428. LinkedList.prototype.addBefore = function (value, nextValue, compareFn) {
  429. if (compareFn === void 0) { compareFn = compare; }
  430. var next = this.find(function (node) { return compareFn(node.value, nextValue); });
  431. return next ? this.attach(value, next.previous, next) : this.addHead(value);
  432. };
  433. LinkedList.prototype.addByIndex = function (value, position) {
  434. if (position < 0)
  435. position += this.size;
  436. else if (position >= this.size)
  437. return this.addTail(value);
  438. if (position <= 0)
  439. return this.addHead(value);
  440. var next = this.get(position);
  441. return this.attach(value, next.previous, next);
  442. };
  443. LinkedList.prototype.addHead = function (value) {
  444. var node = new ListNode(value);
  445. node.next = this.first;
  446. if (this.first)
  447. this.first.previous = node;
  448. else
  449. this.last = node;
  450. this.first = node;
  451. this.size++;
  452. return node;
  453. };
  454. LinkedList.prototype.addTail = function (value) {
  455. var node = new ListNode(value);
  456. if (this.first) {
  457. node.previous = this.last;
  458. this.last.next = node;
  459. this.last = node;
  460. }
  461. else {
  462. this.first = node;
  463. this.last = node;
  464. }
  465. this.size++;
  466. return node;
  467. };
  468. LinkedList.prototype.addManyAfter = function (values, previousValue, compareFn) {
  469. if (compareFn === void 0) { compareFn = compare; }
  470. var previous = this.find(function (node) { return compareFn(node.value, previousValue); });
  471. return previous ? this.attachMany(values, previous, previous.next) : this.addManyTail(values);
  472. };
  473. LinkedList.prototype.addManyBefore = function (values, nextValue, compareFn) {
  474. if (compareFn === void 0) { compareFn = compare; }
  475. var next = this.find(function (node) { return compareFn(node.value, nextValue); });
  476. return next ? this.attachMany(values, next.previous, next) : this.addManyHead(values);
  477. };
  478. LinkedList.prototype.addManyByIndex = function (values, position) {
  479. if (position < 0)
  480. position += this.size;
  481. if (position <= 0)
  482. return this.addManyHead(values);
  483. if (position >= this.size)
  484. return this.addManyTail(values);
  485. var next = this.get(position);
  486. return this.attachMany(values, next.previous, next);
  487. };
  488. LinkedList.prototype.addManyHead = function (values) {
  489. var _this = this;
  490. return values.reduceRight(function (nodes, value) {
  491. nodes.unshift(_this.addHead(value));
  492. return nodes;
  493. }, []);
  494. };
  495. LinkedList.prototype.addManyTail = function (values) {
  496. var _this = this;
  497. return values.map(function (value) { return _this.addTail(value); });
  498. };
  499. LinkedList.prototype.drop = function () {
  500. var _this = this;
  501. return {
  502. byIndex: function (position) { return _this.dropByIndex(position); },
  503. byValue: function () {
  504. var params = [];
  505. for (var _i = 0; _i < arguments.length; _i++) {
  506. params[_i] = arguments[_i];
  507. }
  508. return _this.dropByValue.apply(_this, params);
  509. },
  510. byValueAll: function () {
  511. var params = [];
  512. for (var _i = 0; _i < arguments.length; _i++) {
  513. params[_i] = arguments[_i];
  514. }
  515. return _this.dropByValueAll.apply(_this, params);
  516. },
  517. head: function () { return _this.dropHead(); },
  518. tail: function () { return _this.dropTail(); },
  519. };
  520. };
  521. LinkedList.prototype.dropMany = function (count) {
  522. var _this = this;
  523. return {
  524. byIndex: function (position) { return _this.dropManyByIndex(count, position); },
  525. head: function () { return _this.dropManyHead(count); },
  526. tail: function () { return _this.dropManyTail(count); },
  527. };
  528. };
  529. LinkedList.prototype.dropByIndex = function (position) {
  530. if (position < 0)
  531. position += this.size;
  532. var current = this.get(position);
  533. return current ? this.detach(current) : undefined;
  534. };
  535. LinkedList.prototype.dropByValue = function (value, compareFn) {
  536. if (compareFn === void 0) { compareFn = compare; }
  537. var position = this.findIndex(function (node) { return compareFn(node.value, value); });
  538. return position < 0 ? undefined : this.dropByIndex(position);
  539. };
  540. LinkedList.prototype.dropByValueAll = function (value, compareFn) {
  541. if (compareFn === void 0) { compareFn = compare; }
  542. var dropped = [];
  543. for (var current = this.first, position = 0; current; position++, current = current.next) {
  544. if (compareFn(current.value, value)) {
  545. dropped.push(this.dropByIndex(position - dropped.length));
  546. }
  547. }
  548. return dropped;
  549. };
  550. LinkedList.prototype.dropHead = function () {
  551. var head = this.first;
  552. if (head) {
  553. this.first = head.next;
  554. if (this.first)
  555. this.first.previous = undefined;
  556. else
  557. this.last = undefined;
  558. this.size--;
  559. return head;
  560. }
  561. return undefined;
  562. };
  563. LinkedList.prototype.dropTail = function () {
  564. var tail = this.last;
  565. if (tail) {
  566. this.last = tail.previous;
  567. if (this.last)
  568. this.last.next = undefined;
  569. else
  570. this.first = undefined;
  571. this.size--;
  572. return tail;
  573. }
  574. return undefined;
  575. };
  576. LinkedList.prototype.dropManyByIndex = function (count, position) {
  577. if (count <= 0)
  578. return [];
  579. if (position < 0)
  580. position = Math.max(position + this.size, 0);
  581. else if (position >= this.size)
  582. return [];
  583. count = Math.min(count, this.size - position);
  584. var dropped = [];
  585. while (count--) {
  586. var current = this.get(position);
  587. dropped.push(this.detach(current));
  588. }
  589. return dropped;
  590. };
  591. LinkedList.prototype.dropManyHead = function (count) {
  592. if (count <= 0)
  593. return [];
  594. count = Math.min(count, this.size);
  595. var dropped = [];
  596. while (count--)
  597. dropped.unshift(this.dropHead());
  598. return dropped;
  599. };
  600. LinkedList.prototype.dropManyTail = function (count) {
  601. if (count <= 0)
  602. return [];
  603. count = Math.min(count, this.size);
  604. var dropped = [];
  605. while (count--)
  606. dropped.push(this.dropTail());
  607. return dropped;
  608. };
  609. LinkedList.prototype.find = function (predicate) {
  610. for (var current = this.first, position = 0; current; position++, current = current.next) {
  611. if (predicate(current, position, this))
  612. return current;
  613. }
  614. return undefined;
  615. };
  616. LinkedList.prototype.findIndex = function (predicate) {
  617. for (var current = this.first, position = 0; current; position++, current = current.next) {
  618. if (predicate(current, position, this))
  619. return position;
  620. }
  621. return -1;
  622. };
  623. LinkedList.prototype.forEach = function (iteratorFn) {
  624. for (var node = this.first, position = 0; node; position++, node = node.next) {
  625. iteratorFn(node, position, this);
  626. }
  627. };
  628. LinkedList.prototype.get = function (position) {
  629. return this.find(function (_, index) { return position === index; });
  630. };
  631. LinkedList.prototype.indexOf = function (value, compareFn) {
  632. if (compareFn === void 0) { compareFn = compare; }
  633. return this.findIndex(function (node) { return compareFn(node.value, value); });
  634. };
  635. LinkedList.prototype.toArray = function () {
  636. var array = new Array(this.size);
  637. this.forEach(function (node, index) { return (array[index] = node.value); });
  638. return array;
  639. };
  640. LinkedList.prototype.toNodeArray = function () {
  641. var array = new Array(this.size);
  642. this.forEach(function (node, index) { return (array[index] = node); });
  643. return array;
  644. };
  645. LinkedList.prototype.toString = function (mapperFn) {
  646. if (mapperFn === void 0) { mapperFn = JSON.stringify; }
  647. return this.toArray()
  648. .map(function (value) { return mapperFn(value); })
  649. .join(' <-> ');
  650. };
  651. // Cannot use Generator type because of ng-packagr
  652. LinkedList.prototype[Symbol.iterator] = function () {
  653. var node, position;
  654. return __generator(this, function (_a) {
  655. switch (_a.label) {
  656. case 0:
  657. node = this.first, position = 0;
  658. _a.label = 1;
  659. case 1:
  660. if (!node) return [3 /*break*/, 4];
  661. return [4 /*yield*/, node.value];
  662. case 2:
  663. _a.sent();
  664. _a.label = 3;
  665. case 3:
  666. position++, node = node.next;
  667. return [3 /*break*/, 1];
  668. case 4: return [2 /*return*/];
  669. }
  670. });
  671. };
  672. return LinkedList;
  673. }());
  674. /*
  675. * Public API Surface of utils
  676. */
  677. /**
  678. * Generated bundle index. Do not edit.
  679. */
  680. exports.LinkedList = LinkedList;
  681. exports.ListNode = ListNode;
  682. Object.defineProperty(exports, '__esModule', { value: true });
  683. })));
  684. //# sourceMappingURL=abp-utils.umd.js.map