Skip to content

Commit e6c0aeb

Browse files
author
Steve Thompson
committed
More changes to README
1 parent 072515c commit e6c0aeb

File tree

2 files changed

+73
-94
lines changed

2 files changed

+73
-94
lines changed

README.md

Lines changed: 73 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22

33
A TypeScript/JavaScript class for general array manipulation.
44

5+
The main reason you would use PublicArray is if you hate JavaScript's built-in Array methods,
6+
like `.slice()`, `.splice()`, `.push()`, and `.shift()`. PublicArray has much clearer and expressive
7+
method names, and a lot more of them. Examples:
8+
```
9+
let arr = getPublicArray([1,2,3,4,5,6]);
10+
arr.remove.tail(2); // arr.data is now [1,2,3,4]
11+
arr.remove.head(1); // arr.data is now [2,3,4]
12+
13+
if (arr.notEmpty) arr.prepend([10,11]); // arr.data is now [10,11,2,3,4]
14+
arr.append([100,200,300]); // arr.data is now [10,11,2,3,4,100,200,300]
15+
```
16+
To actually see or get the array itself, you must access PublicArray's `data` property:
17+
18+
`console.log(arr.data); // logs '[10,11,2,3,4,100,200,300]' `
19+
520
## Installation
621

722
You must have npm installed first. Then, in the command line:
@@ -34,36 +49,64 @@ getPublicArray(array = []): PublicArray
3449

3550
### Properties
3651

37-
```
38-
className: string (read-only)
52+
#### className: string (read-only)
53+
54+
#### copy: PublicArray (read-only)
55+
###### an independent copy of the PublicArray instance
56+
57+
#### data: any[] (read-writable)
58+
###### This is the array to be operated on.
59+
60+
#### length: number (read-writable)
61+
###### length of array
62+
63+
#### isEmpty: boolean (read-only)
64+
###### true if this.data is empty
65+
66+
#### notEmpty: boolean (read-only)
67+
68+
#### filter: PublicArrayFilter (read-only)
69+
Filter has methods that narrow down the content of the array it contains
70+
and return the class instance.
71+
72+
To instantiate, pass the actual array it will contain into its constructor:
3973

40-
copy: PublicArray (read-only) // an independent copy of the PublicArray instance
74+
let filter = new PublicArrayFilter( [item1, item2, item3,...] );
4175

42-
data: any[] (read-writable) // This is the array to be operated on.
76+
You can also reset the array by accessing the class 'data' property:
4377

44-
length: number (read-writable) // length of array
78+
filter.data = [1,2,3,4,...];
4579

46-
isEmpty: boolean (read-only) // true if this.data is empty
80+
These are all its methods:
4781

48-
notEmpty: boolean (read-only)
82+
// Narrows down the array to only the values that pass test:
4983

50-
filter: PublicArrayFilter (read-only)
84+
byTest(testFunction): this
85+
// testFunction = function(currentValue, currentIndex?, theArray?){...}
86+
// testFunction must return boolean.
5187

52-
getConverted: PublicArrayGetterConverter (read-only)
88+
89+
// Narrows down the array to only values that are the specified type:
90+
91+
byType(
92+
type: 'number' | 'boolean' | 'string' | 'array' | 'object' | 'function' | 'undefined'
93+
): this
94+
95+
96+
#### getConverted: PublicArrayGetterConverter (read-only)
5397

54-
get: PublicArrayGetter (read-only)
98+
#### get: PublicArrayGetter (read-only)
5599

56-
getAndRemove: PublicArrayGetterRemover (read-only)
100+
#### getAndRemove: PublicArrayGetterRemover (read-only)
57101

58-
insert: PublicArrayInserter (read-only)
102+
#### insert: PublicArrayInserter (read-only)
59103

60-
remove: PublicArrayRemover (read-only)
104+
#### remove: PublicArrayRemover (read-only)
61105

62-
replace: PublicArrayReplacer (read-only)
106+
#### replace: PublicArrayReplacer (read-only)
63107

64-
sort: PublicArraySorter (read-only)
108+
#### sort: PublicArraySorter (read-only)
65109

66-
```
67110

68111
### Methods
69112

@@ -92,35 +135,28 @@ endsWith(values: any[]): boolean
92135
matches(array): boolean
93136
// returns false if array contains object.
94137
95-
96138
// For the next 3 methods:
97139
// testFunction is a callback with same signature as callback passed to
98140
// Array.filter() :
99141
// testFunction(value, index?, theArray?): checks if value passes test. If yes, it returns true.
100142
101-
102-
// returns true if all items pass test.
103143
allPass(testFunction): boolean
144+
// returns true if all items pass test.
104145
105-
106-
// returns true if only 1 value passes.
107146
anyPass(testFunction): boolean
147+
// returns true if only 1 value passes.
108148
149+
indexesThatPass(testFunction): number[]
150+
// returns all indexes of items that pass test.
109151
110-
// returns all indexes of items that pass test.
111-
indexesThatPass(testFunction): number[]
112-
113-
114-
// Does not work if value is object.
115-
firstIndexOf(value): number
152+
firstIndexOf(value): number
153+
// Does not work if value is object.
116154
155+
lastIndexOf(value): number
156+
// Does not work if value is object.
117157
118-
// Does not work if value is object.
119-
lastIndexOf(value): number
120-
121-
122-
// Does not work if value is object.
123-
indexesOf(value): number[]
158+
indexesOf(value): number[]
159+
// Does not work if value is object.
124160
125161
append(values: any[]): this
126162
@@ -135,6 +171,7 @@ protected _createGetterAndOrSetterForEach(
135171
) : void
136172
137173
returnThis_after(voidExpression: any) : this
174+
// Executes voidExpression and returns this.
138175
// Even if voidExpression returns something, the returned data isn't used.
139176
140177
runMethod_and_returnThis(
@@ -150,17 +187,16 @@ runMethod_and_returnThis(
150187
## Usage
151188

152189
```
153-
154190
// changing the array content:
155191
arr.data = [1,2,3,4,5,6,7];
156192
157193
```
158194

159195
## Performance
160196

161-
PublicArray has a large number of dependencies. You should keep this in mind when optimizing the
162-
performance of your app. If your code only uses one property of PublicArray, like for
163-
instance .replace, you will get a slight performance boost if you just use an instance of
197+
PublicArray has a large number of dependencies. You should keep this in mind when optimizing
198+
the performance of your app. If your code only uses one property of PublicArray, like for
199+
instance `.replace`, you will get a slight performance boost if you just use an instance of
164200
PublicArrayReplacer instead:
165201
```
166202
let replace = new PublicArrayReplacer(arr);

README.txt

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)