Skip to content

Commit d34a74a

Browse files
authored
Merge pull request #10 from georapbox/update-library
Update library to v4
2 parents 50ac06a + 3ebfb96 commit d34a74a

22 files changed

+1463
-3036
lines changed

CHAGELOG.md renamed to CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
# CHANGELOG
22

3+
## v4.0.0
4+
5+
### BREAKING CHANGES
6+
7+
Remove default export in favor of named exports.
8+
9+
The following is **NOT** working aymore:
10+
```js
11+
import immutableArrays from 'immutable-arrays';
12+
```
13+
14+
Import the method you want to use instead:
15+
```js
16+
import { push } from 'immutable-arrays';
17+
```
18+
19+
### OTHER CHANGES
20+
21+
- Fix missing build file path for UMD bundling in rollup configuration file
22+
- Update `devDependencies`
23+
324
## v3.0.1
425

526
- Fixes issue #8

README.md

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,28 @@ The library is exported in the following formats:
2727
- `ESM (Ecmascript Modules)` for usage in browsers or environments that support ESM
2828

2929
### Old school browser global
30+
3031
```html
31-
<script src="immutable-arrays/dist/immutable-arrays.umd.min.js"></script>
32+
<script src="https://unpkg.com/immutable-arrays@<VERSION_GOES_HERE>/dist/immutable-arrays.umd.min.js"></script>
3233
```
3334

35+
After importing the library it can be accessed via the global variable `immutableArrays`.
36+
3437
### Node.js
3538

3639
```js
37-
const immutableArrays = require('immutable-arrays');
40+
const push = require('immutable-arrays').push;
3841
```
3942

4043
### ES2015 imports
4144

42-
#### Import default export
43-
44-
```js
45-
import immutableArrays from 'immutable-arrays';
46-
```
47-
48-
#### Import a named export
49-
5045
```js
5146
import { push } from 'immutable-arrays';
5247
```
5348

5449
## API
5550

56-
### immutableArrays.push(array, ...elementN) ⇒ <code>Array</code>
51+
### push(array, ...elementN) ⇒ <code>Array</code>
5752
Adds one or more elements to the end of an array by returning
5853
a new array instead of mutating the original one.
5954

@@ -67,12 +62,12 @@ a new array instead of mutating the original one.
6762
**Example**
6863
```js
6964
const originalArray = ['a', 'b', 'c', 'd', 'e'];
70-
const resultArray = immutableArrays.push(originalArray, 'f', 'g');
65+
const resultArray = push(originalArray, 'f', 'g');
7166
// -> originalArray ['a', 'b', 'c', 'd', 'e']
7267
// -> resultArray ['a', 'b', 'c', 'd', 'e', 'f', 'g']
7368
```
7469

75-
### immutableArrays.pop(array) ⇒ <code>Array</code>
70+
### pop(array) ⇒ <code>Array</code>
7671
Removes the last element from an array by returning
7772
a new array instead of mutating the original one.
7873

@@ -85,12 +80,12 @@ a new array instead of mutating the original one.
8580
**Example**
8681
```js
8782
const originalArray = ['a', 'b', 'c', 'd', 'e'];
88-
const resultArray = immutableArrays.pop(originalArray);
83+
const resultArray = pop(originalArray);
8984
// -> originalArray ['a', 'b', 'c', 'd', 'e']
9085
// -> resultArray ['a', 'b', 'c', 'd']
9186
```
9287

93-
### immutableArrays.shift(array) ⇒ <code>Array</code>
88+
### shift(array) ⇒ <code>Array</code>
9489
Removes the first element from an array.
9590

9691
**Returns**: <code>Array</code> - A new array with the first element removed.
@@ -102,12 +97,12 @@ Removes the first element from an array.
10297
**Example**
10398
```js
10499
const originalArray = ['a', 'b', 'c', 'd', 'e'];
105-
const resultArray = immutableArrays.shift(originalArray);
100+
const resultArray = shift(originalArray);
106101
// -> originalArray ['a', 'b', 'c', 'd', 'e']
107102
// -> resultArray ['b', 'c', 'd', 'e']
108103
```
109104

110-
### immutableArrays.unshift(array, ...elementN) ⇒ <code>Array</code>
105+
### unshift(array, ...elementN) ⇒ <code>Array</code>
111106
Adds one or more elements to the beginning of an array.
112107

113108
**Returns**: <code>Array</code> - A new array with the new elements added to the front.
@@ -120,12 +115,12 @@ Adds one or more elements to the beginning of an array.
120115
**Example**
121116
```js
122117
const originalArray = ['a', 'b', 'c', 'd', 'e'];
123-
const resultArray = immutableArrays.unshift(originalArray, 'f', 'g');
118+
const resultArray = unshift(originalArray, 'f', 'g');
124119
// -> originalArray ['a', 'b', 'c', 'd', 'e']
125120
// -> resultArray ['f', 'g', 'a', 'b', 'c', 'd', 'e']
126121
```
127122

128-
### immutableArrays.reverse(array) ⇒ <code>Array</code>
123+
### reverse(array) ⇒ <code>Array</code>
129124
Reverses an array (not in place).
130125
The first array element becomes the last, and the last array element becomes the first.
131126

@@ -138,12 +133,12 @@ The first array element becomes the last, and the last array element becomes the
138133
**Example**
139134
```js
140135
const originalArray = ['a', 'b', 'c', 'd', 'e'];
141-
const resultArray = immutableArrays.reverse(originalArray);
136+
const resultArray = reverse(originalArray);
142137
// -> originalArray ['a', 'b', 'c', 'd', 'e']
143138
// -> resultArray ['e', 'd', 'c', 'b', 'a']
144139
```
145140

146-
### immutableArrays.sort(array, [compareFunction]) ⇒ <code>Array</code>
141+
### sort(array, [compareFunction]) ⇒ <code>Array</code>
147142
Sorts the elements of an array (not in place) and returns a sorted array.
148143

149144
**Returns**: <code>Array</code> - A new sorted array.
@@ -158,24 +153,24 @@ Sorts the elements of an array (not in place) and returns a sorted array.
158153
const numberArray = [20, 3, 4, 10, -3, 1, 0, 5];
159154
const stringArray = ['Blue', 'Humpback', 'Beluga'];
160155

161-
const resultArray = immutableArrays.sort(numberArray, (a, b) => a - b);
156+
const resultArray = sort(numberArray, (a, b) => a - b);
162157
// -> numberArray [20, 3, 4, 10, -3, 1, 0, 5]
163158
// -> resultArray [-3, 0, 1, 3, 4, 5, 10, 20]
164159

165-
const resultArray = immutableArrays.sort(numberArray, (a, b) => b - a);
160+
const resultArray = sort(numberArray, (a, b) => b - a);
166161
// -> numberArray [20, 3, 4, 10, -3, 1, 0, 5]
167162
// -> resultArray [20, 10, 5, 4, 3, 1, 0, -3]
168163

169-
const resultArray = immutableArrays.sort(stringArray);
164+
const resultArray = sort(stringArray);
170165
// -> stringArray ['Blue', 'Humpback', 'Beluga']
171166
// -> resultArray ['Beluga', 'Blue', 'Humpback']
172167

173-
const resultArray = immutableArrays.sort(stringArray, (a, b) => a.toLowerCase() < b.toLowerCase());
168+
const resultArray = sort(stringArray, (a, b) => a.toLowerCase() < b.toLowerCase());
174169
// -> stringArray ['Blue', 'Humpback', 'Beluga']
175170
// -> resultArray ['Humpback', 'Blue', 'Beluga']
176171
```
177172

178-
### immutableArrays.splice(array, [start], [deleteCount], [...elementN]) ⇒ <code>Array</code>
173+
### splice(array, [start], [deleteCount], [...elementN]) ⇒ <code>Array</code>
179174
Removes existing elements and/or adds new elements to an array.
180175

181176
**Returns**: <code>Array</code> - The result array.
@@ -190,52 +185,52 @@ Removes existing elements and/or adds new elements to an array.
190185
**Example**
191186
```js
192187
const originalArray = ['a', 'b', 'c', 'd', 'e'];
193-
const resultArray = immutableArrays.splice(originalArray, 0);
188+
const resultArray = splice(originalArray, 0);
194189
// -> originalArray ['a', 'b', 'c', 'd', 'e']
195190
// -> resultArray []
196191

197192
const originalArray = ['a', 'b', 'c', 'd', 'e'];
198-
const resultArray = immutableArrays.splice(originalArray, 0, 1);
193+
const resultArray = splice(originalArray, 0, 1);
199194
// -> originalArray ['a', 'b', 'c', 'd', 'e']
200195
// -> resultArray ['b', 'c', 'd', 'e']
201196

202197
const originalArray = ['a', 'b', 'c', 'd', 'e'];
203-
const resultArray = immutableArrays.splice(originalArray, 0, 3);
198+
const resultArray = splice(originalArray, 0, 3);
204199
// -> originalArray ['a', 'b', 'c', 'd', 'e']
205200
// -> resultArray ['d', 'e']
206201

207202
const originalArray = ['a', 'b', 'c', 'd', 'e'];
208-
const resultArray = immutableArrays.splice(originalArray, 0, originalArray.length);
203+
const resultArray = splice(originalArray, 0, originalArray.length);
209204
// -> originalArray ['a', 'b', 'c', 'd', 'e']
210205
// -> resultArray []
211206

212207
const originalArray = ['a', 'b', 'c', 'd', 'e'];
213-
const resultArray = immutableArrays.splice(originalArray, 0, -3);
208+
const resultArray = splice(originalArray, 0, -3);
214209
// -> originalArray ['a', 'b', 'c', 'd', 'e']
215210
// -> resultArray ['a', 'b', 'c', 'd', 'e']
216211

217212
const originalArray = ['a', 'b', 'c', 'd', 'e'];
218-
const resultArray = immutableArrays.splice(originalArray, 0, 0, 'lorem', 'ipsum');
213+
const resultArray = splice(originalArray, 0, 0, 'lorem', 'ipsum');
219214
// -> originalArray ['a', 'b', 'c', 'd', 'e']
220215
// -> resultArray ['lorem', 'ipsum', 'a', 'b', 'c', 'd', 'e']
221216

222217
const originalArray = ['a', 'b', 'c', 'd', 'e'];
223-
const resultArray = immutableArrays.splice(originalArray, originalArray.length, 0, 'lorem', 'ipsum');
218+
const resultArray = splice(originalArray, originalArray.length, 0, 'lorem', 'ipsum');
224219
// -> originalArray ['a', 'b', 'c', 'd', 'e']
225220
// -> resultArray ['a', 'b', 'c', 'd', 'e', 'lorem', 'ipsum']
226221

227222
const originalArray = ['a', 'b', 'c', 'd', 'e'];
228-
const resultArray = immutableArrays.splice(originalArray, 0, 2, 'lorem', 'ipsum');
223+
const resultArray = splice(originalArray, 0, 2, 'lorem', 'ipsum');
229224
// -> originalArray ['a', 'b', 'c', 'd', 'e']
230225
// -> resultArray ['lorem', 'ipsum', 'c', 'd', 'e']
231226

232227
const originalArray = ['a', 'b', 'c', 'd', 'e'];
233-
const resultArray = immutableArrays.splice(originalArray, originalArray.length - 2, 2, 'lorem', 'ipsum');
228+
const resultArray = splice(originalArray, originalArray.length - 2, 2, 'lorem', 'ipsum');
234229
// -> originalArray ['a', 'b', 'c', 'd', 'e']
235230
// -> resultArray ['a', 'b', 'c', 'lorem', 'ipsum']
236231
```
237232

238-
### immutableArrays.del(array, index) ⇒ <code>Array</code>
233+
### del(array, index) ⇒ <code>Array</code>
239234
Deletes an element from an array by its index in the array.
240235

241236
**Returns**: <code>Array</code> - A new array with the element removed.
@@ -248,11 +243,11 @@ Deletes an element from an array by its index in the array.
248243
**Example**
249244
```js
250245
const originalArray = ['a', 'b', 'c', 'd', 'e'];
251-
const resultArray = immutableArrays.del(originalArray, 2);
246+
const resultArray = del(originalArray, 2);
252247
// -> originalArray ['a', 'b', 'c', 'd', 'e']
253248
// -> resultArray ['a', 'b', 'd', 'e']
254249

255-
const resultArray2 = immutableArrays.del(originalArray, -1);
250+
const resultArray2 = del(originalArray, -1);
256251
// -> originalArray ['a', 'b', 'c', 'd', 'e']
257252
// -> resultArray2 ['a', 'b', 'c', 'd', 'e']
258253
```
@@ -283,6 +278,10 @@ $ npm run test
283278
$ npm run coverage
284279
```
285280

281+
## Changelog
282+
283+
For API updates and breaking changes, check the [CHANGELOG](https://github.com/georapbox/immutable-arrays/blob/master/CHAGELOG.md).
284+
286285
## License
287286

288287
[The MIT License (MIT)](https://georapbox.mit-license.org/@2017)

0 commit comments

Comments
 (0)