Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
awesome-imperative-promise
Advanced tools
An imperative API on top of promise, with cancellation support
Offer an imperative API on top of promise, with cancellation support
npm install --save awesome-imperative-promise
// or
yarn add awesome-imperative-promise
import { createImperativePromise } from "awesome-imperative-promise";
const wrappedPromise = fetch("url");
// Wrap an existing promise and expose some additional imperative methods
// The existingPromise paramter is optional and the returned promise with resolve/reject when the existing promise do
const { promise, resolve, reject, cancel } = createImperativePromise(wrappedPromise);
// will make the returned promise resolved (not the wrapped one)
resolve("some value");
// will make the returned promise reject (not the wrapped one)
reject(new Error(":s"));
// will ensure the returned promise never resolves or reject
cancel();
The returned promise can only resolve/reject/cancel once and will ignore further imperative calls like regular promises do.
If you call cancel()
and then call resolve("val")
(or if the wrapped promise resolves), the returned promise will never resolve because it has been cancelled first.
I find this useful to be able to cancel the resolution of promises, and use this lib as an implementation detail in other libs I build, like awesome-debounce-promise.
This is particularly useful in React apps where you want to ensure an async process is cancelled when component unmounts, to avoid triggering a setState and get a warning. See [isMounted() is an antipattern] (https://reactjs.org/blog/2015/12/16/ismounted-antipattern.html)
MIT © slorber
Looking for a React/ReactNative freelance expert with more than 5 years production experience? Contact me from my website or with Twitter.
FAQs
An imperative API on top of promise, with cancellation support
The npm package awesome-imperative-promise receives a total of 90,661 weekly downloads. As such, awesome-imperative-promise popularity was classified as popular.
We found that awesome-imperative-promise 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.