Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lodash-move

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lodash-move - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

14

lib/index.js

@@ -19,4 +19,14 @@ "use strict";

*/
var itemRemovedArray = [].concat(_toConsumableArray(array.slice(0, moveIndex)), _toConsumableArray(array.slice(moveIndex + 1, array.length)));
return [].concat(_toConsumableArray(itemRemovedArray.slice(0, toIndex)), [array[moveIndex]], _toConsumableArray(itemRemovedArray.slice(toIndex, itemRemovedArray.length)));
var item = array[moveIndex];
var length = array.length;
var diff = moveIndex - toIndex;
if (diff > 0) {
// move left
return [].concat(_toConsumableArray(array.slice(0, toIndex)), [item], _toConsumableArray(array.slice(toIndex, moveIndex)), _toConsumableArray(array.slice(moveIndex + 1, length)));
} else if (diff < 0) {
// move right
return [].concat(_toConsumableArray(array.slice(0, moveIndex)), _toConsumableArray(array.slice(moveIndex + 1, toIndex + 1)), [item], _toConsumableArray(array.slice(toIndex + 1, length)));
}
return array;
}

5

package.json
{
"name": "lodash-move",
"version": "1.0.0",
"version": "1.1.0",
"description": "DRY up your common use cases in Redux.",

@@ -19,3 +19,3 @@ "repository": "https://github.com/granteagon/move",

"babel-cli": "^6.9.0",
"eslint": "^2.11.1",
"eslint": "^2.2.0",
"expect": "^1.20.1",

@@ -30,3 +30,2 @@ "babel-core": "^5.4.7",

"babel-preset-stage-0": "^6.5.0",
"eslint": "^2.2.0",
"mocha": "^2.4.5",

@@ -33,0 +32,0 @@ "nodemon": "^1.9.1",

# _.move LoDash mixin
Move an item in an array
`npm install lodash-move`
LoDash issue is [here](https://github.com/lodash/lodash/issues/1978). Give it a 👍 if you want to see it added to Lodash.

@@ -5,0 +7,0 @@

@@ -12,11 +12,24 @@ export default function move (array, moveIndex, toIndex) {

*/
let itemRemovedArray = [
...array.slice(0, moveIndex),
...array.slice(moveIndex + 1, array.length)
]
return [
...itemRemovedArray.slice(0, toIndex),
array[moveIndex],
...itemRemovedArray.slice(toIndex, itemRemovedArray.length)
]
let item = array[moveIndex];
let length = array.length;
let diff = moveIndex - toIndex;
if (diff > 0) {
// move left
return [
...array.slice(0, toIndex),
item,
...array.slice(toIndex, moveIndex),
...array.slice(moveIndex + 1, length)
];
} else if (diff < 0) {
// move right
return [
...array.slice(0, moveIndex),
...array.slice(moveIndex + 1, toIndex + 1),
item,
...array.slice(toIndex + 1, length)
];
}
return array;
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc