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

allora

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

allora - npm Package Compare versions

Comparing version 0.0.2 to 1.0.0

15

index.js

@@ -12,3 +12,3 @@ function isOnCallback (str) {

*/
function makePromisable (parent, prop) {
function allora (parent, prop) {
return new Proxy(prop ? parent[prop] : parent, {

@@ -27,3 +27,3 @@ get: (target, property) => {

// make proxy also the nested object properties
return makePromisable(target, property)
return allora(target, property)
}

@@ -34,3 +34,4 @@ },

apply: (target, thisArg, argumentsList) => {
return new Promise((resolve, reject) => {
let returnValue
const promise = new Promise((resolve, reject) => {
// guessing the timer functions from the type of arguments passed to the method

@@ -40,4 +41,8 @@ const isTimer = !argumentsList.length || typeof argumentsList[0] === 'number'

argumentsList.splice(isTimer ? 0 : 1, 0, resolve)
Reflect.apply(target, parent, argumentsList)
returnValue = Reflect.apply(target, parent, argumentsList)
})
// Return the returnValue through valueOf
promise.valueOf = () => returnValue
promise.toString = () => returnValue
return promise
}

@@ -47,2 +52,2 @@ })

module.exports = exports.default = (object) => makePromisable(object)
module.exports = exports.default = (object) => allora(object)
{
"name": "allora",
"version": "0.0.2",
"version": "1.0.0",
"description": "Promisify everything",

@@ -32,6 +32,4 @@ "main": "index.js",

"eslint-plugin-standard": "^2.0.0",
"mocha": "^2.5.3",
"sinon": "^1.17.4",
"sinon-chai": "^2.8.0"
"mocha": "^2.5.3"
}
}

@@ -47,2 +47,13 @@ # allora

### Clear timers
Thanks to [this pull request](https://github.com/GianlucaGuarini/allora/pull/3) it's now also possible to clear the timers
```js
const myWindow = allora(window)
const timer = myWindow.setTimeout(3000)
timer.then(_ => console.log('time over'))
// the valueOf call should be not needed here
// but if you are on node, you will need it https://github.com/nodejs/node/issues/7792
clearTimeout(timer.valueOf())
```
## "allora" meaning

@@ -49,0 +60,0 @@

const allora = require('../')
const chai = require('chai')
// const sinon = require('sinon')
const sinonChai = require('sinon-chai')
const expect = chai.expect
const EventEmitter = require('events')
const expect = chai.expect
chai.use(sinonChai)

@@ -51,2 +48,25 @@ describe('core', function () {

})
it('Reject the promise', function (done) {
const coolGlobal = allora(global)
coolGlobal.setImmediate().then(() => {
throw new Error('Random error')
}).catch(() => done())
})
it('Can clear properly the timer', function (done) {
const coolGlobal = allora(global)
const timer = coolGlobal.setTimeout(200)
var count = 0
timer.then(_ => count++)
clearTimeout(timer.valueOf())
setTimeout(function () {
expect(count).to.be.equal(0)
done()
}, 1000)
})
})
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