arraymania

1.0.6 • Public • Published

ArrayMania

it has two features for now one is flatArray and second is deep sorting

flatArray

It accepts nested array and convert it into single dimension array

deepSort

It accepts nested array and objects and sort them

Installation

npm i arraymania --save Then...


const { deepSorting, flatArray , getObjValueByPath } = require("arraymania")
let dummy = [
  "a",
  [[[[[[[["john"]]]]]]]],
  ["bab", [["ded"], "cdd"]],
  "s",
  {
    key2: "asd",
    key1: [45, 78, 12],
  },
  ["a", "s", ["z", "s"]],
];

console.log("one dimension array", flatArray(dummy))
//output
//
[ 'a',
  'john',
  'bab',
  'ded',
  'cdd',
  's',
  { key2: 'asd', key1: [ 45, 78, 12 ] },
  'a',
  's',
  'z',
  's' ]

console.log("sorted array/Object", deepSorting(dummy))
//output
//   [{"key1":[12,45,78],"key2":"asd"},"a",["a","s",["s","z"]],["bab",["cdd",["ded"]]],[[[[[[[["john"]]]]]]]],"s"]

let obj = {
  obj1: {
    obj2: {
      arr: [
        {
          key1: "john",
        },
      ],
    },
  },
};
let a = getObjValueByPath(obj, "obj1.obj2.arr[0].key1");
console.log("a: ", a);
//output a:  john

Package Sidebar

Install

npm i arraymania

Weekly Downloads

1

Version

1.0.6

License

ISC

Unpacked Size

5.75 kB

Total Files

7

Last publish

Collaborators

  • owais897