Socket
Socket
Sign inDemoInstall

ts-group-by

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-group-by

group by one or more levels while maintaining type safety.


Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

ts-group-by

This package allows you to group an array by one or more levels while maintaining type safety.

How to install

npm install ts-group-by

Basic usage:

import { groupBy } from "ts-group-by";

const data = [
    { agency: "Agency A", patient: "Carol baskin", gender: "F" },
    { agency: "Agency A", patient: "Carol baskin", gender: "F" },
    { agency: "Agency A", patient: "Esther Friedman", gender: "M" },
    { agency: "Agency A", patient: "Zaritskaia Raia", gender: "M" },
    { agency: "Agency B", patient: "Judy Gottesman", gender: "F" },
];

const groupedByAgency = groupBy(data, "agency");
// : Map<string, { agency: string; patient: string; gender: string; }[]>
// = Map {
//     'Agency A' => [
//         { agency: 'Agency A', patient: 'Carol baskin', gender: 'F' },
//         { agency: 'Agency A', patient: 'Carol baskin', gender: 'F' },
//         { agency: 'Agency A', patient: 'Esther Friedman', gender: 'M' },
//         { agency: 'Agency A', patient: 'Zaritskaia Raia', gender: 'M' }
//      ],
//     'Agency B' => [
//         { agency: 'Agency B', patient: 'Judy Gottesman', gender: 'F' }
//     ]
// }

Group by two levels:

const groupedByAgencyAndGender = groupBy(data, "agency", "gender");
// : Map<string, Map<string, { agency: string; patient: string; gender: string; }[]>>
// = Map {
//     'Agency A' => Map {
//         'F' => [
//             { agency: 'Agency A', patient: 'Carol baskin', gender: 'F' },
//             { agency: 'Agency A', patient: 'Carol baskin', gender: 'F' }
//         ],
//         'M' => [
//             { agency: 'Agency A', patient: 'Esther Friedman', gender: 'M' },
//             { agency: 'Agency A', patient: 'Zaritskaia Raia', gender: 'M' }
//         ]
//     }
//     'Agency B' => Map {
//         'F' => [
//             { agency: 'Agency B', patient: 'Judy Gottesman', gender: 'F' }
//         ]
//     }
// }

Keywords

FAQs

Package last updated on 16 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc