This commit is contained in:
49
node_modules/array-move/index.d.ts
generated
vendored
Normal file
49
node_modules/array-move/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
Clones the given `array`, moves the item to a new position in the new array, and then returns the new array. The given `array` is not mutated.
|
||||
|
||||
@param array - The array with the item to move.
|
||||
@param fromIndex - The index of item to move. If negative, it will begin that many elements from the end.
|
||||
@param toIndex - The index of where to move the item. If negative, it will begin that many elements from the end.
|
||||
@returns A new array with the item moved to the new position.
|
||||
|
||||
@example
|
||||
```
|
||||
import {arrayMoveImmutable} from 'array-move';
|
||||
|
||||
const input = ['a', 'b', 'c'];
|
||||
|
||||
const array1 = arrayMoveImmutable(input, 1, 2);
|
||||
console.log(array1);
|
||||
//=> ['a', 'c', 'b']
|
||||
|
||||
const array2 = arrayMoveImmutable(input, -1, 0);
|
||||
console.log(array2);
|
||||
//=> ['c', 'a', 'b']
|
||||
|
||||
const array3 = arrayMoveImmutable(input, -2, -3);
|
||||
console.log(array3);
|
||||
//=> ['b', 'a', 'c']
|
||||
```
|
||||
*/
|
||||
export function arrayMoveImmutable<ValueType>(array: readonly ValueType[], fromIndex: number, toIndex: number): ValueType[];
|
||||
|
||||
/**
|
||||
Moves the item to the new position in the input array. Useful for huge arrays where absolute performance is needed.
|
||||
|
||||
@param array - The array to modify.
|
||||
@param fromIndex - The index of item to move. If negative, it will begin that many elements from the end.
|
||||
@param toIndex - The index of where to move the item. If negative, it will begin that many elements from the end.
|
||||
|
||||
@example
|
||||
```
|
||||
import {arrayMoveMutable} from 'array-move';
|
||||
|
||||
const input = ['a', 'b', 'c'];
|
||||
|
||||
arrayMoveMutable(input, 1, 2);
|
||||
|
||||
console.log(input);
|
||||
//=> ['a', 'c', 'b']
|
||||
```
|
||||
*/
|
||||
export function arrayMoveMutable(array: unknown[], fromIndex: number, toIndex: number): void;
|
||||
16
node_modules/array-move/index.js
generated
vendored
Normal file
16
node_modules/array-move/index.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
export function arrayMoveMutable(array, fromIndex, toIndex) {
|
||||
const startIndex = fromIndex < 0 ? array.length + fromIndex : fromIndex;
|
||||
|
||||
if (startIndex >= 0 && startIndex < array.length) {
|
||||
const endIndex = toIndex < 0 ? array.length + toIndex : toIndex;
|
||||
|
||||
const [item] = array.splice(fromIndex, 1);
|
||||
array.splice(endIndex, 0, item);
|
||||
}
|
||||
}
|
||||
|
||||
export function arrayMoveImmutable(array, fromIndex, toIndex) {
|
||||
array = [...array];
|
||||
arrayMoveMutable(array, fromIndex, toIndex);
|
||||
return array;
|
||||
}
|
||||
9
node_modules/array-move/license
generated
vendored
Normal file
9
node_modules/array-move/license
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
37
node_modules/array-move/package.json
generated
vendored
Normal file
37
node_modules/array-move/package.json
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "array-move",
|
||||
"version": "4.0.0",
|
||||
"description": "Move an array item to a different position",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/array-move",
|
||||
"funding": "https://github.com/sponsors/sindresorhus",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "https://sindresorhus.com"
|
||||
},
|
||||
"type": "module",
|
||||
"exports": "./index.js",
|
||||
"engines": {
|
||||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"array",
|
||||
"move",
|
||||
"change",
|
||||
"position",
|
||||
"index"
|
||||
],
|
||||
"devDependencies": {
|
||||
"ava": "^3.15.0",
|
||||
"tsd": "^0.17.0",
|
||||
"xo": "^0.44.0"
|
||||
}
|
||||
}
|
||||
59
node_modules/array-move/readme.md
generated
vendored
Normal file
59
node_modules/array-move/readme.md
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
# array-move
|
||||
|
||||
> Move an array item to a different position
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install array-move
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import {arrayMoveImmutable} from 'array-move';
|
||||
|
||||
const input = ['a', 'b', 'c'];
|
||||
|
||||
const array1 = arrayMoveImmutable(input, 1, 2);
|
||||
console.log(array1);
|
||||
//=> ['a', 'c', 'b']
|
||||
|
||||
const array2 = arrayMoveImmutable(input, -1, 0);
|
||||
console.log(array2);
|
||||
//=> ['c', 'a', 'b']
|
||||
|
||||
const array3 = arrayMoveImmutable(input, -2, -3);
|
||||
console.log(array3);
|
||||
//=> ['b', 'a', 'c']
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### arrayMoveImmutable(array, fromIndex, toIndex)
|
||||
|
||||
Clones the given `array`, moves the item to a new position in the new array, and then returns the new array. The given `array` is not mutated.
|
||||
|
||||
### arrayMoveMutable(array, fromIndex, toIndex)
|
||||
|
||||
Moves the item to the new position in the `array` array. Useful for huge arrays where absolute performance is needed.
|
||||
|
||||
#### array
|
||||
|
||||
Type: `Array`
|
||||
|
||||
#### fromIndex
|
||||
|
||||
Type: `number`
|
||||
|
||||
The index of item to move.
|
||||
|
||||
If negative, it will begin that many elements from the end.
|
||||
|
||||
#### toIndex
|
||||
|
||||
Type: `number`
|
||||
|
||||
The index of where to move the item.
|
||||
|
||||
If negative, it will begin that many elements from the end.
|
||||
Reference in New Issue
Block a user