{"id":17256147,"url":"https://github.com/jalal246/move-position","last_synced_at":"2025-06-23T15:34:41.789Z","repository":{"id":37963998,"uuid":"244382900","full_name":"jalal246/move-position","owner":"jalal246","description":"Move element(s) with one/multips arrays(s)","archived":false,"fork":false,"pushed_at":"2022-09-01T16:30:41.000Z","size":101,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-19T02:53:10.861Z","etag":null,"topics":["array","array-helper","array-item","array-manipulations","array-map","array-methods","array-utils","flatten","index","move","move-position","package-sorter","position","swap","toarray","tools","utility"],"latest_commit_sha":null,"homepage":"https://jalal246.github.io/move-position/","language":"JavaScript","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/jalal246.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-03-02T13:51:49.000Z","updated_at":"2023-10-22T14:51:15.000Z","dependencies_parsed_at":"2022-09-16T13:10:44.338Z","dependency_job_id":null,"html_url":"https://github.com/jalal246/move-position","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/jalal246/move-position","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jalal246%2Fmove-position","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jalal246%2Fmove-position/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jalal246%2Fmove-position/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jalal246%2Fmove-position/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jalal246","download_url":"https://codeload.github.com/jalal246/move-position/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jalal246%2Fmove-position/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261434110,"owners_count":23157201,"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","array-helper","array-item","array-manipulations","array-map","array-methods","array-utils","flatten","index","move","move-position","package-sorter","position","swap","toarray","tools","utility"],"created_at":"2024-10-15T07:13:43.992Z","updated_at":"2025-06-23T15:34:41.765Z","avatar_url":"https://github.com/jalal246.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# move-position\n\n\u003e Move element in a given array from one index to another ..with some extra\n\u003e functions.\n\n```bash\nnpm install move-position\n```\n\n## API\n\n- [move](#move)\n- [getDiff](#getDiff)\n- [compareBoth](#compareBoth)\n- [flatten](#flatten)\n- [toArray](#toArray)\n\n## move\n\n\u003e Moves element form one index to another with ability to fill each position and\n\u003e mutate the input array.\n\n```js\nfunction move\u003cT\u003e(\n  arr: T[] = [],\n  movingMap: ArrayRange | ArrayRange[],\n  Opts\u003cT\u003e = {}\n)\n```\n\n- `ArrayRange` object contains:\n\n  - `from: number` - Target index.\n  - `to: number` - Destination index.\n\n- `Opts` object contains:\n\n  - `isMutate?: boolean` - Default `true` - Mutate array input or create new one.\n  - `isDuplicate?: boolean` - Default `false` - Duplicate the traveled element or not.\n  - `isSwap?: boolean` - Default `false` - Swap between array elements.\n  - `fill?: T` - Fill the original position with a value.\n\n### Example - `move`\n\nTrying default options:\n\n```js\nconst INPUT = [\"first\", \"second\", \"third\", \"fourth\"];\n\nconst movingMap = [{ from: 0, to: 3 }];\nconst result = move(INPUT, movingMap);\n\n\u003e\u003e result= [\"fourth\", \"second\", \"third\", \"first\"];\n```\n\nEnables `isDuplicate:true`:\n\n```js\nconst INPUT = [\"first\", \"second\", \"third\", \"fourth\"];\n\nconst movingMap = [{ from: 0, to: 3 }];\nconst result = move(INPUT, movingMap, { isDuplicate: true });\n\n//\n\u003e\u003e result= [\"first\", \"second\", \"third\", \"first\"];\n```\n\nWith nullish:\n\n```js\nconst INPUT = [\"first\", \"second\", \"third\", \"fourth\"];\n\nconst movingMap = [{ from: 0, to: 3 }];\nconst result = move(INPUT, movingMap, {\n  isDuplicate: false,\n  isSwap: false,\n});\n\n\u003e\u003e result = [null, \"second\", \"third\", \"first\"];\n```\n\nWith custom fill:\n\n```js\nconst INPUT = [\"first\", \"second\", \"third\", \"fourth\"];\n\nconst movingMap = [{ from: 0, to: 3 }];\nconst result = move(INPUT, movingMap, {\n  fill: \"emptiness\"\n});\n\n\u003e\u003e result = [\"emptiness\", \"second\", \"third\", \"first\"];\n```\n\n## compare\n\n\u003e Compare elements of the first array with the rest of arrays.\n\n```js\nfunction compare\u003cT\u003e(...args: T[][])\n```\n\n### Example - `compare`\n\n```js\nconst diff = compare([\"a\", \"b\", \"c\"], [\"b\", \"c\", \"e\"]);\n\n\u003e diff = [\"a\"]\n```\n\n## compareBoth\n\n\u003e Compare elements in all inputs and gets the difference.\n\n```js\nfunction compareBoth\u003cT\u003e(...args: T[][])\n```\n\n### Example - `compareBoth`\n\n```js\nconst allDiff = compareBoth([\"a\", \"b\", \"c\"], [\"b\", \"c\", \"e\"]);\n\n\u003e allDiff = [\"a\", \"e\"]\n```\n\n## flatten\n\n\u003e Flatten an array\n\n```js\nfunction flatten\u003cT\u003e(unFlatten: T[])\n```\n\n### Example - `flatten`\n\n```js\nconst flattened = flatten([[1, [2, 3]], [1, [2, 3]], 0]);\n\n\u003e flattened = [1, 2, 3, 1, 2, 3, 0]\n```\n\n## toArray\n\n\u003e Convert an input to array\n\n```js\nfunction flatten\u003cT\u003e(unFlatten: T[])\n```\n\n### Example - `toArray`\n\n```js\nconst array = toArray(\"a\");\n\n\u003e array = [\"a\"]\n```\n\n## Tests\n\n```sh\nnpm test\n```\n\n## License\n\nThis project is licensed under the [MIT](https://github.com/jalal246/move-position/blob/master/LICENSE)\n\n### Related projects\n\n- [builderz](https://github.com/jalal246/builderz) - Zero Configuration JS bundler.\n\n- [validate-access](https://github.com/jalal246/https://github.com/jalal246/validate-access) - Utility functions, parse and validate a given directory with multiple entries.\n\n- [get-info](https://github.com/jalal246/get-info) - Utility functions for projects production.\n\n- [textics](https://github.com/jalal246/textics) \u0026\n  [textics-stream](https://github.com/jalal246/textics-stream) - Counts lines,\n  words, chars and spaces for a given string.\n\n\u003e Support this package by giving it a Star ⭐\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjalal246%2Fmove-position","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjalal246%2Fmove-position","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjalal246%2Fmove-position/lists"}