# array-move-with-pivot

> This package moves items (objects) in circular format and around a selected property which acts a pivot.

Latest version **1.0.1** (published 2022-07-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install array-move-with-pivot
pnpm add array-move-with-pivot
yarn add array-move-with-pivot
bun add array-move-with-pivot
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2022-07-07 |
| First published | 2022-07-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | ScribbleTons |
| Maintainers | scribbletons |
| Keywords | array, array-move, object, pivot, object, drag-sort, drag-drop, table |

## Links

- npm: https://www.npmjs.com/package/array-move-with-pivot
- Repository: https://github.com/ScribbleTons/array-move-with-pivot
- Homepage: https://github.com/ScribbleTons/array-move-with-pivot#readme
- Issues: https://github.com/ScribbleTons/array-move-with-pivot/issues
- npm.io page: https://npm.io/package/array-move-with-pivot

## Alternatives

- [@lexical/table](https://npm.io/package/@lexical/table.md) — 3.0M weekly downloads
- [mantine-datatable](https://npm.io/package/mantine-datatable.md) — 98.2K weekly downloads
- [react-native-collapsible-tab-view](https://npm.io/package/react-native-collapsible-tab-view.md) — 70.6K weekly downloads
- [@handsontable/vue3](https://npm.io/package/@handsontable/vue3.md) — 16.1K weekly downloads
- [vuewordcloud](https://npm.io/package/vuewordcloud.md) — 7.2K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2022-07-07
- 1.0.0 — 2022-07-07

## README

# array-move-with-pivot

This is a simple javaScript utility function for moving objects in an array with a property as a rotation point called `pivot`.

This function is handy when dragging and rearrange objects on a table.

if array [1, 2, 3, 4] 
After dragging value 3 to position of value 1 
We have [3, 1, 2, 4] 


### installation

```
npm i --save array-move-with-pivot

or 

yarn add array-move-with-pivot
```


## Use Case

```
// I have an array of objects and I need to move objects
// in circular manner around a property of the objects.

type User = {
      id: number;
      name: string;
      position: number;
    }

const rawData: User[] = [
      { id: 11, name: "Ekene", position: 1},
      { id: 12, name: "Akunna", position: 2 },
      { id: 30, name: "Chidimna", position: 3 },
    ];

```

I want to move any user from one position to another
without altering the `position` property

```
// for example moving user at index 2 to 0

// expected result

    const newData = [
      { id: 30, name: "Chidimna", position: 1},
      { id: 11, name: "Ekene", position: 2 },
      {  id: 12, name: "Akunna", position: 3 },
    ];
```

### Usage

```
import moveArrayItemsWithPivot from 'array-move-with-pivot'

const rawData: User[] = [
      { id: 11, name: "Ekene", position: 1},
      { id: 12, name: "Akunna", position: 2 },
      { id: 30, name: "Chidimna", position: 3 },
    ];

const result = moveArrayItemsWithPivot(rawData,2,0,"position");

console.log(result) //  [{ id: 30, name: "Chidimna", position: 1}, { id: 11, name: "Ekene", position: 2 }, {  id: 12, name: "Akunna", position: 3 }];

```
#### Note
> It is not a named export, you can import with your chosen name e.g arrayMove, moveArrayItems, etc.

---
_Source: https://npm.io/package/array-move-with-pivot · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
