array-move
Advanced tools
Comparing version 1.0.0 to 2.0.0
19
index.js
'use strict'; | ||
function arrayMove(x, from, to) { | ||
x.splice((to < 0 ? x.length + to : to), 0, x.splice(from, 1)[0]); | ||
} | ||
const arrayMoveMutate = (array, from, to) => { | ||
array.splice((to < 0 ? array.length + to : to), 0, array.splice(from, 1)[0]); | ||
}; | ||
module.exports = function (x, from, to) { | ||
x = x.slice(); | ||
arrayMove(x, from, to); | ||
return x; | ||
const arrayMove = (array, from, to) => { | ||
array = array.slice(); | ||
arrayMoveMutate(array, from, to); | ||
return array; | ||
}; | ||
module.exports.mut = arrayMove; | ||
module.exports = arrayMove; | ||
module.exports.default = arrayMove; | ||
module.exports.mutate = arrayMoveMutate; |
{ | ||
"name": "array-move", | ||
"version": "1.0.0", | ||
"description": "Move an array item to a different position", | ||
"license": "MIT", | ||
"repository": "sindresorhus/array-move", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"array", | ||
"arr", | ||
"move", | ||
"change", | ||
"position", | ||
"index" | ||
], | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
} | ||
"name": "array-move", | ||
"version": "2.0.0", | ||
"description": "Move an array item to a different position", | ||
"license": "MIT", | ||
"repository": "sindresorhus/array-move", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava && tsd-check" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"keywords": [ | ||
"array", | ||
"move", | ||
"change", | ||
"position", | ||
"index" | ||
], | ||
"devDependencies": { | ||
"ava": "^1.3.1", | ||
"tsd-check": "^0.6.0", | ||
"xo": "^0.24.0" | ||
} | ||
} |
@@ -9,3 +9,3 @@ # array-move [![Build Status](https://travis-ci.org/sindresorhus/array-move.svg?branch=master)](https://travis-ci.org/sindresorhus/array-move) | ||
``` | ||
$ npm install --save array-move | ||
$ npm install array-move | ||
``` | ||
@@ -17,5 +17,5 @@ | ||
```js | ||
var arrayMove = require('array-move'); | ||
const arrayMove = require('array-move'); | ||
var input = ['a', 'b', 'c']; | ||
const input = ['a', 'b', 'c']; | ||
@@ -35,14 +35,13 @@ arrayMove(input, 1, 2); | ||
### arrayMove(input, from, to) | ||
### arrayMove(array, from, to) | ||
Returns a new array with the item moved to the new position. | ||
### arrayMove.mut(input, from, to) | ||
### arrayMove.mutate(array, from, to) | ||
Moves the item to the new position in the input array. | ||
Useful for huge arrays where absolute performance is needed. | ||
Moves the item to the new position in the `array` array. Useful for huge arrays where absolute performance is needed. | ||
#### input | ||
#### array | ||
Type: `array` | ||
Type: `Array` | ||
@@ -53,4 +52,3 @@ #### from | ||
Index of item to move. | ||
If negative, it will begin that many elements from the end. | ||
Index of item to move. If negative, it will begin that many elements from the end. | ||
@@ -61,4 +59,3 @@ #### to | ||
Index of where to move the item. | ||
If negative, it will begin that many elements from the end. | ||
Index of where to move the item. If negative, it will begin that many elements from the end. | ||
@@ -65,0 +62,0 @@ |
Sorry, the diff of this file is not supported yet
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
4271
5
41
0
3
61