immutable-array-methods
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -60,2 +60,6 @@ "use strict"; | ||
exports.default = { push: push, pop: pop, shift: shift, unshift: unshift, splice: splice, set: set, flatten: flatten, map: map }; | ||
var move = exports.move = function move(array, fromIndex, toIndex) { | ||
return splice(splice(array, fromIndex, 1), toIndex, 0, array[fromIndex]); | ||
}; | ||
exports.default = { push: push, pop: pop, shift: shift, unshift: unshift, splice: splice, set: set, flatten: flatten, map: map, move: move }; |
@@ -19,2 +19,7 @@ var methods = require('./'); | ||
result = methods.move([1, 2, 3], 0, 1); | ||
console.log('move()'); | ||
console.log('input is unchanged', input); | ||
console.log('result', result); | ||
// also available is .push(), .shift(), .unshift(), .set() |
11
index.js
@@ -40,2 +40,11 @@ const setMultiple = (array, index, items) => | ||
export default {push, pop, shift, unshift, splice, set, flatten, map}; | ||
export const move = (array, fromIndex, toIndex) => { | ||
return splice( | ||
splice(array, fromIndex, 1), | ||
toIndex, | ||
0, | ||
array[fromIndex] | ||
); | ||
}; | ||
export default {push, pop, shift, unshift, splice, set, flatten, map, move}; |
{ | ||
"name": "immutable-array-methods", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Immutable versions of normally mutable array methods, such as pop(), push(), splice()", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -34,2 +34,7 @@ # immutable-array-methods [![Build Status](https://travis-ci.org/micnews/immutable-array-methods.png?branch=master)](https://travis-ci.org/micnews/immutable-array-methods) | ||
result = methods.move([1, 2, 3], 0, 1); | ||
console.log('move()'); | ||
console.log('input is unchanged', input); | ||
console.log('result', result); | ||
// also available is .push(), .shift(), .unshift(), .set() | ||
@@ -36,0 +41,0 @@ |
29
test.js
import test from 'ava'; | ||
import 'babel-core/register'; | ||
import {push, pop, unshift, shift, splice, set, flatten, map} from './index'; | ||
import {push, pop, unshift, shift, splice, set, flatten, map, move} from './index'; | ||
import arrayMethods from './index'; | ||
@@ -87,2 +87,29 @@ | ||
test('move() forward', t => { | ||
const input = [1, 2, 3]; | ||
const from = 0; | ||
const to = 1; | ||
const actual = move(input, from, to); | ||
const expected = [2, 1, 3]; | ||
t.deepEqual(actual, expected); | ||
}); | ||
test('move() backward', t => { | ||
const input = [1, 2, 3]; | ||
const from = 1; | ||
const to = 0; | ||
const actual = move(input, from, to); | ||
const expected = [2, 1, 3]; | ||
t.deepEqual(actual, expected); | ||
}); | ||
test('move() multiple indexes length', t => { | ||
const input = [1, 2, 3]; | ||
const from = 0; | ||
const to = 2; | ||
const actual = move(input, from, to); | ||
const expected = [2, 3, 1]; | ||
t.deepEqual(actual, expected); | ||
}); | ||
test('default import', t => { | ||
@@ -89,0 +116,0 @@ t.is(arrayMethods.push, push); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10091
211
68
1