Skip to content

Commit f3f390b

Browse files
author
Steve Thompson
committed
changed PublicArray.ts file to index.ts
1 parent 02faff2 commit f3f390b

File tree

6 files changed

+103
-209
lines changed

6 files changed

+103
-209
lines changed

dist/PublicArray.js

Lines changed: 0 additions & 94 deletions
This file was deleted.
File renamed without changes.

dist/index.js

Lines changed: 91 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,94 @@
11
"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+
})();
215
Object.defineProperty(exports, "__esModule", { value: true });
16+
var array_append_prepend_1 = require("@writetome51/array-append-prepend");
17+
var set_array_1 = require("@writetome51/set-array");
318
var di_factory_1 = require("@writetome51/di-factory");
4-
var public_array_filter_1 = require("@writetome51/public-array-filter");
5-
var public_array_getter_1 = require("@writetome51/public-array-getter");
6-
var public_array_getter_converter_1 = require("@writetome51/public-array-getter-converter");
7-
var public_array_getter_remover_1 = require("@writetome51/public-array-getter-remover");
8-
var public_array_inserter_1 = require("@writetome51/public-array-inserter");
9-
var public_array_remover_1 = require("@writetome51/public-array-remover");
10-
var public_array_replacer_1 = require("@writetome51/public-array-replacer");
11-
var public_array_sorter_1 = require("@writetome51/public-array-sorter");
12-
var PublicArray_1 = require("./PublicArray");
13-
di_factory_1.DIFactory.register({
14-
class: PublicArray_1.PublicArray,
15-
dependencies: [
16-
public_array_filter_1.PublicArrayFilter, public_array_getter_converter_1.PublicArrayGetterConverter, public_array_getter_1.PublicArrayGetter,
17-
public_array_getter_remover_1.PublicArrayGetterRemover, public_array_inserter_1.PublicArrayInserter,
18-
public_array_remover_1.PublicArrayRemover, public_array_replacer_1.PublicArrayReplacer, public_array_sorter_1.PublicArraySorter
19-
]
20-
});
21-
// This must be used to instantiate PublicArray:
22-
function getPublicArray(array) {
23-
if (array === void 0) { array = []; }
24-
return di_factory_1.DIFactory.getInstance(PublicArray_1.PublicArray, [array]);
25-
}
26-
exports.getPublicArray = getPublicArray;
19+
var public_array_content_1 = require("@writetome51/public-array-content");
20+
/***********************
21+
This class is for general array manipulation. It's called PublicArray because it
22+
contains an array in a public property: 'data' .
23+
24+
The main reason you would use this class is if you hate JavaScript's built-in Array
25+
methods, like .slice(), .splice(), .push(), and .shift(). This class has much clearer
26+
and expressive method names, and a lot more of them.
27+
28+
A few examples of usage:
29+
30+
let arr = getPublicArray([1,2,3,4,5,6]);
31+
arr.remove.tail(2); // arr.data is now [1,2,3,4]
32+
if (arr.notEmpty) arr.prepend([10]); // arr.data is now [10,1,2,3,4]
33+
**********************/
34+
var PublicArray = /** @class */ (function (_super) {
35+
__extends(PublicArray, _super);
36+
function PublicArray(data // the actual array, represented by inherited property this.data
37+
) {
38+
if (data === void 0) { data = []; }
39+
var _this = _super.call(this, data) || this;
40+
var dependencyClasses = [
41+
{ path: '@writetome51/public-array-filter', name: 'PublicArrayFilter' },
42+
{ path: '@writetome51/public-array-getter-converter', name: 'PublicArrayGetterConverter' },
43+
{ path: '@writetome51/public-array-getter', name: 'PublicArrayGetter' },
44+
{ path: '@writetome51/public-array-getter-remover', name: 'PublicArrayGetterRemover' },
45+
{ path: '@writetome51/public-array-inserter', name: 'PublicArrayInserter' },
46+
{ path: '@writetome51/public-array-remover', name: 'PublicArrayRemover' },
47+
{ path: '@writetome51/public-array-replacer', name: 'PublicArrayReplacer' },
48+
{ path: '@writetome51/public-array-sorter', name: 'PublicArraySorter' }
49+
];
50+
_this._createGetterAndOrSetterForEach(
51+
// each of these is a public property:
52+
['filter', 'getConverted', 'get', 'getAndRemove', 'insert',
53+
'remove', 'replace', 'sort'], {
54+
get_getterFunction: function (property, index) {
55+
return function () {
56+
// Lazy-Loading is used to instantiate these properties:
57+
if (!(_this["_" + property])) { // if property not set...
58+
var dependencyClass = dependencyClasses[index];
59+
// @ts-ignore
60+
var modul = require(dependencyClass.path);
61+
_this["_" + property] = di_factory_1.DIFactory.getInstance(modul[dependencyClass.name]);
62+
}
63+
_this["_" + property].data = _this.data;
64+
return _this["_" + property];
65+
};
66+
}
67+
});
68+
return _this;
69+
}
70+
Object.defineProperty(PublicArray.prototype, "copy", {
71+
// this.copy -- returns independent copy of 'this', not linked to 'this' in any way.
72+
get: function () {
73+
// @ts-ignore
74+
return di_factory_1.DIFactory.getInstance(PublicArray, [this.get.copy()]);
75+
},
76+
enumerable: true,
77+
configurable: true
78+
});
79+
PublicArray.prototype.append = function (values) {
80+
return this.returnThis_after(array_append_prepend_1.append(values, this.data));
81+
};
82+
PublicArray.prototype.prepend = function (values) {
83+
return this.returnThis_after(array_append_prepend_1.prepend(values, this.data));
84+
};
85+
PublicArray.prototype.forEach = function (iterationFunction) {
86+
return this.returnThis_after(this.data.forEach(iterationFunction));
87+
};
88+
// Use this to change the value of this.data without breaking its memory reference.
89+
PublicArray.prototype.set = function (newArray) {
90+
return this.returnThis_after(set_array_1.setArray(this.data, newArray));
91+
};
92+
return PublicArray;
93+
}(public_array_content_1.PublicArrayContent));
94+
exports.PublicArray = PublicArray;

dist/tests.js

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
33
var arrays_match_1 = require("@writetome51/arrays-match");
4-
var PublicArray_1 = require("./PublicArray");
5-
var arr = new PublicArray_1.PublicArray([1, 2, 3, 4, 5, 6, 7, 8, 9]);
4+
var index_1 = require("./index");
5+
var arr = new index_1.PublicArray([1, 2, 3, 4, 5, 6, 7, 8, 9]);
66
// Test 1: new PublicArray() must return instance of PublicArray:
77
if (arr.className && arr.className === 'PublicArray')
88
console.log('test 1 passed');
@@ -111,44 +111,6 @@ if (arrays_match_1.arraysMatch(arr.remove.data, arr.data))
111111
console.log('test 7B passed');
112112
else
113113
console.log('test 7B FAILED');
114-
/****************
115-
116-
117-
let otherArr = arr.data;
118-
119-
otherArr.length = 0;
120-
121-
console.log(otherArr);
122-
123-
console.log(arr.data);
124-
125-
126-
127-
128-
arr.remove.allAfterFirst(6);
129-
arr.remove.allBeforeFirst(3);
130-
arr.prepend([100]);
131-
arr.append([100]);
132-
133-
let anotherArr = arr.copy;
134-
135-
arr.append([888]);
136-
137-
anotherArr.append([3000]);
138-
139-
console.log(arr.data);
140-
console.log(anotherArr.data);
141-
console.log(arr.length);
142-
143-
let hasStrings = arr.anyPass((item) => typeof item === 'string' );
144-
145-
console.log(hasStrings);
146-
147-
console.log(arr.firstIndexOf(4));
148-
149-
console.log(arr.startsWith([100, 3]));
150-
151-
console.log(arr.sort.shuffle());
152-
153-
console.log(arr.sort);
154-
*************/
114+
var copy = arr.copy;
115+
copy.data = ['j'];
116+
console.log(arr.data);

lib/PublicArray.ts renamed to lib/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { PublicArrayContent } from '@writetome51/public-array-content';
2323
export class PublicArray extends PublicArrayContent {
2424

2525

26-
// readonly copy: PublicArray (an independent copy of this instance).
26+
// readonly copy: PublicArray (an independent copy of this instance).
2727
readonly filter; // PublicArrayFilter
2828
readonly getConverted; // PublicArrayGetterConverter;
2929
readonly get; // PublicArrayGetter;

lib/tests.ts

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { arraysMatch } from '@writetome51/arrays-match';
2-
import { PublicArray } from './PublicArray';
2+
import { PublicArray } from './index';
33

44

55
let arr = new PublicArray([1, 2, 3, 4, 5, 6, 7, 8, 9]);
@@ -49,7 +49,7 @@ if (arraysMatch(arr.get.data, arr.data)) console.log('test 4A passed');
4949
else console.log('test 4A FAILED');
5050

5151
// Test 4B: arr.data must remain in-sync with arr.get.data after calling an arr.get method:
52-
arr.get.byIndexes([0,2]);
52+
arr.get.byIndexes([0, 2]);
5353
if (arraysMatch(arr.get.data, arr.data)) console.log('test 4B passed');
5454
else console.log('test 4B FAILED');
5555

@@ -64,7 +64,7 @@ else console.log('test 5A FAILED');
6464

6565
// Test 5B: arr.data must remain in-sync with arr.getAndRemove.data after calling an arr.getAndRemove
6666
// method:
67-
arr.getAndRemove.byIndexes([0,2]);
67+
arr.getAndRemove.byIndexes([0, 2]);
6868
if (arraysMatch(arr.getAndRemove.data, arr.data)) console.log('test 5B passed');
6969
else console.log('test 5B FAILED');
7070

@@ -96,48 +96,6 @@ arr.remove.firstOf('h');
9696
if (arraysMatch(arr.remove.data, arr.data)) console.log('test 7B passed');
9797
else console.log('test 7B FAILED');
9898

99-
100-
101-
102-
103-
/****************
104-
105-
106-
let otherArr = arr.data;
107-
108-
otherArr.length = 0;
109-
110-
console.log(otherArr);
111-
112-
console.log(arr.data);
113-
114-
115-
116-
117-
arr.remove.allAfterFirst(6);
118-
arr.remove.allBeforeFirst(3);
119-
arr.prepend([100]);
120-
arr.append([100]);
121-
122-
let anotherArr = arr.copy;
123-
124-
arr.append([888]);
125-
126-
anotherArr.append([3000]);
127-
128-
console.log(arr.data);
129-
console.log(anotherArr.data);
130-
console.log(arr.length);
131-
132-
let hasStrings = arr.anyPass((item) => typeof item === 'string' );
133-
134-
console.log(hasStrings);
135-
136-
console.log(arr.firstIndexOf(4));
137-
138-
console.log(arr.startsWith([100, 3]));
139-
140-
console.log(arr.sort.shuffle());
141-
142-
console.log(arr.sort);
143-
*************/
99+
let copy = arr.copy;
100+
copy.data = ['j'];
101+
console.log(arr.data);

0 commit comments

Comments
 (0)