Socket
Socket
Sign inDemoInstall

@supercharge/collections

Package Overview
Dependencies
Maintainers
3
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@supercharge/collections - npm Package Compare versions

Comparing version 1.12.2 to 1.13.0

6

CHANGELOG.md
# Changelog
## [1.13.0](https://github.com/supercharge/collections/compare/v1.12.2...v1.13.0) - 2020-03-26
### Updated
- `unique` supports a string or callback function as a parameter to identify unique values
## [1.12.2](https://github.com/supercharge/collections/compare/v1.12.1...v1.12.2) - 2020-03-12

@@ -4,0 +10,0 @@

2

package.json
{
"name": "@supercharge/collections",
"description": "Supercharge collections",
"version": "1.12.2",
"version": "1.13.0",
"author": "Marcus Pöhls <marcus@futurestud.io>",

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

@@ -693,6 +693,8 @@ 'use strict'

*
* @param {String|Function}
*
* @returns {CollectionProxy}
*/
unique () {
return this._enqueue('unique')
unique (key) {
return this._enqueue('unique', null, key)
}

@@ -699,0 +701,0 @@

@@ -717,11 +717,45 @@ 'use strict'

*
* @param {String|Function}
*
* @returns {Array}
*/
unique () {
return Array.from(
new Set(this.items)
)
async unique (key) {
if (!key) {
return Array.from(
new Set(this.items)
)
}
const exists = new Set()
const callback = this.valueRetriever(key)
return this.reject(async item => {
const id = await callback(item)
if (exists.has(id)) {
return true
}
exists.add(id)
})
}
/**
* Create a value receiving callback.
*
* @param {*} value
*
* @returns {Function}
*/
valueRetriever (value) {
if (typeof value === 'function') {
return value
}
return function (item) {
return item[value]
}
}
/**
* Add one or more items to the beginning of the collection.

@@ -728,0 +762,0 @@ *

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