@@ -7,7 +7,7 @@ Immutable versions of normally mutable array methods
77[ ![ npm downloads] ( https://img.shields.io/npm/dt/immutable-arrays.svg )] ( http://badge.fury.io/js/immutable-arrays )
88[ ![ npm license] ( https://img.shields.io/npm/l/immutable-arrays.svg )] ( http://badge.fury.io/js/immutable-arrays )
99[ ![ PRs Welcome] ( https://img.shields.io/badge/PRs-welcome-brightgreen.svg )] ( http://makeapullrequest.com )
10- [ ![ Code Climate ] ( https://codeclimate.com/github/georapbox/immutable-arrays/ badges/gpa.svg )] ( https://codeclimate.com/github/georapbox/immutable-arrays )
10+ [ ![ Maintainability ] ( https://api. codeclimate.com/v1/ badges/a9558f63e22c3e89d06c/maintainability )] ( https://codeclimate.com/github/georapbox/immutable-arrays/maintainability )
1111[ ![ Issue Count] ( https://codeclimate.com/github/georapbox/immutable-arrays/badges/issue_count.svg )] ( https://codeclimate.com/github/georapbox/immutable-arrays )
1212[ ![ Codecov] ( https://img.shields.io/codecov/c/github/georapbox/immutable-arrays/master.svg )] ( https://codecov.io/gh/georapbox/immutable-arrays )
1313[ ![ Dependencies] ( https://david-dm.org/georapbox/immutable-arrays.svg )] ( https://david-dm.org/georapbox/immutable-arrays )
@@ -16,65 +16,77 @@ Immutable versions of normally mutable array methods
1616## Install
1717
1818``` sh
19- $ npm install immutable-arrays
19+ $ npm install --save immutable-arrays
2020```
2121
2222## Usage
2323
2424### Old school browser global
2525``` html
2626<script src =" immutable-arrays/lib/immutableArrays.min.js" ></script >
27- <script >
28- var res = immutableArrays .push ([1 , 2 , 3 , 4 ], 10 );
29- </script >
3027```
3128
3229### Node.js
3330``` js
34- var immutableArrays = require (' immutable-arrays' );
35- var res = immutableArrays .push ([1 , 2 , 3 , 4 ], 10 );
31+ const immutableArrays = require (' immutable-arrays' );
3632```
3733
38- ### ES6 imports
34+ ### ES2015 imports
3935
40- #### Importing defaults
36+ #### Import default export
4137
4238``` js
4339import immutableArrays from ' immutable-arrays' ;
44- const res = immutableArrays .push ([1 , 2 , 3 , 4 ], 10 );
4540```
4641
47- #### Importing a single method
42+ #### Import a single export
4843
4944``` js
5045import {push } from ' immutable-arrays' ;
51- const res = push ([ 1 , 2 , 3 , 4 ], 10 );
46+ ```
5247
53- // or
48+ #### Import multiple exports
5449
55- import {push as immutablePush } from ' immutable-arrays' ;
56- const res = immutablePush ([1 , 2 , 3 , 4 ], 10 );
50+ ``` js
51+ import {push , pop , shift } from ' immutable-arrays' ;
52+ ```
53+
54+ #### Import ES2015 (uncompiled) method from source
55+
56+ ``` js
57+ import push from ' immutable-arrays/src/immutable-push' ;
5758```
5859
5960## API
6061
6162<dl >
62- <dt ><a href =" #immutableArrays.push " >immutableArrays.push(array, ...elementN)</a > ⇒ <code >Array</code ></dt >
63- <dd ><p >Adds one or more elements to the end of an array by returning a new array instead of mutating the original one.</p ></dd >
64- <dt ><a href =" #immutableArrays.pop " >immutableArrays.pop(array)</a > ⇒ <code >Array</code ></dt >
65- <dd ><p >Removes the last element from an array by returning a new array instead of mutating the original one.</p ></dd >
66- <dt ><a href =" #immutableArrays.del " >immutableArrays.del(array, index)</a > ⇒ <code >Array</code ></dt >
67- <dd ><p >Deletes an element from an array by its index in the array.</p ></dd >
68- <dt ><a href =" #immutableArrays.shift " >immutableArrays.shift(array)</a > ⇒ <code >Array</code ></dt >
69- <dd ><p >Removes the first element from an array.</p ></dd >
70- <dt ><a href =" #immutableArrays.unshift " >immutableArrays.unshift(array, ...elementN)</a > ⇒ <code >Array</code ></dt >
71- <dd ><p >Adds one or more elements to the beginning of an array.</p ></dd >
72- <dt ><a href =" #immutableArrays.reverse " >immutableArrays.reverse(array)</a > ⇒ <code >Array</code ></dt >
73- <dd ><p >Reverses an array (not in place). The first array element becomes the last, and the last array element becomes the first.</p ></dd >
74- <dt ><a href =" #immutableArrays.sort " >immutableArrays.sort(array, [compareFunction])</a > ⇒ <code >Array</code ></dt >
75- <dd ><p >Sorts the elements of an array (not in place) and returns a sorted array.</p ></dd >
76- <dt ><a href =" #immutableArrays.splice " >immutableArrays.splice(array, [start], [deleteCount], [...elementN])</a > ⇒ <code >Array</code ></dt >
77- <dd ><p >Removes existing elements and/or adds new elements to an array.</p ></dd >
63+ <dt ><a href =" #immutableArrays.push " >immutableArrays.push(array, ...elementN)</a > ⇒ <code >Array</code ></dt >
64+ <dd ><p >Adds one or more elements to the end of an array by returning a new array instead of mutating the original one.</p ></dd >
65+
66+ <dt ><a href =" #immutableArrays.pop " >immutableArrays.pop(array)</a > ⇒ <code >Array</code ></dt >
67+ <dd ><p >Removes the last element from an array by returning a new array instead of mutating the original one.</p ></dd >
68+
69+ <dt ><a href =" #immutableArrays.shift " >immutableArrays.shift(array)</a > ⇒ <code >Array</code ></dt >
70+ <dd ><p >Removes the first element from an array.</p ></dd >
71+
72+ <dt ><a href =" #immutableArrays.unshift " >immutableArrays.unshift(array, ...elementN)</a > ⇒ <code >Array</code ></dt >
73+ <dd ><p >Adds one or more elements to the beginning of an array.</p ></dd >
74+
75+ <dt ><a href =" #immutableArrays.reverse " >immutableArrays.reverse(array)</a > ⇒ <code >Array</code ></dt >
76+ <dd ><p >Reverses an array (not in place). The first array element becomes the last, and the last array element becomes the first.</p ></dd >
77+
78+ <dt ><a href =" #immutableArrays.sort " >immutableArrays.sort(array, [compareFunction])</a > ⇒ <code >Array</code ></dt >
79+ <dd ><p >Sorts the elements of an array (not in place) and returns a sorted array.</p ></dd >
80+
81+ <dt ><a href =" #immutableArrays.splice " >immutableArrays.splice(array, [start], [deleteCount], [...elementN])</a > ⇒ <code >Array</code ></dt >
82+ <dd ><p >Removes existing elements and/or adds new elements to an array.</p ></dd >
83+ </dl >
84+
85+ #### Bonus method
86+
87+ <dl >
88+ <dt ><a href =" #immutableArrays.del " >immutableArrays.del(array, index)</a > ⇒ <code >Array</code ></dt >
89+ <dd ><p >Deletes an element from an array by its index in the array.</p ></dd >
7890</dl >
7991
8092<a name =" immutableArrays.push " ></a >
@@ -118,26 +130,6 @@ const resultArray = immutableArrays.pop(originalArray);
118130// -> resultArray ['a', 'b', 'c', 'd']
119131```
120132
121- <a name =" immutableArrays.del " ></a >
122-
123- ## immutableArrays.del(array, index) ⇒ <code >Array</code >
124- Deletes an element from an array by its index in the array.
125-
126- ** Returns** : <code >Array</code > - A new array with the element removed.
127-
128- | Param | Type | Description |
129- | --- | --- | --- |
130- | array | <code >Array</code > | The original array. |
131- | index | <code >Number</code > | The index of the element to delete in the original array. |
132-
133- ** Example**
134- ``` js
135- const originalArray = [' a' , ' b' , ' c' , ' d' , ' e' ];
136- const resultArray = immutableArrays .del (originalArray, 2 );
137- // -> originalArray ['a', 'b', 'c', 'd', 'e']
138- // -> resultArray ['a', 'b', 'd', 'e']
139- ```
140-
141133<a name =" immutableArrays.shift " ></a >
142134
143135## immutableArrays.shift(array) ⇒ <code >Array</code >
@@ -293,6 +285,26 @@ const resultArray = immutableArrays.splice(originalArray, originalArray.length -
293285// -> resultArray ['a', 'b', 'c', 'lorem', 'ipsum']
294286```
295287
288+ <a name =" immutableArrays.del " ></a >
289+
290+ ## immutableArrays.del(array, index) ⇒ <code >Array</code >
291+ Deletes an element from an array by its index in the array.
292+
293+ ** Returns** : <code >Array</code > - A new array with the element removed.
294+
295+ | Param | Type | Description |
296+ | --- | --- | --- |
297+ | array | <code >Array</code > | The original array. |
298+ | index | <code >Number</code > | The index of the element to delete in the original array. |
299+
300+ ** Example**
301+ ``` js
302+ const originalArray = [' a' , ' b' , ' c' , ' d' , ' e' ];
303+ const resultArray = immutableArrays .del (originalArray, 2 );
304+ // -> originalArray ['a', 'b', 'c', 'd', 'e']
305+ // -> resultArray ['a', 'b', 'd', 'e']
306+ ```
307+
296308## Test
297309
298310``` sh
0 commit comments