node package manager
It’s your turn. Help us improve JavaScript. Take the 2017 JavaScript Ecosystem Survey »

sort-values

Sort Values

Last version Build Status Dependency status Dev Dependencies Status NPM Status Donate

Sort the keys of an object based in the value.

Install

npm install sort-values --save

If you want to use in the browser (powered by Browserify):

bower install sort-values --save

and later link in your HTML:

<script src="bower_components/sort-values/dist/sort-values.js"></script>

Usage

var sortValues = require('sort-values');
 
sortValues({en: 10, es: 100, it: 50}, 'desc');
//=> {es: 100, it: 50, en: 10} 
 
sortValues({en: 10, es: 100, it: 50}, 'asc');
//=> {en: 10, it: 50, es: 100} 
 
sortValues({en: 10, es: 100, it: 50});
//=> {en: 10, it: 50, es: 100} 

API

sortValues(input, mode)

input

Required Type: Object

mode

Type: String Default: asc

How to sort the object. Could be asc or desc.

Related

License

MIT © Kiko Beats