arraymania

It make all the nested array into one dimension array and more functionalities will come soon

Usage no npm install needed!

<script type="module">
  import arraymania from 'https://cdn.skypack.dev/arraymania';
</script>

README

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