1.0.2 • Published 5 years ago

groupum v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

Introduction

Groupum is a simple grouping library built in TypeScript. Groupum utilises deep-equal to compare object types.

Group on Single Property

Group on a single property:

const arrayOfThings = [
    { thingOne: "5", thingTwo: 2, thingThree: { a: 1, b: 2 } },
    { thingOne: "2", thingTwo: 5, thingThree: { a: 1, b: 2 } },
    { thingOne: "3", thingTwo: 2, thingThree: { a: 1, b: 2 } },
    { thingOne: "5", thingTwo: 3, thingThree: { a: 2, b: 2 } },
    { thingOne: "5", thingTwo: 2, thingThree: { a: 1, b: 2 } },
  ];

Groupum(arrayOfThings, "thingOne");

Multiple Properties

Group on multiple properties:

const arrayOfThings = [
    { thingOne: "5", thingTwo: 2, thingThree: { a: 1, b: 2 } },
    { thingOne: "2", thingTwo: 5, thingThree: { a: 1, b: 2 } },
    { thingOne: "3", thingTwo: 2, thingThree: { a: 1, b: 2 } },
    { thingOne: "5", thingTwo: 3, thingThree: { a: 2, b: 2 } },
    { thingOne: "5", thingTwo: 2, thingThree: { a: 1, b: 2 } },
  ];

Groupum(arrayOfThings, ["thingOne", "thingThree"]);

Dot Notation

Group on child property using dot notation:

const arrayOfThings = [
    { thingOne: "5", thingTwo: 2, thingThree: { a: 1, b: 2 } },
    { thingOne: "2", thingTwo: 5, thingThree: { a: 1, b: 2 } },
    { thingOne: "3", thingTwo: 2, thingThree: { a: 1, b: 2 } },
    { thingOne: "5", thingTwo: 3, thingThree: { a: 2, b: 2 } },
    { thingOne: "5", thingTwo: 2, thingThree: { a: 1, b: 2 } },
  ];

Groupum(arrayOfThings, ["thingOne", "thingThree.a"]);

Options

Return a list of keys (array of value's matches) and groups as an object:

const arrayOfThings = [
    { thingOne: "5", thingTwo: 2, thingThree: { a: 1, b: 2 } },
    { thingOne: "2", thingTwo: 5, thingThree: { a: 1, b: 2 } },
    { thingOne: "3", thingTwo: 2, thingThree: { a: 1, b: 2 } },
    { thingOne: "5", thingTwo: 3, thingThree: { a: 2, b: 2 } },
    { thingOne: "5", thingTwo: 2, thingThree: { a: 1, b: 2 } },
  ];

Groupum(arrayOfThings, "thingOne", { showKeys: true });
1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago