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.
tiny-thenable
Advanced tools
This is a lightweight thenable implementation in JavaScript. It is entirely self-contained within a single function with no external dependencies, so it can be easily serialized to a web worker, for example.
This implementation conforms fully to the Promises/A+ spec, so it can safely interoperate with other thenable implementations.
However, it is not a full implementation of ES2015 Promises, e.g. it does not have the same constructor signature and does not expose a catch
method or the static resolve
/reject
/all
/race
initializer methods. If you need to hand a Thenable instance off to consuming code that may expect a true Promise, you'll want to wrap it in a native-or-polyfilled Promise first.
Why yet another Promises/A+ implementation? Great question. We needed a polyfill-like thing that was (a) wrapped in a single function for easy serialization across to a Worker, and (b) was as small as possible -- at ~900B minified (~500B gzipped) this is the smallest implementation I found at the time. And also, exercises like this are challenging and fun!
This began as a utility in troika-worker-utils as a way to use Promise
-like objects in web workers where the browser may not have a native Promise
implementation. The browser support landscape changed since such that native Promises can now be used reliably in that project, so this JS implementation has been extracted and placed here for posterity and for anyone else who might need such a thing.
npm install tiny-thenable
import Thenable from 'tiny-thenable'
const myThenable = Thenable()
myThenable.then(
result => {
console.log('Got result: ' + result)
},
error => {
console.error(error)
}
)
myThenable.resolve('OK!')
// or: myThenable.reject(new Error('Oopsie!'))
Since it has a then()
method, it should be usable as
There's also a Thenable.all([...thenables])
utility function that behaves like Promise.all()
.
FAQs
A small JavaScript implementation of Promises/A+ thenables
The npm package tiny-thenable receives a total of 0 weekly downloads. As such, tiny-thenable popularity was classified as not popular.
We found that tiny-thenable 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.