sort-object-value

1.0.3 • Public • Published

sort-object-value

npm GitHub PRs Welcome tylim88

🎀 0 dependency values based object keys sorting.

  • immutable
  • small footprint
  • 0 learning curve
  • 0 dependency
  • tested

Installation

npm i sort-object-value

Usage

import objSort from 'sort-object-value'
 
 const obj = {
  md: 768,
  dm: -768.965,
  sm: 576.28367,
  ms: -576,
  xs: 0,
  xl: 1200.23872,
  lx: -1200,
  lg: 992,
  gl: -992.34632,
 }

ascending sort

const ascending = objSort(obj)
 
console.log(ascending)
// output
// {
//  lx: -1200,
//  gl: -992.34632,
//  dm: -768.965,
//  ms: -576,
//  xs: 0,
//  sm: 576.28367,
//  md: 768,
//  lg: 992,
//  xl: 1200.23872,
// }

descending sort

const descending = objSort(obj,true)
 
console.log(descending)
// output
// {
//  xl: 1200.23872,
//  lg: 992,
//  md: 768,
//  sm: 576.28367,
//  xs: 0,
//  ms: -576,
//  dm: -768.965,
//  gl: -992.34632,
//  lx: -1200,
// }

Package Sidebar

Install

npm i sort-object-value

Weekly Downloads

0

Version

1.0.3

License

MIT

Unpacked Size

6.45 kB

Total Files

5

Last publish

Collaborators

  • tylim