Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dankreiger/groop

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dankreiger/groop

Normalize an array of objects by a property.

  • 0.1.32
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

groop

Normalize an array of objects by a property.

Both lists and single objects can be normalized.

Usage

import { createArrayGroup } from '@dankreiger/groop';

const listGroup = [
  { name: 'Dan', age: 5 },
  { name: 'Puppy', age: 5 },
  { name: 'Woofer', age: 22 },
  { name: 'Dan', age: 20 },
];

const byAge = createArrayGroup('age');

byAge(listGroup);
/**
 *  {
 *    entities: {
 *      '20': [
 *        {
 *          age: 20,
 *          name: 'Dan',
 *        },
 *      ],
 *      '22': [
 *        {
 *          age: 22,
 *          name: 'Woofer',
 *        },
 *      ],
 *      '5': [
 *        {
 *          age: 5,
 *          name: 'Dan',
 *        },
 *        {
 *          age: 5,
 *          name: 'Puppy',
 *        },
 *      ],
 *    },
 *    ids: [5, 22, 20],
 *  }
 */

const byName = createArrayGroup('name');

byName(listGroup);

/**
 * {
 *   entities: {
 *     Dan: [
 *       { name: 'Dan', age: 5 },
 *       { name: 'Dan', age: 20 }
 *     ],
 *     Puppy: [ { name: 'Puppy', age: 5 } ],
 *     Woofer: [ { name: 'Woofer', age: 22 } ]
 *   },
 *   ids: [ 'Dan', 'Puppy', 'Woofer' ]
 *  }
 */
import { createGroup } from '@dankreiger/groop';

const singleGroup = { name: 'Dan', age: 5 };

const byAge = createGroup('age');

byAge(singleGroup);

/**
 * {
 *   entities: {
 *     '5': { name: 'Dan', age: 5 }
 *   },
 *   ids: [5]
 * }
 */

const byName = createGroup('name');

byName(singleGroup);

/**
 * {
 *   entities: {
 *     Dan: { name: 'Dan', age: 5 }
 *   },
 *   ids: ['Dan']
 * }
 */

FAQs

Package last updated on 11 Apr 2024

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