{"id":20101792,"url":"https://github.com/drenther/array-move-slice","last_synced_at":"2025-05-06T06:33:49.217Z","repository":{"id":42726310,"uuid":"284543232","full_name":"drenther/array-move-slice","owner":"drenther","description":"A tiny utility to move a slice of an array from one starting index to another within the same array","archived":false,"fork":false,"pushed_at":"2023-07-11T03:39:00.000Z","size":209,"stargazers_count":3,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-09-17T05:08:02.193Z","etag":null,"topics":["array","javascript","js","slice","splice","utility-library"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drenther.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-02T21:16:27.000Z","updated_at":"2023-05-04T11:49:59.000Z","dependencies_parsed_at":"2023-02-06T04:16:35.531Z","dependency_job_id":null,"html_url":"https://github.com/drenther/array-move-slice","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drenther%2Farray-move-slice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drenther%2Farray-move-slice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drenther%2Farray-move-slice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drenther%2Farray-move-slice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drenther","download_url":"https://codeload.github.com/drenther/array-move-slice/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224493818,"owners_count":17320574,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array","javascript","js","slice","splice","utility-library"],"created_at":"2024-11-13T17:26:46.046Z","updated_at":"2024-11-13T17:26:49.690Z","avatar_url":"https://github.com/drenther.png","language":"TypeScript","readme":"# array-move-slice\n\n![Bundle Size](https://badgen.net/bundlephobia/minzip/array-move-slice) ![npm version](https://badgen.net/npm/v/array-move-slice) ![types](https://badgen.net/npm/types/array-move-slice) ![license](https://badgen.net/npm/license/array-move-slice)\n\n\u003e Move a slice of an array to a different position in the array\n\nVery similar to [array-move](https://github.com/sindresorhus/array-move) but with this package you can move single element or a slice of elements (only continuous slices though). If you need to move multiple items that are not in sequence try using [array-move-multiple](https://www.npmjs.com/package/array-move-multiple)\n\n## Install\n\n```sh\n$ npm install array-move-slice\n```\n\n## Usage\n\n```js\nconst input = ['a', 'b', 'c', 'd', 'e'];\n\n// moving single item\nconst array1 = arrayMoveSlice(input, 1, 2);\nconsole.log(array1);\n// [\"a\", \"c\", \"b\", \"d\", \"e\"]\n\n// moving a slice of items\nconst array2 = arrayMoveSlice(input, 1, 2, 2);\nconsole.log(array2);\n// [\"a\", \"c\", \"d\", \"b\", \"e\"]\n\n// using -ve value to move a slice to end of the array\nconst array3 = arrayMoveSlice(input, -1, 0, 3);\nconsole.log(array3);\n// [\"d\", \"e\", \"a\", \"b\", \"c\"]\n\n// using -ve value for fromIndex to move a slice from the end of the array\nconst array4 = arrayMoveSlice(input, 0, -1, 2);\nconsole.log(array4)\n// [\"e\", \"a\", \"b\", \"c\", \"d\"]\n```\n\n## API Reference\n\n### arrayMoveSlice(array, to, from, count)\n\nClones the given `array`, moves the item / slice of items (if a non-zero `count` parameter value is passed) to a new position in the new array. The given `array` is not mutated.\n\n### arrayMoveSliceMutate(array, to, from, count)\n\nSame as `arrayMoveSlice` but it mutates the `array` passed to it. Useful for operating on huge arrays where performance can become a factor.\n\n#### Params\n\n**array** - Type `Array\u003cany\u003e` - the array to be operated on\n\n**to** - Type `number` - the index of where the item / slice of items need to be moved to. If negative, it will be used as an offset from the end (like the native `Array.prototype.slice` method).\n\n**from** - Type `number` - the index of the item / start of the slice of items that need to be moved. If negative, it will be used as an offset from the end (like the native `Array.prototype.slice` method).\n\n**count** - Type `number` or `undefined` - the number of elements to be moved in the slice. It is optional and defaults to `1`. If a value is passed, it must be more than one.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrenther%2Farray-move-slice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrenther%2Farray-move-slice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrenther%2Farray-move-slice/lists"}