Socket
Socket
Sign inDemoInstall

js-shortcuts

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    js-shortcuts

Shortcuts for JavaScript operations


Version published
Weekly downloads
0
Maintainers
1
Created
Weekly downloads
 

Readme

Source

js-shortcuts

It is a shortcut package for performing different JavaScript operations.

Installing

$ npm install js-shortcuts

For sorting

const sort = require('js-shortcuts').sort;

For array with elements

const sort = require('js-shortcuts').sort;

let arr = [3, 2, 1, 4, 5];
let sorted_array = sort(arr);


For array with objects

const sort = require('js-shortcuts').sort;

let arr = [
  {
    id: 3,
    age: 21,
    name: 'Robert'
  },
  {
    id: 1,
    age: 25,
    name: 'John'  
  },
  {
    id: 2,
    age: 20,
    name: 'Jeff'
  }
];
Sorting by id
let sorted_array = sort(arr, {property: ['id']});
Sorting by name
let sorted_array = sort(arr, {property: ['name']});
Sorting array with property inside parent object

Example: Sorting array with 'name' property

const sort = require('js-shortcuts').sort;

let arr = [
  {
    id: 2,
    email: 'robert@xxx.com',
    profile: {
      name: 'Robert',
      age: 23
    }
  },
  {
    id: 1,
    email: 'john@xxx.com',
    profile: {
      name: 'John',
      age: 24
    }
  }
];
let sorted_array = sort(arr, {property: ['profile', 'name']});

Additional attributes

Additional attribute can be provided to sort function for Ascending Order and Descending Order

sort(arr, {
  order: 'asce',
  property: ['id']
});

'asce' or 'ASCE' for Ascending Order and 'desc' or 'DESC' for Descending Order.

The default order is always Ascending Order

Keywords

FAQs

Last updated on 16 Feb 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc