Giter Club home page Giter Club logo

sort-deep-object-arrays's Introduction

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.

sort-deep-object-arrays's People

Contributors

aiham avatar dependabot[bot] avatar tinder-fren avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

sort-deep-object-arrays's Issues

abiliity to specify the key i want to sort

Would be great if i could specify the key of the object i want to sort, eg:

with this object, i could sort by name, or by shortcut, or by modality, or even date, if there was createdAt field

[
    {
      name: 'NEUROCP',
      id: 1,
      children: [
        {
          name: 'Vascular Isquemico',
          id: 241,
          children: [
            {
              name: 'TITULO DO ITEM VASCULAR 1',
              id: 235,
              modality: 'RX',
              shortcut: 'roubodasubclavia1',
            },
            { name: '4443', id: 3, modality: 'US' },
          ],
        },
        { name: '4443', id: 3, modality: 'US' },
      ],
    },
    {
      name: 'Aneurismas ou estenoses',
      id: 4,
      children: [
        { name: 'asdasd', id: 5, modality: 'TC' },
        { name: '22222', id: 6, modality: 'MMG' },
      ],
    },
    {
      name: 'Abscessos, nódulos, cistos ou massas',
      id: 71,
      children: [
        {
          name: 'asdasd',
          id: 7,
          children: [
            { name: 'asdasd', id: 52, modality: 'TC' },
            { name: '22222', id: 63, modality: 'MMG' },
          ],
        },
        { name: '22222', id: 8, modality: 'RM' },
        { name: '22222', id: 9, modality: 'RM' },
      ],
    },
    {
      name: 'Esclerose Múltipla',
      id: 10,
      children: [
        { name: 'asdasd', modality: 'US', id: 11 },
        { name: '22222', modality: 'RM', id: 12 },
      ],
    },
    {
      name: 'Hemorragias no cérebro',
      id: 13,
      children: [
        { name: 'asdasd', modality: 'TC', id: 14 },
        { name: '22222', modality: 'US', id: 15 },
      ],
    },
  ],

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.