Socket
Socket
Sign inDemoInstall

immutable-array-methods

Package Overview
Dependencies
Maintainers
3
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

immutable-array-methods - npm Package Compare versions

Comparing version 1.3.0 to 1.4.0

6

dist/index.js

@@ -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()

@@ -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};

2

package.json
{
"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 @@

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);

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