{"id":16590307,"url":"https://github.com/michaelzoidl/swap-array","last_synced_at":"2025-10-29T09:32:12.173Z","repository":{"id":45134902,"uuid":"56661016","full_name":"michaelzoidl/swap-array","owner":"michaelzoidl","description":"Swaps the index / position of an array","archived":false,"fork":false,"pushed_at":"2022-01-06T03:47:02.000Z","size":8,"stargazers_count":7,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-02T00:32:00.577Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://npmjs.com/package/swap-array","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/michaelzoidl.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":"2016-04-20T06:22:04.000Z","updated_at":"2022-01-06T03:49:33.000Z","dependencies_parsed_at":"2022-07-21T06:32:33.825Z","dependency_job_id":null,"html_url":"https://github.com/michaelzoidl/swap-array","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/michaelzoidl%2Fswap-array","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelzoidl%2Fswap-array/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelzoidl%2Fswap-array/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelzoidl%2Fswap-array/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michaelzoidl","download_url":"https://codeload.github.com/michaelzoidl/swap-array/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238803342,"owners_count":19533297,"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":[],"created_at":"2024-10-11T23:12:13.726Z","updated_at":"2025-10-29T09:32:06.865Z","avatar_url":"https://github.com/michaelzoidl.png","language":"JavaScript","readme":"# Swap Array\nSwap position of two items in array without changing the state of the passed array.\n\n[![Build Status](https://travis-ci.org/michaelzoidl/swap-array.svg?branch=master)](https://travis-ci.org/michaelzoidl/swap-array)\n[![devDependency Status](https://david-dm.org/michaelzoidl/swap-array/dev-status.svg)](https://david-dm.org/michaelzoidl/babel-root-import#info=devDependencies)\n\n## Install\n```\n$ npm install swap-array --save\n```\n\n## Usage\n```js\nimport SwapArray from 'swap-array';\n\nvar SomeArray = ['thats','cool','dude'];\n\nSwapArray(SomeArray, 0, 2);\n// ['dude','thats','cool'];\n```\n\n## Does it change the passed array?\nNope, before it changes the positioning we clone the passed array and return just the new instance. Ideal for e.g. some redux-reducer where it's not allowed to change an existing state. If you want that the origin-array changes his state checkout the [array-swap](https://github.com/Marko-Jankovic/array-swap) repo from Marko Jankovic.\n\n## FAQ\n### How to import/require with old ES5 standard\nJust import it usually but attend the default prop\n```javascript\nvar SwapArray = require('swapt-array').default;\n```\n\n## Benchmark\n```\n1,149,543 op/s\n```\n\n## Contribute\n```shell\n// Run and Watch tests\n$ npm run test -- -w\n\n// Just run tests\n$ npm run test\n\n// Create new build\n$ npm run build\n\n// Run benchmark\n$ npm run bench\n```\n","funding_links":[],"categories":["Modules","模块"],"sub_categories":["Array","数组"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelzoidl%2Fswap-array","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichaelzoidl%2Fswap-array","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelzoidl%2Fswap-array/lists"}