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

@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.9.1 to 1.10.0

9

CHANGELOG.md
# Changelog
## [1.10.0](https://github.com/superchargejs/collections/compare/v1.9.1...v1.10.0) - 2020-01-22
### Added
- `.tap()` method
- `.hasDuplicates()` method
### Fixed
- an empty value creates an empty collection, example: `Collect(null).all()` returns an empty array `[]`
## [1.9.1](https://github.com/superchargejs/collections/compare/v1.9.0...v1.9.1) - 2020-01-07

@@ -5,0 +14,0 @@

6

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

@@ -17,7 +17,7 @@ "bugs": {

"eslint-config-standard": "~14.1.0",
"eslint-plugin-import": "~2.19.1",
"eslint-plugin-import": "~2.20.0",
"eslint-plugin-node": "~11.0.0",
"eslint-plugin-promise": "~4.2.1",
"eslint-plugin-standard": "~4.0.1",
"sinon": "~8.0.4"
"sinon": "~8.1.0"
},

@@ -24,0 +24,0 @@ "engines": {

@@ -7,4 +7,4 @@ 'use strict'

class CollectionProxy {
constructor (items = [], callChain = []) {
this.items = [].concat(items)
constructor (items, callChain = []) {
this.items = [].concat(items || [])
this.callChain = new Queue(callChain)

@@ -640,2 +640,22 @@ }

/**
* Returns `true` when the collection contains duplicate items, `false` otherwise.
*
* @returns {Boolean}
*/
async hasDuplicates () {
return this.all(
this._enqueue('hasDuplicates')
)
}
/**
* Tap into the chain, run the given `callback` and retreive the original value.
*
* @returns {CollectionProxy}
*/
tap (callback) {
return this._enqueue('tap', callback)
}
/**
* Enqueues an operation in the collection pipeline

@@ -642,0 +662,0 @@ * for processing at a later time.

@@ -235,3 +235,3 @@ 'use strict'

/**
* Creates an array of unique values that are included in both given array
* Creates an array of unique values that are included in both given array.
*

@@ -276,5 +276,4 @@ * @param {Array} items

/**
* Returns the last item in the collection
* that satisfies the `callback` testing
* function, `undefined` otherwise.
* Returns the last item in the collection that satisfies
* the `callback` testing function, `undefined` otherwise.
*

@@ -309,3 +308,5 @@ * @param {Function} callback

async map (callback) {
return Promise.all(this.items.map(callback))
return Promise.all(
this.items.map(callback)
)
}

@@ -348,3 +349,3 @@

/**
* Removes and returns the last item from the collection
* Removes and returns the last item from the collection.
*

@@ -509,3 +510,3 @@ * @param {}

/**
* Returns reversed version of original collection
* Returns reversed version of original collection.
*

@@ -557,3 +558,3 @@ * @returns {Array}

*/
async sort (comparator) {
sort (comparator) {
return [...this.items.sort(comparator)]

@@ -563,3 +564,3 @@ }

/**
* Returns median of the current collection
* Returns median of the current collection.
*

@@ -570,4 +571,4 @@ * @param {}

*/
async median () {
await this.sort((a, b) => a - b)
median () {
this.sort((a, b) => a - b)

@@ -607,3 +608,3 @@ const mid = Math.floor(this.size() / 2)

/**
* Returns JSON representation of collection
* Returns JSON representation of collection.
*

@@ -621,3 +622,3 @@ * @returns {String}

*/
async unique () {
unique () {
return Array.from(

@@ -633,3 +634,3 @@ new Set(this.items)

*/
async unshift (items) {
unshift (items) {
this.items.unshift(...items)

@@ -641,3 +642,3 @@

/**
* Returns the average of all collection items
* Returns the average of all collection items.
*

@@ -649,4 +650,24 @@ * @returns {Number}

}
/**
* Tap into the chain, run the given `callback` and retreive the original value.
*
* @returns {Number}
*/
async tap (callback) {
await this.forEach(callback)
return this
}
/**
* Returns `true` when the collection contains duplicate items, `false` otherwise.
*
* @returns {Boolean}
*/
async hasDuplicates () {
return (new Set(this.items)).size !== this.size()
}
}
module.exports = Collection
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