|
| 1 | +"use strict"; |
| 2 | +var __extends = (this && this.__extends) || (function () { |
| 3 | + var extendStatics = function (d, b) { |
| 4 | + extendStatics = Object.setPrototypeOf || |
| 5 | + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || |
| 6 | + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; |
| 7 | + return extendStatics(d, b); |
| 8 | + } |
| 9 | + return function (d, b) { |
| 10 | + extendStatics(d, b); |
| 11 | + function __() { this.constructor = d; } |
| 12 | + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); |
| 13 | + }; |
| 14 | +})(); |
| 15 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 16 | +var array_append_prepend_1 = require("@writetome51/array-append-prepend"); |
| 17 | +var di_factory_1 = require("@writetome51/di-factory"); |
| 18 | +var public_array_content_1 = require("@writetome51/public-array-content"); |
| 19 | +/************** |
| 20 | + This class is called PublicArray because an array is contained inside it, in a public property. |
| 21 | +
|
| 22 | + The main reason you would use this class is if you hate JavaScript's built-in Array |
| 23 | + methods, like .slice(), .splice(), .push(), and .shift(). This class has much clearer |
| 24 | + and expressive method names. |
| 25 | +
|
| 26 | + A few examples of usage: |
| 27 | +
|
| 28 | + let arr = getPublicArray( [1,2,3,4,5,6] ); |
| 29 | + arr.remove.tail(2); // arr.data is now [1,2,3,4] |
| 30 | + if (arr.notEmpty) arr.prepend([10]); // arr.data is now [10,1,2,3,4] |
| 31 | +
|
| 32 | + To access the array itself, you access the 'data' property. |
| 33 | + *************/ |
| 34 | +var PublicArray = /** @class */ (function (_super) { |
| 35 | + __extends(PublicArray, _super); |
| 36 | + function PublicArray( |
| 37 | + // begin injected dependencies... |
| 38 | + _filter, _getConverted, _get, _getAndRemove, _insert, _remove, _replace, _sort, |
| 39 | + // ... end injected dependencies |
| 40 | + data) { |
| 41 | + if (data === void 0) { data = []; } |
| 42 | + var _this = _super.call(this, data) || this; |
| 43 | + _this._filter = _filter; |
| 44 | + _this._getConverted = _getConverted; |
| 45 | + _this._get = _get; |
| 46 | + _this._getAndRemove = _getAndRemove; |
| 47 | + _this._insert = _insert; |
| 48 | + _this._remove = _remove; |
| 49 | + _this._replace = _replace; |
| 50 | + _this._sort = _sort; |
| 51 | + _this._createGetterAndOrSetterForEach( |
| 52 | + // each of these is a public property: |
| 53 | + ['filter', 'getConverted', 'get', 'getAndRemove', 'insert', |
| 54 | + 'remove', 'replace', 'sort'], { |
| 55 | + get_getterFunction: function (property) { |
| 56 | + return function () { |
| 57 | + _this["_" + property].data = _this.data; |
| 58 | + return _this["_" + property]; |
| 59 | + }; |
| 60 | + } |
| 61 | + }); |
| 62 | + return _this; |
| 63 | + } |
| 64 | + Object.defineProperty(PublicArray.prototype, "copy", { |
| 65 | + // this.copy -- returns independent copy of this. |
| 66 | + get: function () { |
| 67 | + // @ts-ignore |
| 68 | + return di_factory_1.DIFactory.getInstance(PublicArray, [this.get.copy]); |
| 69 | + }, |
| 70 | + enumerable: true, |
| 71 | + configurable: true |
| 72 | + }); |
| 73 | + PublicArray.prototype.append = function (values) { |
| 74 | + return this.returnThis_after(array_append_prepend_1.append(values, this.data)); |
| 75 | + }; |
| 76 | + PublicArray.prototype.prepend = function (values) { |
| 77 | + return this.returnThis_after(array_append_prepend_1.prepend(values, this.data)); |
| 78 | + }; |
| 79 | + // this.forEach(iterationFunction) |
| 80 | + // iterationFunction = function(currentItem, currentIndex?, entireArray?){...} |
| 81 | + PublicArray.prototype.forEach = function (iterationFunction) { |
| 82 | + return this.returnThis_after(this.data.forEach(iterationFunction)); |
| 83 | + }; |
| 84 | + return PublicArray; |
| 85 | +}(public_array_content_1.PublicArrayContent)); |
| 86 | +exports.PublicArray = PublicArray; |
0 commit comments