JSPM

pluckngrouparray

1.0.0
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • 0
    • Score
      100M100P100Q19819F
    • License MIT

    A tiny util library to pluck and group data at one loop (used to remove boilerplate codes)

    Package Exports

    • pluckngrouparray

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pluckngrouparray) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    PluckNGroup

    To pluck and group data from an array of objects in javascript in a single loop (used to remove boilerplate codes)

    We can pluck any number of key, group the array using any number of keys or even group using multiple key combimations

    Sample inputs and outputs

    1)Input

    const arrayOfObjects = [{apple:1, ball:2, cat:3, dog: "hi"}, {apple:4, ball:5, cat:6, dog: "bye"}]; const toPluckKeys = ['apple','ball']; const groupByTheseKeysIndividually = ['apple', 'ball']; const groupByCombinningTheseKeys = ['cat','dog'];

    2)Function call

    pluckAndGroup(arrayOfObjects, toPluckKeys, groupByTheseKeysIndividually, groupByCombinningTheseKeys)));

    3)Output

    { "pluckedData":{"balls":["2","5"],"apples":["1","4"]}, "groupedByData":{ "ballgrp":{"2":{"apple":1,"ball":2,"cat":3,"dog":"hi"},"5":{"apple":4,"ball":5,"cat":6,"dog":"bye"}}, "applegrp":{"1":{"apple":1,"ball":2,"cat":3,"dog":"hi"},"4":{"apple":4,"ball":5,"cat":6,"dog":"bye"}} }, "gropedByMultiKeyData":{ "cat_dogmultiGrp":{"6_bye":{"apple":4,"ball":5,"cat":6,"dog":"bye"},"3_hi":{"apple":1,"ball":2,"cat":3,"dog":"hi"}} } }