Skip to content

Commit 9d73b42

Browse files
committed
remove default export
1 parent 3bac1cc commit 9d73b42

19 files changed

+97
-100
lines changed

CHAGELOG.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: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,25 @@ The library is exported in the following formats:
3131
<script src="immutable-arrays/dist/immutable-arrays.umd.min.js"></script>
3232
```
3333

34-
### Node.js
35-
3634
```js
37-
const immutableArrays = require('immutable-arrays');
35+
const push = immutableArrays.push;
3836
```
3937

40-
### ES2015 imports
41-
42-
#### Import default export
38+
### Node.js
4339

4440
```js
45-
import immutableArrays from 'immutable-arrays';
41+
const push = require('immutable-arrays').push;
4642
```
4743

48-
#### Import a named export
44+
### ES2015 imports
4945

5046
```js
5147
import { push } from 'immutable-arrays';
5248
```
5349

5450
## API
5551

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

@@ -67,12 +63,12 @@ a new array instead of mutating the original one.
6763
**Example**
6864
```js
6965
const originalArray = ['a', 'b', 'c', 'd', 'e'];
70-
const resultArray = immutableArrays.push(originalArray, 'f', 'g');
66+
const resultArray = push(originalArray, 'f', 'g');
7167
// -> originalArray ['a', 'b', 'c', 'd', 'e']
7268
// -> resultArray ['a', 'b', 'c', 'd', 'e', 'f', 'g']
7369
```
7470

75-
### immutableArrays.pop(array) ⇒ <code>Array</code>
71+
### pop(array) ⇒ <code>Array</code>
7672
Removes the last element from an array by returning
7773
a new array instead of mutating the original one.
7874

@@ -85,12 +81,12 @@ a new array instead of mutating the original one.
8581
**Example**
8682
```js
8783
const originalArray = ['a', 'b', 'c', 'd', 'e'];
88-
const resultArray = immutableArrays.pop(originalArray);
84+
const resultArray = pop(originalArray);
8985
// -> originalArray ['a', 'b', 'c', 'd', 'e']
9086
// -> resultArray ['a', 'b', 'c', 'd']
9187
```
9288

93-
### immutableArrays.shift(array) ⇒ <code>Array</code>
89+
### shift(array) ⇒ <code>Array</code>
9490
Removes the first element from an array.
9591

9692
**Returns**: <code>Array</code> - A new array with the first element removed.
@@ -102,12 +98,12 @@ Removes the first element from an array.
10298
**Example**
10399
```js
104100
const originalArray = ['a', 'b', 'c', 'd', 'e'];
105-
const resultArray = immutableArrays.shift(originalArray);
101+
const resultArray = shift(originalArray);
106102
// -> originalArray ['a', 'b', 'c', 'd', 'e']
107103
// -> resultArray ['b', 'c', 'd', 'e']
108104
```
109105

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

113109
**Returns**: <code>Array</code> - A new array with the new elements added to the front.
@@ -120,12 +116,12 @@ Adds one or more elements to the beginning of an array.
120116
**Example**
121117
```js
122118
const originalArray = ['a', 'b', 'c', 'd', 'e'];
123-
const resultArray = immutableArrays.unshift(originalArray, 'f', 'g');
119+
const resultArray = unshift(originalArray, 'f', 'g');
124120
// -> originalArray ['a', 'b', 'c', 'd', 'e']
125121
// -> resultArray ['f', 'g', 'a', 'b', 'c', 'd', 'e']
126122
```
127123

128-
### immutableArrays.reverse(array) ⇒ <code>Array</code>
124+
### reverse(array) ⇒ <code>Array</code>
129125
Reverses an array (not in place).
130126
The first array element becomes the last, and the last array element becomes the first.
131127

@@ -138,12 +134,12 @@ The first array element becomes the last, and the last array element becomes the
138134
**Example**
139135
```js
140136
const originalArray = ['a', 'b', 'c', 'd', 'e'];
141-
const resultArray = immutableArrays.reverse(originalArray);
137+
const resultArray = reverse(originalArray);
142138
// -> originalArray ['a', 'b', 'c', 'd', 'e']
143139
// -> resultArray ['e', 'd', 'c', 'b', 'a']
144140
```
145141

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

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

161-
const resultArray = immutableArrays.sort(numberArray, (a, b) => a - b);
157+
const resultArray = sort(numberArray, (a, b) => a - b);
162158
// -> numberArray [20, 3, 4, 10, -3, 1, 0, 5]
163159
// -> resultArray [-3, 0, 1, 3, 4, 5, 10, 20]
164160

165-
const resultArray = immutableArrays.sort(numberArray, (a, b) => b - a);
161+
const resultArray = sort(numberArray, (a, b) => b - a);
166162
// -> numberArray [20, 3, 4, 10, -3, 1, 0, 5]
167163
// -> resultArray [20, 10, 5, 4, 3, 1, 0, -3]
168164

169-
const resultArray = immutableArrays.sort(stringArray);
165+
const resultArray = sort(stringArray);
170166
// -> stringArray ['Blue', 'Humpback', 'Beluga']
171167
// -> resultArray ['Beluga', 'Blue', 'Humpback']
172168

173-
const resultArray = immutableArrays.sort(stringArray, (a, b) => a.toLowerCase() < b.toLowerCase());
169+
const resultArray = sort(stringArray, (a, b) => a.toLowerCase() < b.toLowerCase());
174170
// -> stringArray ['Blue', 'Humpback', 'Beluga']
175171
// -> resultArray ['Humpback', 'Blue', 'Beluga']
176172
```
177173

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

181177
**Returns**: <code>Array</code> - The result array.
@@ -190,52 +186,52 @@ Removes existing elements and/or adds new elements to an array.
190186
**Example**
191187
```js
192188
const originalArray = ['a', 'b', 'c', 'd', 'e'];
193-
const resultArray = immutableArrays.splice(originalArray, 0);
189+
const resultArray = splice(originalArray, 0);
194190
// -> originalArray ['a', 'b', 'c', 'd', 'e']
195191
// -> resultArray []
196192

197193
const originalArray = ['a', 'b', 'c', 'd', 'e'];
198-
const resultArray = immutableArrays.splice(originalArray, 0, 1);
194+
const resultArray = splice(originalArray, 0, 1);
199195
// -> originalArray ['a', 'b', 'c', 'd', 'e']
200196
// -> resultArray ['b', 'c', 'd', 'e']
201197

202198
const originalArray = ['a', 'b', 'c', 'd', 'e'];
203-
const resultArray = immutableArrays.splice(originalArray, 0, 3);
199+
const resultArray = splice(originalArray, 0, 3);
204200
// -> originalArray ['a', 'b', 'c', 'd', 'e']
205201
// -> resultArray ['d', 'e']
206202

207203
const originalArray = ['a', 'b', 'c', 'd', 'e'];
208-
const resultArray = immutableArrays.splice(originalArray, 0, originalArray.length);
204+
const resultArray = splice(originalArray, 0, originalArray.length);
209205
// -> originalArray ['a', 'b', 'c', 'd', 'e']
210206
// -> resultArray []
211207

212208
const originalArray = ['a', 'b', 'c', 'd', 'e'];
213-
const resultArray = immutableArrays.splice(originalArray, 0, -3);
209+
const resultArray = splice(originalArray, 0, -3);
214210
// -> originalArray ['a', 'b', 'c', 'd', 'e']
215211
// -> resultArray ['a', 'b', 'c', 'd', 'e']
216212

217213
const originalArray = ['a', 'b', 'c', 'd', 'e'];
218-
const resultArray = immutableArrays.splice(originalArray, 0, 0, 'lorem', 'ipsum');
214+
const resultArray = splice(originalArray, 0, 0, 'lorem', 'ipsum');
219215
// -> originalArray ['a', 'b', 'c', 'd', 'e']
220216
// -> resultArray ['lorem', 'ipsum', 'a', 'b', 'c', 'd', 'e']
221217

222218
const originalArray = ['a', 'b', 'c', 'd', 'e'];
223-
const resultArray = immutableArrays.splice(originalArray, originalArray.length, 0, 'lorem', 'ipsum');
219+
const resultArray = splice(originalArray, originalArray.length, 0, 'lorem', 'ipsum');
224220
// -> originalArray ['a', 'b', 'c', 'd', 'e']
225221
// -> resultArray ['a', 'b', 'c', 'd', 'e', 'lorem', 'ipsum']
226222

227223
const originalArray = ['a', 'b', 'c', 'd', 'e'];
228-
const resultArray = immutableArrays.splice(originalArray, 0, 2, 'lorem', 'ipsum');
224+
const resultArray = splice(originalArray, 0, 2, 'lorem', 'ipsum');
229225
// -> originalArray ['a', 'b', 'c', 'd', 'e']
230226
// -> resultArray ['lorem', 'ipsum', 'c', 'd', 'e']
231227

232228
const originalArray = ['a', 'b', 'c', 'd', 'e'];
233-
const resultArray = immutableArrays.splice(originalArray, originalArray.length - 2, 2, 'lorem', 'ipsum');
229+
const resultArray = splice(originalArray, originalArray.length - 2, 2, 'lorem', 'ipsum');
234230
// -> originalArray ['a', 'b', 'c', 'd', 'e']
235231
// -> resultArray ['a', 'b', 'c', 'lorem', 'ipsum']
236232
```
237233

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

241237
**Returns**: <code>Array</code> - A new array with the element removed.
@@ -248,11 +244,11 @@ Deletes an element from an array by its index in the array.
248244
**Example**
249245
```js
250246
const originalArray = ['a', 'b', 'c', 'd', 'e'];
251-
const resultArray = immutableArrays.del(originalArray, 2);
247+
const resultArray = del(originalArray, 2);
252248
// -> originalArray ['a', 'b', 'c', 'd', 'e']
253249
// -> resultArray ['a', 'b', 'd', 'e']
254250

255-
const resultArray2 = immutableArrays.del(originalArray, -1);
251+
const resultArray2 = del(originalArray, -1);
256252
// -> originalArray ['a', 'b', 'c', 'd', 'e']
257253
// -> resultArray2 ['a', 'b', 'c', 'd', 'e']
258254
```

src/del.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
* @example
88
*
99
* const originalArray = ['a', 'b', 'c', 'd', 'e'];
10-
* const resultArray = immutableArrays.del(originalArray, 2);
10+
* const resultArray = del(originalArray, 2);
1111
* // -> originalArray ['a', 'b', 'c', 'd', 'e']
1212
* // -> resultArray ['a', 'b', 'd', 'e']
1313
*
14-
* const resultArray2 = immutableArrays.del(originalArray, -1);
14+
* const resultArray2 = del(originalArray, -1);
1515
* // -> originalArray ['a', 'b', 'c', 'd', 'e']
1616
* // -> resultArray2 ['a', 'b', 'c', 'd', 'e']
1717
*/
18-
export default function immutableDelete(array, index) {
18+
export function del(array, index) {
1919
return index >= 0 ? [...array.slice(0, index), ...array.slice(index + 1)] : [...array];
2020
}

src/index.js

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,8 @@
1-
import immutableDelete from './del';
2-
import immutablePop from './pop';
3-
import immutablePush from './push';
4-
import immutableReverse from './reverse';
5-
import immutableShift from './shift';
6-
import immutableSort from './sort';
7-
import immutableSplice from './splice';
8-
import immutableUnshift from './unshift';
9-
10-
export const del = immutableDelete;
11-
export const pop = immutablePop;
12-
export const push = immutablePush;
13-
export const reverse = immutableReverse;
14-
export const shift = immutableShift;
15-
export const sort = immutableSort;
16-
export const splice = immutableSplice;
17-
export const unshift = immutableUnshift;
18-
19-
export default {
20-
push: immutablePush,
21-
pop: immutablePop,
22-
shift: immutableShift,
23-
unshift: immutableUnshift,
24-
splice: immutableSplice,
25-
reverse: immutableReverse,
26-
sort: immutableSort,
27-
del: immutableDelete
28-
};
1+
export { del } from './del';
2+
export { pop } from './pop';
3+
export { push } from './push';
4+
export { reverse } from './reverse';
5+
export { shift } from './shift';
6+
export { sort } from './sort';
7+
export { splice } from './splice';
8+
export { unshift } from './unshift';

src/pop.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
* @example
88
*
99
* const originalArray = ['a', 'b', 'c', 'd', 'e'];
10-
* const resultArray = immutablePop(originalArray);
10+
* const resultArray = pop(originalArray);
1111
* // -> originalArray ['a', 'b', 'c', 'd', 'e']
1212
* // -> resultArray ['a', 'b', 'c', 'd']
1313
*/
14-
export default function immutablePop(array) {
14+
export function pop(array) {
1515
return array.slice(0, -1);
1616
}

src/push.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
* @example
99
*
1010
* const originalArray = ['a', 'b', 'c', 'd', 'e'];
11-
* const resultArray = immutablePush(originalArray, 'f', 'g');
11+
* const resultArray = push(originalArray, 'f', 'g');
1212
* // -> originalArray ['a', 'b', 'c', 'd', 'e']
1313
* // -> resultArray ['a', 'b', 'c', 'd', 'e', 'f', 'g']
1414
*/
15-
export default function immutablePush(array, ...elementN) {
15+
export function push(array, ...elementN) {
1616
return [...array, ...elementN];
1717
}

src/reverse.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
* @example
88
*
99
* const originalArray = ['a', 'b', 'c', 'd', 'e'];
10-
* const resultArray = immutableReverse(originalArray);
10+
* const resultArray = reverse(originalArray);
1111
* // -> originalArray ['a', 'b', 'c', 'd', 'e']
1212
* // -> resultArray ['e', 'd', 'c', 'b', 'a']
1313
*/
14-
export default function immutableReverse(array) {
14+
export function reverse(array) {
1515
return [...array].reverse();
1616
}

src/shift.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
* @example
77
*
88
* const originalArray = ['a', 'b', 'c', 'd', 'e'];
9-
* const resultArray = immutableShift(originalArray);
9+
* const resultArray = shift(originalArray);
1010
* // -> originalArray ['a', 'b', 'c', 'd', 'e']
1111
* // -> resultArray ['b', 'c', 'd', 'e']
1212
*/
13-
export default function immutableShift(array) {
13+
export function shift(array) {
1414
return array.slice(1);
1515
}

src/sort.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@
1010
* const numberArray = [20, 3, 4, 10, -3, 1, 0, 5];
1111
* const stringArray = ['Blue', 'Humpback', 'Beluga'];
1212
*
13-
* const resultArray = immutableSort(numberArray, (a, b) => a - b);
13+
* const resultArray = sort(numberArray, (a, b) => a - b);
1414
* // -> numberArray [20, 3, 4, 10, -3, 1, 0, 5]
1515
* // -> resultArray [-3, 0, 1, 3, 4, 5, 10, 20]
1616
*
17-
* const resultArray = immutableSort(numberArray, (a, b) => b - a);
17+
* const resultArray = sort(numberArray, (a, b) => b - a);
1818
* // -> numberArray [20, 3, 4, 10, -3, 1, 0, 5]
1919
* // -> resultArray [20, 10, 5, 4, 3, 1, 0, -3]
2020
*
21-
* const resultArray = immutableSort(stringArray);
21+
* const resultArray = sort(stringArray);
2222
* // -> stringArray ['Blue', 'Humpback', 'Beluga']
2323
* // -> resultArray ['Beluga', 'Blue', 'Humpback']
2424
*
25-
* const resultArray = immutableSort(stringArray, (a, b) => a.toLowerCase() < b.toLowerCase());
25+
* const resultArray = sort(stringArray, (a, b) => a.toLowerCase() < b.toLowerCase());
2626
* // -> stringArray ['Blue', 'Humpback', 'Beluga']
2727
* // -> resultArray ['Humpback', 'Blue', 'Beluga']
2828
*/
29-
export default function immutableSort(array, compareFunction) {
29+
export function sort(array, compareFunction) {
3030
return [...array].sort(compareFunction);
3131
}

0 commit comments

Comments
 (0)