Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Readme
Tiny extension for native Promises to make them more suitable for Node core APIs.
The package exposes a subclass of the built-in Promise
, which extends that with the following four methods.
new Deferred([executor])
Unlike Promise
, Deferred
does not require an executor function for instantiation, because it makes possible to
resolve or reject the instance from outside the executor's scope.
const d1 = new Deferred,
d2 = new Deferred(executor)
d1.resolve('sun is shining')
function executor(resolve, reject) {
reject('baby is crying') // same as d2.reject(...)
}
d1.then(result => console.log('success:', result))
d2.catch(error => console.error('error:', error))
Output:
success: sun is shining
error: baby is crying
deferred.resolve(value)
Resolve the deferred instance.
deferred.reject(reason)
Reject the deferred instance.
deferred.done(callback)
Attach an error-first callback to the instance. It will be fired once the instance resolves or rejects.
const d1 = new Deferred,
d2 = new Deferred
function handler(err, result) {
if (err)
console.error('error:', err)
else
console.log('success:', result)
}
d1.done(handler)
d2.done(handler)
d1.resolve('your pizza order has arrived')
d2.reject('something exploded')
Output:
success: your pizza order has arrived
error: something exploded
deferred.callback()
Generate an error-first callback which will resolve or reject the instance based on the first parameter passed to it.
const d1 = new Deferred,
d2 = new Deferred,
cb1 = d1.callback(),
cb2 = d2.callback()
d1.then(result => console.log('success:', result))
d2.catch(error => console.error('error:', error))
cb1(null, 'your cat is purring')
cb2('coffee machine is out of order')
Output:
success: your cat is purring
error: coffee machine is out of order
With npm:
npm install defd
Run unit tests:
npm test
Run unit tests and create coverage report:
npm run cover
FAQs
Tiny extension for native Promises to make them more suitable for Node core APIs.
The npm package defd receives a total of 1 weekly downloads. As such, defd popularity was classified as not popular.
We found that defd 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.