array-move
Advanced tools
Comparing version 2.2.1 to 2.2.2
declare const arrayMove: { | ||
/** | ||
Move an array item to a different position. | ||
Clones the given `array`, moves the item to a new position in the new array, and then returns the new array. The given `array` is not mutated. | ||
@param array - The array to move the item in. | ||
@param array - The array with the item to move. | ||
@param from - Index of item to move. If negative, it will begin that many elements from the end. | ||
@@ -16,9 +16,12 @@ @param to - Index of where to move the item. If negative, it will begin that many elements from the end. | ||
arrayMove(input, 1, 2); | ||
const array1 = arrayMove(input, 1, 2); | ||
console.log(array1); | ||
//=> ['a', 'c', 'b'] | ||
arrayMove(input, -1, 0); | ||
const array2 = arrayMove(input, -1, 0); | ||
console.log(array2); | ||
//=> ['c', 'a', 'b'] | ||
arrayMove(input, -2, -3); | ||
const array3 = arrayMove(input, -2, -3); | ||
console.log(array3); | ||
//=> ['b', 'a', 'c'] | ||
@@ -25,0 +28,0 @@ ``` |
{ | ||
"name": "array-move", | ||
"version": "2.2.1", | ||
"version": "2.2.2", | ||
"description": "Move an array item to a different position", | ||
@@ -11,3 +11,3 @@ "license": "MIT", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
"url": "https://sindresorhus.com" | ||
}, | ||
@@ -14,0 +14,0 @@ "engines": { |
@@ -1,6 +0,5 @@ | ||
# array-move [![Build Status](https://travis-ci.org/sindresorhus/array-move.svg?branch=master)](https://travis-ci.org/sindresorhus/array-move) | ||
# array-move [![Build Status](https://travis-ci.com/sindresorhus/array-move.svg?branch=master)](https://travis-ci.com/github/sindresorhus/array-move) | ||
> Move an array item to a different position | ||
## Install | ||
@@ -12,3 +11,2 @@ | ||
## Usage | ||
@@ -21,13 +19,15 @@ | ||
arrayMove(input, 1, 2); | ||
const array1 = arrayMove(input, 1, 2); | ||
console.log(array1); | ||
//=> ['a', 'c', 'b'] | ||
arrayMove(input, -1, 0); | ||
const array2 = arrayMove(input, -1, 0); | ||
console.log(array2); | ||
//=> ['c', 'a', 'b'] | ||
arrayMove(input, -2, -3); | ||
const array3 = arrayMove(input, -2, -3); | ||
console.log(array3); | ||
//=> ['b', 'a', 'c'] | ||
``` | ||
## API | ||
@@ -37,3 +37,3 @@ | ||
Returns a new array with the item moved to the new position. | ||
Clones the given `array`, moves the item to a new position in the new array, and then returns the new array. The given `array` is not mutated. | ||
@@ -40,0 +40,0 @@ ### arrayMove.mutate(array, from, to) |
Sorry, the diff of this file is not supported yet
4864
49