Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
promise-flow
Advanced tools
Utility module for functions that return promises.
Note that this module expects a global Promise
to exist. If used in an environment that does not implement Promise, a shim should be used.
import * as pf from 'promise-flow';
pf.allObject({
key1: Promise.resolve('value from a promise'),
key2: 'non-promise value'
}).then(function(result) {
// result == { key1: 'value from a promise', key2: 'non-promise value' }
});
allObject(object)
allObject<T>(object: { [key: string]: Promise<T> | T }): Promise<{ [key: string]: T }>
Returns a promise that resolves with a copy of the input object when all values have resolved.
promise_flow.allObject({
key1: Promise.resolve('value from a promise'),
key2: 'non-promise value'
}).then(function(result) {
// result == { key1: 'value from a promise', key2: 'non-promise value' }
});
series(factories)
series<T>(factories: Array<() => Promise<T> | T): Promise<Array<T>>
Takes an array of functions that will be executed in series. Each one will wait until the previous function is done.
If one of the functions returns a rejected promise or throws an error then the resulting promise will reject with that error.
promise_flow.series([
() => Promise.resolve('value from a promise'),
() => 'non-promise value'
]).then(function(result) {
// result == ['value from a promise', 'non-promise value']
});
parallel(factories)
parallel<T>(factories: Array<() => Promise<T> | T): Promise<Array<T>>
Same as series
but will run all functions in parallel.
map(array, closure)
map<T, U>(array: Array<T>, closure: (value: T, index: number) => Promise<U> | U): Promise<Array<U>>
Map the items in the array with a function that may return a promise.
mapSeries(array, closure)
map<T, U>(array: Array<T>, closure: (value: T, index: number) => Promise<U> | U): Promise<Array<U>>
Same as map
but will run all functions in series.
filter(array, closure)
filter<T>(array: Array<T>, closure: (value: T, index: number) => Promise<boolean> | boolean): Promise<Array<T>>
Filter the array using a function that may return a promise.
To keep a value in the array, return a promise that resolves with a truthy value (or return the value directly).
filterSeries(array, closure)
filterSeries<T>(array: Array<T>, closure: (value: T, index: number) => Promise<boolean> | boolean): Promise<Array<T>>
Same as filter
but will run all functions in series.
entangledCallback(optional_value_resolver)
entangledCallback<T>(optional_value_resolver?: (...values: Array<any>) => T): [Promise<T>, (err: ?Error, ...values: Array<any>) => void]
Returns a tuple where the first item is a promise and the second item is a node-style callback function. The two are connected so that when the callback is invoked, the promise will be resolved.
An optional function can be provided to reduce arguments passed to the callback to a single value.
// Example where a function that takes a callback is used:
import { readFile } from 'fs';
// Example function that calls readFile and pass the entangled callback instead of wrapping the call in new Promise(...)
function myReadFile(filename, options) {
const [promise, callback] = promise_flow.entangledCallback();
readFile(filename, options, callback);
return promise;
}
// myReadFile will return a promise that is either resolved with the file content or rejected with the error from readFile.
myReadFile('./file.txt').then(handleFileData, handleReadError);
// Example callback invocation and the equivalent state of the entangled promise:
const [promise, callback] = promise_flow.entangledCallback();
// callback() is equivalent to Promise.resolve()
// callback(null, 'value') is equivalent to Promise.resolve('value')
// callback(null, 'a', 'b', 'c') is equivalent to Promise.resolve('a')
// callback(new Error('error')) is equivalent to Promise.reject(new Error('error'))
// The optional function argument is used to reduce values passed to the callback to a single value
const [promise, callback] = promise_flow.entangledCallback(Array.of);
// callback(null, 'a') is equivalent to Promise.resolve(['a'])
// callback(null, 'a', 'b', 'c') is equivalent to Promise.resolve(['a', 'b', 'c'])
FAQs
Utility module for functions that return promises
The npm package promise-flow receives a total of 66 weekly downloads. As such, promise-flow popularity was classified as not popular.
We found that promise-flow demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.