array-move
Advanced tools
Comparing version 2.2.2 to 3.0.0
@@ -39,7 +39,4 @@ declare const arrayMove: { | ||
mutate(array: unknown[], from: number, to: number): void; | ||
// TODO: Remove this for the next major release | ||
default: typeof arrayMove; | ||
}; | ||
export = arrayMove; |
12
index.js
@@ -5,8 +5,11 @@ 'use strict'; | ||
const startIndex = to < 0 ? array.length + to : to; | ||
const item = array.splice(from, 1)[0]; | ||
array.splice(startIndex, 0, item); | ||
if (startIndex >= 0 && startIndex < array.length) { | ||
const item = array.splice(from, 1)[0]; | ||
array.splice(startIndex, 0, item); | ||
} | ||
}; | ||
const arrayMove = (array, from, to) => { | ||
array = array.slice(); | ||
array = [...array]; | ||
arrayMoveMutate(array, from, to); | ||
@@ -17,5 +20,2 @@ return array; | ||
module.exports = arrayMove; | ||
// TODO: Remove this for the next major release | ||
module.exports.default = arrayMove; | ||
module.exports.mutate = arrayMoveMutate; |
{ | ||
"name": "array-move", | ||
"version": "2.2.2", | ||
"version": "3.0.0", | ||
"description": "Move an array item to a different position", | ||
@@ -14,3 +14,3 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">=8" | ||
"node": ">=10" | ||
}, | ||
@@ -17,0 +17,0 @@ "scripts": { |
4758
47