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

big-time

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

big-time - npm Package Compare versions

Comparing version 1.0.7 to 1.0.8

90

lib/index.js

@@ -1,10 +0,9 @@

"use strict";
'use strict';
var _bind = Function.prototype.bind;
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }

@@ -14,63 +13,60 @@ var TIMEOUT_MAX = 2147483647; // 2^31-1

var Timeout = (function () {
function Timeout(callback, delay) {
_classCallCheck(this, Timeout);
function Timeout(callback, delay) {
_classCallCheck(this, Timeout);
this._callback = callback;
this._delay = delay;
this._callback = callback;
this._delay = delay;
for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
args[_key - 2] = arguments[_key];
}
this.start(args);
for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
args[_key - 2] = arguments[_key];
}
_createClass(Timeout, [{
key: "start",
value: function start(args) {
var _this = this;
this.start(args);
}
var _args = args.slice(0);
var max = module.exports._TIMEOUT_MAX;
_createClass(Timeout, [{
key: 'start',
value: function start(args) {
var _this = this;
if (this._delay <= max) {
var _args = args.slice(0);
var max = module.exports._TIMEOUT_MAX;
_args = [this._callback, this._delay].concat(_toConsumableArray(_args));
} else {
var callback = function callback() {
if (this._delay <= max) {
_args = [this._callback, this._delay].concat(_toConsumableArray(_args));
} else {
var callback = function callback() {
_this._delay -= max;
_this.start(args);
};
_args = [callback, max].concat(_toConsumableArray(_args));
}
this._timeout = setTimeout.apply(undefined, _toConsumableArray(_args));
}
}, {
key: 'close',
value: function close() {
clearTimeout(this._timeout);
}
}]);
_this._delay -= max;
_this.start(args);
};
_args = [callback, max].concat(_toConsumableArray(_args));
}
this._timeout = setTimeout.apply(undefined, _toConsumableArray(_args));
}
}, {
key: "close",
value: function close() {
clearTimeout(this._timeout);
}
}]);
return Timeout;
return Timeout;
})();
var _setTimeout = function _setTimeout() {
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return new (_bind.apply(Timeout, [null].concat(args)))();
return new (_bind.apply(Timeout, [null].concat(args)))();
};
var _clearTimeout = function _clearTimeout(timer) {
return timer.close();
return timer.close();
};
module.exports = {
setTimeout: _setTimeout,
clearTimeout: _clearTimeout,
_TIMEOUT_MAX: TIMEOUT_MAX
setTimeout: _setTimeout,
clearTimeout: _clearTimeout,
_TIMEOUT_MAX: TIMEOUT_MAX
};
{
"name": "big-time",
"version": "1.0.7",
"version": "1.0.8",
"description": "Big time makes it possible to have a timeout that is longer than 24.8 days (2^31-1 milliseconds).",

@@ -9,3 +9,3 @@ "main": "lib/index.js",

"compile": "babel src --out-dir lib",
"lint": "eslint src",
"lint": "belly-button --i 'src/**.js' --i 'test/**.js'",
"prepublish": "npm run compile"

@@ -26,8 +26,6 @@ },

"babel-core": "5.8.x",
"belly-button": "1.x.x",
"code": "1.x.x",
"eslint": "1.x.x",
"eslint-config-hapi": "3.x.x",
"eslint-plugin-hapi": "1.x.x",
"lab": "6.x.x"
}
}

@@ -5,2 +5,3 @@ # Big-Time

[![belly-button-style](https://cdn.rawgit.com/continuationlabs/belly-button/master/badge.svg)](https://github.com/continuationlabs/belly-button)

@@ -7,0 +8,0 @@ Reworking of [long-timeout](https://github.com/tellnes/long-timeout) that has more features, follows correct semver, and has unit tests. Big-Time is a custom timer class to allow really long values into `setTimeout` that are larger than Node would normally support (2^31-1).

@@ -0,43 +1,38 @@

'use strict';
const TIMEOUT_MAX = 2147483647; // 2^31-1
class Timeout {
constructor (callback, delay, ...args) {
constructor (callback, delay, ...args) {
this._callback = callback;
this._delay = delay;
this.start(args);
}
start (args) {
let _args = args.slice(0);
const max = module.exports._TIMEOUT_MAX;
this._callback = callback;
this._delay = delay;
if (this._delay <= max) {
_args = [this._callback, this._delay, ..._args];
} else {
const callback = () => {
this._delay -= max;
this.start(args);
};
_args = [callback, max, ..._args];
}
start (args) {
let _args = args.slice(0);
const max = module.exports._TIMEOUT_MAX;
if (this._delay <= max) {
_args = [this._callback, this._delay, ..._args];
}
else {
const callback = () => {
this._delay -= max;
this.start(args);
};
_args = [callback, max, ..._args];
}
this._timeout = setTimeout(..._args);
}
close () {
clearTimeout(this._timeout);
}
this._timeout = setTimeout(..._args);
}
close () {
clearTimeout(this._timeout);
}
}
const _setTimeout = (...args) => new Timeout(...args);
const _setTimeout = (...args) => { return new Timeout(...args); };
const _clearTimeout = (timer) => timer.close();
const _clearTimeout = (timer) => { return timer.close(); };
module.exports = {
setTimeout: _setTimeout,
clearTimeout: _clearTimeout,
_TIMEOUT_MAX: TIMEOUT_MAX
setTimeout: _setTimeout,
clearTimeout: _clearTimeout,
_TIMEOUT_MAX: TIMEOUT_MAX
};

@@ -0,7 +1,7 @@

'use strict';
var Code = require('code');
var Lab = require('lab');
var lab = exports.lab = Lab.script();
var BigTime = require('../src');
var lab = exports.lab = Lab.script();
var describe = lab.describe;

@@ -12,91 +12,77 @@ var it = lab.it;

var internals = {
ignore: function () {}
ignore: function () {}
};
describe('Timeout', function () {
describe('setTimeout()', function () {
it('returns a new Timeout object', function (done) {
var result = BigTime.setTimeout(done, 100);
expect(result._callback).to.be.a.function();
expect(result._delay).to.equal(100);
expect(result._timeout._idleTimeout).to.equal(100);
});
describe('setTimeout()', function () {
it('will allow really large numbers that built-in setTimeout will not', function (done) {
var result = BigTime.setTimeout(internals.ignore, 3000000000);
expect(result._callback).to.be.a.function();
expect(result._delay).to.equal(3000000000);
expect(result._timeout._idleTimeout).to.equal(2147483647);
it('returns a new Timeout object', function (done) {
// We don't want to wait for this to finish
clearTimeout(result._timeout);
done();
});
var result = BigTime.setTimeout(done, 100);
expect(result._callback).to.be.a.function();
expect(result._delay).to.equal(100);
expect(result._timeout._idleTimeout).to.equal(100);
});
it('will adjust the remaining timeout after a run for really large numbers', function (done) {
// Make testing easier
var max = BigTime._TIMEOUT_MAX;
BigTime._TIMEOUT_MAX = 1000;
it('will allow really large numbers that built-in setTimeout will not', function (done) {
var orig = setTimeout;
var counter = 3;
process.nextTick(function () {
setTimeout = function () { // eslint-disable-line no-native-reassign, no-undef
counter--;
expect(result._delay).to.be.between((counter * 1000 - 1), ((counter + 1) * 1000));
expect(arguments).to.have.length(4);
orig.apply(null, arguments);
};
});
var result = BigTime.setTimeout(internals.ignore, 3000000000);
expect(result._callback).to.be.a.function();
expect(result._delay).to.equal(3000000000);
expect(result._timeout._idleTimeout).to.equal(2147483647);
var result = BigTime.setTimeout(function (name, foo) {
expect(name).to.equal('john doe');
expect(foo).to.be.true();
expect(arguments).to.have.length(2);
setTimeout = orig; // eslint-disable-line no-native-reassign, no-undef
BigTime._TIMEOUT_MAX = max;
// 1 because there is a setTimeout we don't catch due to needed process.nextTick and the real setTimeout is called.
expect(counter).to.equal(1);
done();
}, 3000, 'john doe', true);
});
// We don't want to wait for this to finish
clearTimeout(result._timeout);
done();
});
it('will adjust the remaining timeout after a run for really large numbers', function (done) {
// Make testing easier
var max = BigTime._TIMEOUT_MAX;
BigTime._TIMEOUT_MAX = 1000;
var orig = setTimeout;
var counter = 3;
process.nextTick(function () {
setTimeout = function () {
counter--;
expect(result._delay).to.be.between((counter * 1000 - 1), ((counter + 1) * 1000));
expect(arguments).to.have.length(4);
orig.apply(null, arguments);
};
});
var result = BigTime.setTimeout(function (name, foo) {
expect(name).to.equal('john doe');
expect(foo).to.be.true();
expect(arguments).to.have.length(2);
setTimeout = orig;
BigTime._TIMEOUT_MAX = max;
// 1 because there is a setTimeout we don't catch due to needed process.nextTick and the real setTimeout is called.
expect(counter).to.equal(1);
done();
}, 3000, 'john doe', true);
});
it('passes arguments through like native setTimeout', function (done) {
BigTime.setTimeout(function (x, y, z) {
expect(x).to.equal('foo');
expect(y).to.equal('bar');
expect(z).to.equal('baz');
done();
}, 100, 'foo', 'bar', 'baz');
});
it('passes arguments through like native setTimeout', function (done) {
BigTime.setTimeout(function (x, y, z) {
expect(x).to.equal('foo');
expect(y).to.equal('bar');
expect(z).to.equal('baz');
done();
}, 100, 'foo', 'bar', 'baz');
});
});
describe('clearTimeout()', function () {
describe('clearTimeout()', function () {
it('cleans up all of the setTimeout objects', function (done) {
var result = BigTime.setTimeout(internals.ignore, 100);
expect(result._callback).to.be.a.function();
expect(result._delay).to.equal(100);
expect(result._timeout._idleTimeout).to.equal(100);
it('cleans up all of the setTimeout objects', function (done) {
var result = BigTime.setTimeout(internals.ignore, 100);
expect(result._callback).to.be.a.function();
expect(result._delay).to.equal(100);
expect(result._timeout._idleTimeout).to.equal(100);
process.nextTick(function () {
BigTime.clearTimeout(result);
expect(result._timeout._idleTimeout).to.equal(-1);
done();
});
});
process.nextTick(function () {
BigTime.clearTimeout(result);
expect(result._timeout._idleTimeout).to.equal(-1);
done();
});
});
});
});

@@ -0,21 +1,21 @@

'use strict';
var Babel = require('babel-core');
module.exports = [{
ext: '.js',
transform: function (content, filename) {
ext: '.js',
transform: function (content, filename) {
// Make sure to only transform your code or the dependencies you want
if (filename.indexOf('src') >= 0) {
var result = Babel.transform(content, {
sourceMap: 'inline',
filename: filename,
sourceFileName: filename,
auxiliaryCommentBefore: '$lab:coverage:off$',
auxiliaryCommentAfter: '$lab:coverage:on$'
});
return result.code;
}
// Make sure to only transform your code or the dependencies you want
if (filename.indexOf('src') >= 0) {
var result = Babel.transform(content, {
sourceMap: 'inline',
filename: filename,
sourceFileName: filename,
auxiliaryCommentBefore: '$lab:coverage:off$',
auxiliaryCommentAfter: '$lab:coverage:on$'
});
return result.code;
}
return content;
}
return content;
}
}];
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