New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

move-sort

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

move-sort

Switch an array item's index and get a new sorted array.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
37
increased by208.33%
Maintainers
1
Weekly downloads
 
Created
Source

move-sort

Build Status

Switch an array item's index and get a new sorted array.

Install

$ yarn add move-sort

or

$ npm install move-sort --save

or include the UMD build, hosted by unpkg in a <script> tag.

<script src="//unpkg.com/move-sort" />

Usage

// ES6 (check out the tests for more examples)
import moveSort from "move-sort"
const items = ["a", "b", "c", "d", "e"]
const sortedItems = moveSort(items, 4, 0)

console.log(sortedItems) // returns ["e", "a", "b", "c", "d"]
// Browser (include the UMD build in a <script> tag as shown above)
const items = ["a", "b", "c", "d", "e"]
const sortedItems = MoveSort(items, 1, 3)
// or
const sortedItems = window.MoveSort(items, 1, 3)
console.log(sortedItems) // returns ["a", "c", "d", "b", "e"]

Note: move-sort always generates a new array, and will never mutate the original array you pass into it.

API

moveSort(items, startIndex, endIndex)

items

Type: Array

Default: []

The original array you want to generate a sorted array for.

startIndex

Type: integer

Default: 0

The index of the inital element in the array you want to move.

endIndex

Type: integer

Default: 0

The target index of the inital element in the array you want to move it to.

Index constraints

The start and end index arguments are run through parseInt() and clamped to the bounds of the items array. Indexes less than 0 will become 0 and indexes greater than (items.length - 1) will become (items.length - 1).

Development

# To run the tests
$ npm test
# or
$ npm run watch-test

# To publish the dist files
$ npm run build

License

MIT © Collin Henderson

FAQs

Package last updated on 06 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc