Skip to content

Sort objects and arrays of objects nested deeply within other objects or arrays

License

Notifications You must be signed in to change notification settings

shantmarouti/sort-deep-object-arrays

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Note: Not maintained

sort-deep-object-arrays

NPM version Travis-CI

Sort objects and arrays of objects nested deeply within other objects or arrays

Requirements

Usage

Install as a local dependency for your project:

yarn add sort-deep-object-arrays

Run in command line

npx sort-deep-object-arrays /path/to/input/file.json

Require and use it in your code:

const sortDeepObjectArrays = require('sort-deep-object-arrays');

const myUnsortedObject = {
    b: 2,
    a: 1,
    d: [3, 5, 1],
    c: 3,
    e: [
        {
            f: 7,
            g: 8,
            h: 9
        },
        {
            g: 2,
            h: 3,
            f: 1
        },
        {
            g: 5,
            f: 4,
            h: 6
        }
    ]
};

const mySortedObject = sortDeepObjectArrays(myUnsortedObject);

console.log(JSON.stringify(mySortedObject, null, 2));

This should output:

{
  "a": 1,
  "b": 2,
  "c": 3,
  "d": [
    1,
    3,
    5
  ],
  "e": [
    {
      "f": 1,
      "g": 2,
      "h": 3
    },
    {
      "f": 4,
      "g": 5,
      "h": 6
    },
    {
      "f": 7,
      "g": 8,
      "h": 9
    }
  ]
}

Tests

Run tests with npm test. Written in tape. Automatically tested using Travis CI

Tests run against Node 0.12, 4, 6, 8, 10 and 12.

About

Sort objects and arrays of objects nested deeply within other objects or arrays

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%