Skip to content

Commit

Permalink
added new method .moveByIndex() .
Browse files Browse the repository at this point in the history
Removed DIFactory from dependencies.
made .forEach() return void.
Incremented package version to 4.0.0
  • Loading branch information
Steve Thompson committed Feb 8, 2019
1 parent f258ffc commit c01a5cc
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 14 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ new PublicArray(array = [])
<summary>view properties</summary>

#### data: any[] (read-writable)
###### This is the array to be operated on.
&nbsp;&nbsp;&nbsp;&nbsp;<small>This is the array to be operated on.</small>

#### copy: PublicArray (read-only)
###### a copy of the PublicArray instance, containing an independent copy of this.data that can be manipulated separately.
&nbsp;&nbsp;&nbsp;&nbsp;<small>a copy of the PublicArray instance, containing an independent copy of this.data that can be manipulated separately.</small>

#### length: number (read-writable)
###### length of this.data
Expand Down Expand Up @@ -558,7 +558,11 @@ append(values: any[]): this
prepend(values: any[]): this
// attaches values to beginning of this.data.
forEach(iterationFunction): this
moveByIndex(currentIndex, newIndex): this
// moves an item, identified by currentIndex, to newIndex.
// Both currentIndex and newIndex can be negative or positive.
forEach(iterationFunction): void
// Behaves same as Array.forEach()
// iterationFunction = function(currentValue, currentIndex?, entireArray?){...}
Expand Down
5 changes: 4 additions & 1 deletion dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ export declare class PublicArray extends PublicArrayContent {
prepend(values: any[]): this;


moveByIndex(currentIndex: number, newIndex: number): this;


forEach(
iterationFunction: (currentValue: any, currentIndex?: number, entireArray?: any[]) => any
): this;
): void;

}
9 changes: 6 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ var __extends = (this && this.__extends) || (function () {
})();
Object.defineProperty(exports, "__esModule", { value: true });
var array_append_prepend_1 = require("@writetome51/array-append-prepend");
var array_move_by_index_1 = require("@writetome51/array-move-by-index");
var set_array_1 = require("@writetome51/set-array");
var di_factory_1 = require("@writetome51/di-factory");
var public_array_content_1 = require("@writetome51/public-array-content");
/***********************
This class is for general array manipulation. It's called PublicArray because it
Expand Down Expand Up @@ -53,7 +53,7 @@ var PublicArray = /** @class */ (function (_super) {
var dependencyClass = dependencyClasses[index];
// @ts-ignore
var modul = require(dependencyClass.path);
_this["_" + property] = di_factory_1.DIFactory.getInstance(modul[dependencyClass.name]);
_this["_" + property] = new modul[dependencyClass.name];
}
_this["_" + property].data = _this.data;
return _this["_" + property];
Expand All @@ -72,8 +72,11 @@ var PublicArray = /** @class */ (function (_super) {
PublicArray.prototype.prepend = function (values) {
return this._returnThis_after(array_append_prepend_1.prepend(values, this.data));
};
PublicArray.prototype.moveByIndex = function (currentIndex, newIndex) {
return this._returnThis_after(array_move_by_index_1.moveByIndex(currentIndex, newIndex, this.data));
};
PublicArray.prototype.forEach = function (iterationFunction) {
return this._returnThis_after(this.data.forEach(iterationFunction));
this.data.forEach(iterationFunction);
};
return PublicArray;
}(public_array_content_1.PublicArrayContent));
Expand Down
7 changes: 7 additions & 0 deletions dist/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,10 @@ if (arrays_match_1.arraysMatch(indexes, [1, 3]))
console.log('test 22 passed');
else
console.log('test 22 FAILED');
// Test 23: make sure .moveByIndex() works:
// arr.data is [1,2,3,4,5]
arr.moveByIndex(-1, 1);
if (arrays_match_1.arraysMatch(arr.data, [1, 5, 2, 3, 4]))
console.log('test 23 passed');
else
console.log('test 23 FAILED');
13 changes: 9 additions & 4 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { append, prepend } from '@writetome51/array-append-prepend';
import { moveByIndex } from '@writetome51/array-move-by-index';
import { setArray } from '@writetome51/set-array';
import { DIFactory } from '@writetome51/di-factory';
import { PublicArrayContent } from '@writetome51/public-array-content';


Expand Down Expand Up @@ -73,7 +73,7 @@ export class PublicArray extends PublicArrayContent {
let dependencyClass = dependencyClasses[index];
// @ts-ignore
let modul = require(dependencyClass.path);
this[`_${property}`] = DIFactory.getInstance(modul[dependencyClass.name]);
this[`_${property}`] = new modul[dependencyClass.name];
}
this[`_${property}`].data = this.data;
return this[`_${property}`];
Expand Down Expand Up @@ -101,8 +101,13 @@ export class PublicArray extends PublicArrayContent {
}


forEach(iterationFunction: (currentValue, currentIndex?, entireArray?) => any): this {
return this._returnThis_after(this.data.forEach(iterationFunction));
moveByIndex(currentIndex, newIndex): this {
return this._returnThis_after(moveByIndex(currentIndex, newIndex, this.data));
}


forEach(iterationFunction: (currentValue, currentIndex?, entireArray?) => any): void {
this.data.forEach(iterationFunction);
}


Expand Down
6 changes: 6 additions & 0 deletions lib/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,9 @@ let indexes = arr.indexesThatPass((item) => (item % 2 === 0));
if (arraysMatch(indexes, [1, 3])) console.log('test 22 passed');
else console.log('test 22 FAILED');


// Test 23: make sure .moveByIndex() works:
// arr.data is [1,2,3,4,5]
arr.moveByIndex(-1, 1);
if (arraysMatch(arr.data, [1, 5, 2, 3, 4])) console.log('test 23 passed');
else console.log('test 23 FAILED');
12 changes: 11 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@writetome51/public-array",
"version": "3.0.1",
"version": "4.0.0",
"description": "A TypeScript/JavaScript class for general array manipulation",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -47,7 +47,7 @@
"@writetome51/public-array-getter-remover": "~2.0.0",
"@writetome51/public-array-filter": "~2.0.0",
"@writetome51/array-append-prepend": "~1.0.3",
"@writetome51/di-factory": "~1.0.0",
"@writetome51/array-move-by-index": "~1.0.0",
"@writetome51/set-array": "~1.0.1"
}
}

0 comments on commit c01a5cc

Please sign in to comment.