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

appolo-utils

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

appolo-utils - npm Package Compare versions

Comparing version 0.0.28 to 0.0.29

32

lib/promises.js

@@ -107,3 +107,3 @@ "use strict";

}
static some(promises, counter = 1) {
static some(promises, { counter = 1 } = { counter: 1 }) {
return new Promise((resolve) => {

@@ -119,25 +119,35 @@ let settled = [];

}
static someResolved(promises, counter = 1) {
static someRejected(promises, { counter = 1, fn = null } = {
counter: 1,
fn: null
}) {
return new Promise((resolve, reject) => {
let resolved = [], rejected = [];
counter = Math.min(Math.max(Math.floor(counter), 1), promises.length);
let fnResolve = value => (resolved.push({ status: "fulfilled", value }) + rejected.length === promises.length)
&& resolve(rejected);
let fnReject = reason => (rejected.push({ status: "rejected", reason }) === counter
|| resolved.length + rejected.length === promises.length) && resolve(rejected);
for (let i = 0; i < promises.length; i++) {
promises[i]
.then(value => (resolved.push({ status: "fulfilled", value }) === counter
|| resolved.length + rejected.length === promises.length) && resolve(resolved))
.catch(reason => (rejected.push({ status: "rejected", reason }) + resolved.length === promises.length)
&& resolve(resolved));
.then(value => fn ? (fn(value) ? fnResolve(value) : fnReject(value)) : fnResolve(value))
.catch(fnReject);
}
});
}
static someRejected(promises, counter = 1) {
static someResolved(promises, { counter = 1, fn = null } = {
counter: 1,
fn: null
}) {
return new Promise((resolve, reject) => {
let resolved = [], rejected = [];
counter = Math.min(Math.max(Math.floor(counter), 1), promises.length);
let fnResolve = value => (resolved.push({ status: "fulfilled", value }) === counter
|| resolved.length + rejected.length === promises.length) && resolve(resolved);
let fnReject = reason => (rejected.push({ status: "rejected", reason }) + resolved.length === promises.length)
&& resolve(resolved);
for (let i = 0; i < promises.length; i++) {
promises[i]
.then(value => (resolved.push({ status: "fulfilled", value }) + rejected.length === promises.length)
&& resolve(rejected))
.catch(reason => (rejected.push({ status: "rejected", reason }) === counter
|| resolved.length + rejected.length === promises.length) && resolve(rejected));
.then(value => fn ? (fn(value) ? fnResolve(value) : fnReject(value)) : fnResolve(value))
.catch(fnReject);
}

@@ -144,0 +154,0 @@ });

@@ -145,3 +145,3 @@ type Resolvable<R> = R | PromiseLike<R>

public static some<T>(promises: Promise<T>[], counter: number = 1): Promise<({ status: "fulfilled"; value: T; } | { status: "rejected"; reason: any; })[]> {
public static some<T>(promises: Promise<T>[], {counter = 1} = {counter: 1}): Promise<({ status: "fulfilled"; value: T; } | { status: "rejected"; reason: any; })[]> {

@@ -161,3 +161,6 @@ return new Promise((resolve) => {

public static someResolved<T>(promises: Promise<T>[], counter: number = 1): Promise<({ status: "fulfilled"; value: T; })[]> {
public static someRejected<T>(promises: Promise<T>[], {counter = 1, fn = null}: { counter?: number, fn?: (value: T) => boolean } = {
counter: 1,
fn: null
}): Promise<({ status: "rejected"; reason: any; })[]> {

@@ -169,8 +172,12 @@ return new Promise((resolve, reject) => {

let fnResolve = value => (resolved.push({status: "fulfilled", value}) + rejected.length === promises.length)
&& resolve(rejected);
let fnReject = reason => (rejected.push({status: "rejected", reason}) === counter
|| resolved.length + rejected.length === promises.length) && resolve(rejected);
for (let i = 0; i < promises.length; i++) {
promises[i]
.then(value => (resolved.push({status: "fulfilled", value}) === counter
|| resolved.length + rejected.length === promises.length) && resolve(resolved))
.catch(reason => (rejected.push({status: "rejected", reason}) + resolved.length === promises.length)
&& resolve(resolved))
.then(value => fn ? (fn(value) ? fnResolve(value) : fnReject(value)) : fnResolve(value))
.catch(fnReject)
}

@@ -180,3 +187,6 @@ })

public static someRejected<T>(promises: Promise<T>[], counter: number = 1): Promise<({ status: "fulfilled"; value: T; })[]> {
public static someResolved<T>(promises: Promise<T>[], {counter = 1, fn = null}: { counter?: number, fn?: (value: T) => boolean } = {
counter: 1,
fn: null
}): Promise<({ status: "fulfilled"; value: T; })[]> {

@@ -188,8 +198,12 @@ return new Promise((resolve, reject) => {

let fnResolve = value => (resolved.push({status: "fulfilled", value}) === counter
|| resolved.length + rejected.length === promises.length) && resolve(resolved);
let fnReject = reason => (rejected.push({status: "rejected", reason}) + resolved.length === promises.length)
&& resolve(resolved);
for (let i = 0; i < promises.length; i++) {
promises[i]
.then(value => (resolved.push({status: "fulfilled", value}) + rejected.length === promises.length)
&& resolve(rejected))
.catch(reason => (rejected.push({status: "rejected", reason}) === counter
|| resolved.length + rejected.length === promises.length) && resolve(rejected))
.then(value => fn ? (fn(value) ? fnResolve(value) : fnReject(value)) : fnResolve(value))
.catch(fnReject)
}

@@ -196,0 +210,0 @@ })

@@ -17,3 +17,3 @@ {

"main": "./index.js",
"version": "0.0.28",
"version": "0.0.29",
"license": "MIT",

@@ -20,0 +20,0 @@ "repository": {

Sorry, the diff of this file is not supported yet

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