Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

just-order-by

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

just-order-by

Produces a new array, sorted in given order

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

just-order-by

Part of a library of zero-dependency npm modules that do just do one thing. Guilt-free utilities for every occasion.

🍦 Try it

npm install just-order-by
yarn add just-order-by

Produces a new array, sorted in given order

import orderBy from 'just-order-by';

orderBy([10, 1, 5, 20, 15, 35, 30, 6, 8]); // [1, 5, 6, 8, 10, 15, 20, 30, 35]

orderBy(
  [
    { user: 'fabio', details: { city: 'Milan', age: 34 } },
    { user: 'max', details: { city: 'Munich', age: 29 } },
    { user: 'zacarias', details: { city: 'Sao Paulo', age: 44 } },
    { user: 'robert', details: { city: 'Manchester', age: 28 } },
    { user: 'max', details: { city: 'Zurich', age: 38 } },
  ],
  [
    {
      property(v) {
        return v.details.age;
      },
    },
  ]
);

/*
[
  {user: 'robert', age: 28},
  {user: 'max', age: 29},
  {user: 'fabio', age: 34},
  {user: 'klaus', age: 38},
  {user: 'zacarias', age: 44},
]
*/

orderBy(
  [
    {user: 'fabio', age: 34},
    {user: 'max', age: 29},
    {user: 'zacarias', age: 44},
    {user: 'robert', age: 28},
    {user: 'klaus', age: 38},
  ],
  [
    {
      property: 'user',
    },
  ]
);

/*
[
  {user: 'fabio', age: 34},
  {user: 'klaus', age: 38},
  {user: 'max', age: 29},
  {user: 'robert', age: 28},
  {user: 'zacarias', age: 44},
]
*/

orderBy(
  [
    { user: 'fabio', age: 34 },
    { user: 'max', age: 29 },
    { user: 'zacarias', age: 44 },
    { user: 'moris', age: 28 },
    { user: 'max', age: 38 },
  ],
  [
    {
      property: 'user',
      order: 'desc',
    },
    {
      property(v) {
        return v.age;
      },
    },
  ]
);

/*
[
  {
    user: 'zacarias',
    age: 44
  },
  {
    user: 'moris',
    age: 28
  },
  {
    user: 'max',
    age: 29
  },
  {
    user: 'max',
    age: 38
  },
  {
    user: 'fabio',
    age: 34
  }
]
*/

Keywords

FAQs

Package last updated on 26 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc