Socket
Socket
Sign inDemoInstall

@supercharge/collections

Package Overview
Dependencies
1
Maintainers
3
Versions
41
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.3.0 to 2.4.0

7

CHANGELOG.md
# Changelog
## [2.4.0](https://github.com/supercharge/collections/compare/v2.3.0...v2.4.0) - 2020-07-21
### Added
- `uniqueBy(callback)` method: create a collection of unique items where each unique item is identified by a value returned from the `callback`
- GitHub Action to publish the package in the GitHub Package Registry
## [2.3.0](https://github.com/supercharge/collections/compare/v2.2.0...v2.3.0) - 2020-07-19

@@ -4,0 +11,0 @@

@@ -420,2 +420,10 @@ export declare class CollectionProxy<T> {

/**
* Returns all unique items in the collection identified by the given `selector`.
*
* @param {Function}
*
* @returns {CollectionProxy}
*/
uniqueBy(selector: (item: T) => unknown | Promise<unknown>): this;
/**
* Add one or more items to the beginning of the collection.

@@ -422,0 +430,0 @@ *

@@ -530,2 +530,12 @@ 'use strict';

/**
* Returns all unique items in the collection identified by the given `selector`.
*
* @param {Function}
*
* @returns {CollectionProxy}
*/
uniqueBy(selector) {
return this.enqueue('uniqueBy', selector);
}
/**
* Add one or more items to the beginning of the collection.

@@ -532,0 +542,0 @@ *

10

dist/collection.d.ts

@@ -391,2 +391,10 @@ export declare class Collection {

/**
* Returns all unique items in the collection identified by the given `selector`.
*
* @param {Function}
*
* @returns {Array}
*/
uniqueBy(selector: (item: any) => any): Promise<any[]>;
/**
* Create a value receiving callback.

@@ -398,3 +406,3 @@ *

*/
valueRetriever(value: Function | any): Function;
valueRetriever(value: Function | any): (item: any) => any;
/**

@@ -401,0 +409,0 @@ * Add one or more items to the beginning of the collection.

17

dist/collection.js

@@ -571,9 +571,18 @@ 'use strict';

async unique(key) {
if (!key) {
return Array.from(new Set(this.items));
if (key) {
return this.uniqueBy(this.valueRetriever(key));
}
return Array.from(new Set(this.items));
}
/**
* Returns all unique items in the collection identified by the given `selector`.
*
* @param {Function}
*
* @returns {Array}
*/
async uniqueBy(selector) {
const exists = new Set();
const callback = this.valueRetriever(key);
return this.reject(async (item) => {
const id = await callback(item);
const id = await selector(item);
if (exists.has(id)) {

@@ -580,0 +589,0 @@ return true;

{
"name": "@supercharge/collections",
"description": "Supercharge collections",
"version": "2.3.0",
"version": "2.4.0",
"author": "Marcus Pöhls <marcus@superchargejs.com>",

@@ -6,0 +6,0 @@ "bugs": {

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc