@drcyph3r/dynamic-sort

An easy to use dynamic sort function.

Usage no npm install needed!

<script type="module">
  import drcyph3rDynamicSort from 'https://cdn.skypack.dev/@drcyph3r/dynamic-sort';
</script>

README

Dynamic Sort

Build Status

Fast and easy way to sort an array of objects based on a property with typescript support.

Installation

npm i @drcyph3r/dynamic-sort
yarn add @drcyph3r/dynamic-sort

Usage

import dynamicsort from '@drcyph3r/dynamic-sort'

let fruits = [
  {
    id: 1,
    name: 'Apple'
  },
  {
    id: 2,
    name: 'Orange'
  }
]

// sort the fruits array by id in ascending order
const sortedArr = fruits.sort(dynamicsort('id', 'asc'))

Props

Prop Value
property key of a json object
order asc, desc

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT