npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sortex

v0.2.0

Published

A package for every sort

Downloads

147

Readme

sortex

sortex is an open source package created to make it easy to sort arrays based on a specific value contained in each array element. Using this package, you can easily use any sorting algorithm you want. Sort an array and get the best result and perform the fastest sort based on the state of your array.

install

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install sortex

Usage

To use sortex, you must call it according to your use of common js or es module

Common JS

const {manualSort} = require('sortex'); //common js

manualSort(StudentList, {valuePath: "score",sortAlgorithm: "quick3",});

ES Module

import {manualSort} from 'sortex'; //ES Module

manualSort(StudentList, {valuePath: "score",sortAlgorithm: "quick3",});

Features

In the following, you can see how to sort and the features of sortex

manualSort automatedSort getSpecificDatas getBiggest getSmallest

manual sort

manualSort(arr,options = {arrayCondition : '',sortAlgorithm : '',valuePath : ''})

In this method, you can manually enter the name of the algorithm that you want to sort with

  • valuePath ➜ In this parameter, you must pass the path of the value that you want the array to be sorted based on as a string to the method.For example, in this array:

        [
            {
                name : 'Abbas',
                lastName : 'Elahian',
                result : {
                    score : ['math',20],
                    grade : 12,
                }
            },
            ...
        ]

    if we want to sort the values ​​of the array based on result→score→index 1 in score array, the value of our valuePath will be result.score.1.

    ⚠️ valuePath is required! ⚠️

  • sortAlgorithm ➜ To this parameter, you must pass the name of the algorithm with which you want the sorting to be done: | Algorithm name | sortAlgorithm value | |--------|--------| | insertion sort | insertion | | selection sort | selection | | bubble sort | bubble | | merge sort | merge | | heap sort | heap | | shell sort | shell | | quick3 sort | quick3 | | quick sort | quick |

  • arrayCondition ➜ With this parameter, you can specify the state of your array so that the best algorithm is selected according to the state of your array and that algorithm is used for sorting.

    random → All values ​​of the array are distributed completely randomly and no particular order can be found in the array ・nearly sorted → The array is almost ordered, but some values ​​are not in the right place ・reversed → The array is almost in reverse order, but still some values ​​are not in the right place ・random few unique → The different values ​​of the array are several numbers that are repeated in different indexes and several values ​​use that number.

    | condition | arrayCondition value | |--------|--------| | random | random | | nearly sorted | nearly-sorted | | reversed | reversed | | random few unique | random-few-unique |

usage

import {manualSort} from 'sortex';

const StudentList = [
    {
        name: "Abbas",
        lastName: "Elahian",
        score: "20",
    },
    {
        name: "Arian",
        lastName: "Elahi",
        score: "18",
    },
    {
        name: "Hossein",
        lastName: "Elyasipoor",
        score: "19",
    },
    {
        name: "Ali",
        lastName: "mohammadi",
        score: "15.5",
    },
    {
        name: "Reza",
        lastName: "Hosseini",
        score: "11",
    },
    {
        name: "Jafar",
        lastName: "Karimi",
        score: "14",
    },
];

const result = manualSort(StudentList, {valuePath: "score",sortAlgorithm: "quick3",});
/*
result => [
    {
        name: "Reza",
        lastName: "Hosseini",
        score: "11",
    },
    {
        name: "Jafar",
        lastName: "Karimi",
        score: "14",
    },
    {
        name: "Ali",
        lastName: "mohammadi",
        score: "15.5",
    },
    {
        name: "Arian",
        lastName: "Elahi",
        score: "18",
    },
    {
        name: "Hossein",
        lastName: "Elahi",
        score: "19",
    },
    {
        name: "Abbas",
        lastName: "Elahi",
        score: "20",
    },
]
*/

automate sort

automateSort(arr, options = { valuePath: "" })

In this method, you only have to enter the path of the value that you want the array to be sorted based on. The method automatically detects the state of the array and selects the best and most optimal algorithm for sorting It performs the sorting algorithm

  • valuePath ➜ In this parameter, you must pass the path of the value that you want the array to be sorted based on as a string to the method.For example, in this array:

        [
            {
                name : 'Abbas',
                lastName : 'Elahian',
                result : {
                    score : ['math',20],
                    grade : 12,
                }
            },
            ...
        ]

    if we want to sort the values ​​of the array based on result→score→index 1 in score array, the value of our valuePath will be result.score.1.

    ⚠️ valuePath is required! ⚠️

usage

import {automateSort} from 'sortex';

const StudentList = [
    {
        name: "Abbas",
        lastName: "Elahian",
        score: "20",
    },
    {
        name: "Arian",
        lastName: "Elahi",
        score: "18",
    },
    {
        name: "Hossein",
        lastName: "Elyasipoor",
        score: "19",
    },
    {
        name: "Ali",
        lastName: "mohammadi",
        score: "15.5",
    },
    {
        name: "Reza",
        lastName: "Hosseini",
        score: "11",
    },
    {
        name: "Jafar",
        lastName: "Karimi",
        score: "14",
    },
];

const result = automateSort(StudentList, {valuePath: "score"});
/*
result => [
    {
        name: "Reza",
        lastName: "Hosseini",
        score: "11",
    },
    {
        name: "Jafar",
        lastName: "Karimi",
        score: "14",
    },
    {
        name: "Ali",
        lastName: "mohammadi",
        score: "15.5",
    },
    {
        name: "Arian",
        lastName: "Elahi",
        score: "18",
    },
    {
        name: "Hossein",
        lastName: "Elahi",
        score: "19",
    },
    {
        name: "Abbas",
        lastName: "Elahi",
        score: "20",
    },
]
*/

get specific datas

getSpecificData(arr,options = {valuePath : ""}

Suppose you want to have a new array with a certain value of each index. This method will do it for you!

  • valuePath ➜ In this parameter, you must pass the path of the value that you want the array to be sorted based on as a string to the method.For example, in this array:

        [
            {
                name : 'Abbas',
                lastName : 'Elahian',
                result : {
                    score : ['math',20],
                    grade : 12,
                }
            },
            ...
        ]

    if we want to sort the values ​​of the array based on result→score→index 1 in score array, the value of our valuePath will be result.score.1.

    ⚠️ valuePath is required! ⚠️

usage

import {getSpecificData} from 'sortex';

const StudentList = [
    {
        name: "Abbas",
        lastName: "Elahian",
        score: "20",
    },
    {
        name: "Arian",
        lastName: "Elahi",
        score: "18",
    },
    {
        name: "Hossein",
        lastName: "Elyasipoor",
        score: "19",
    },
    {
        name: "Ali",
        lastName: "mohammadi",
        score: "15.5",
    },
    {
        name: "Reza",
        lastName: "Hosseini",
        score: "11",
    },
    {
        name: "Jafar",
        lastName: "Karimi",
        score: "14",
    },
];

const result = getSpecificData(StudentList, {valuePath: "score"});
/*
result => ["20","18","19","15.5","11","14"]
*/

get biggest or smallest data

getBiggest(arr,options = {valuePath : ""}) | getSmallest(arr,options = {valuePath : ""})

With this method, you can find the biggest data or the smallest one based on an arbitrary value in the data in your array.

  • valuePath ➜ In this parameter, you must pass the path of the value that you want the array to be sorted based on as a string to the method.For example, in this array:

        [
            {
                name : 'Abbas',
                lastName : 'Elahian',
                result : {
                    score : ['math',20],
                    grade : 12,
                }
            },
            ...
        ]

    if we want to sort the values ​​of the array based on result→score→index 1 in score array, the value of our valuePath will be result.score.1.

    ⚠️ valuePath is required! ⚠️

usage

import {getSpecificData} from 'sortex';

const StudentList = [
    {
        name: "Abbas",
        lastName: "Elahian",
        score: "20",
    },
    {
        name: "Arian",
        lastName: "Elahi",
        score: "18",
    },
    {
        name: "Hossein",
        lastName: "Elyasipoor",
        score: "19",
    },
    {
        name: "Ali",
        lastName: "mohammadi",
        score: "15.5",
    },
    {
        name: "Reza",
        lastName: "Hosseini",
        score: "11",
    },
    {
        name: "Jafar",
        lastName: "Karimi",
        score: "14",
    },
];

const b = getBiggest(StudentList, {valuePath: "score"});
const s = getSmallest(StudentList, {valuePath: "score"});

/*
b => {name: "Abbas",lastName: "Elahian",score: "20"}

c => {name: "Reza",lastName: "Hosseini",score: "11"}
*/