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

@applitools/functional-commons

Package Overview
Dependencies
Maintainers
19
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@applitools/functional-commons - npm Package Compare versions

Comparing version 1.5.2 to 1.5.3

12

package.json
{
"name": "@applitools/functional-commons",
"version": "1.5.2",
"version": "1.5.3",
"description": "",

@@ -37,9 +37,9 @@ "main": "src/functional-commons.js",

"chai-as-promised": "^7.1.1",
"eslint": "^6.2.2",
"eslint": "^6.7.2",
"eslint-plugin-mocha-no-only": "^1.1.0",
"eslint-plugin-node": "^9.1.0",
"eslint-plugin-prettier": "^3.1.0",
"mocha": "^6.2.0",
"prettier": "^1.18.2"
"eslint-plugin-node": "^9.2.0",
"eslint-plugin-prettier": "^3.1.1",
"mocha": "^6.2.2",
"prettier": "^1.19.1"
}
}

@@ -212,3 +212,6 @@ 'use strict'

function presult(promise) {
return promise.then(v => [undefined, v], err => [err])
return promise.then(
v => [undefined, v],
err => [err],
)
}

@@ -420,2 +423,52 @@

function isFunction(functionToCheck) {
return functionToCheck && typeof functionToCheck == 'function'
}
async function promiseProps(object) {
const result = {}
const promises = []
for (let key of Object.keys(object)) {
async function resolve() {
return object[key]
}
async function populate() {
const value = await resolve()
result[key] = value
}
promises.push(populate())
}
await Promise.all(promises)
return result
}
async function promiseMap(collection, func, {concurrency} = {concurrency: 4}) {
if (concurrency <= 0 || concurrency > 100) {
throw new Error('concurrency should be in range: 1..100')
}
if (!isFunction(func)) {
throw new Error('func must be a function')
}
if (collection.length == 0) {
return []
}
const collectionWithIndexes = []
for (let i = 0; i < collection.length; i++) {
collectionWithIndexes.push({object: collection[i], index: i})
}
const promises = []
const result = new Array(collection.length)
for (let i = 0; i < concurrency; i++) {
async function worker() {
while (collectionWithIndexes.length > 0) {
const element = collectionWithIndexes.pop()
result[element.index] = await func(element.object)
}
}
promises.push(worker())
}
await Promise.all(promises)
return result
}
module.exports = {

@@ -452,2 +505,5 @@ cacheFunctionSync,

groupBy,
promiseMap,
promiseProps,
isFunction,
}
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