chronokinesis
Advanced tools
Comparing version 3.1.2 to 4.0.0
@@ -6,39 +6,23 @@ var chronokinesis = (function (exports) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) { | ||
symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
} | ||
keys.push.apply(keys, symbols); | ||
enumerableOnly && (symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
})), keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
var source = null != arguments[i] ? arguments[i] : {}; | ||
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
return target; | ||
} | ||
function _defineProperty(obj, key, value) { | ||
key = _toPropertyKey(key); | ||
if (key in obj) { | ||
@@ -54,6 +38,4 @@ Object.defineProperty(obj, key, { | ||
} | ||
return obj; | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
@@ -67,14 +49,9 @@ if (!o) return; | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _createForOfIteratorHelper(o, allowArrayLike) { | ||
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; | ||
if (!it) { | ||
@@ -84,5 +61,3 @@ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
var i = 0; | ||
var F = function () {}; | ||
return { | ||
@@ -105,9 +80,7 @@ s: F, | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
var normalCompletion = true, | ||
didErr = false, | ||
err; | ||
didErr = false, | ||
err; | ||
return { | ||
@@ -135,2 +108,16 @@ s: function () { | ||
} | ||
function _toPrimitive(input, hint) { | ||
if (typeof input !== "object" || input === null) return input; | ||
var prim = input[Symbol.toPrimitive]; | ||
if (prim !== undefined) { | ||
var res = prim.call(input, hint || "default"); | ||
if (typeof res !== "object") return res; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return (hint === "string" ? String : Number)(input); | ||
} | ||
function _toPropertyKey(arg) { | ||
var key = _toPrimitive(arg, "string"); | ||
return typeof key === "symbol" ? key : String(key); | ||
} | ||
@@ -149,3 +136,2 @@ /** | ||
var iana = null; | ||
function FakeDate() { | ||
@@ -155,9 +141,6 @@ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
} | ||
var length = args.length; | ||
if (!length) { | ||
if (freezedAt) args = [freezedAt];else if (traveledTo) args = [time()]; | ||
} | ||
var dt = instantiate(NativeDate, args); | ||
@@ -175,7 +158,5 @@ Object.defineProperty(dt, 'getTimezoneOffset', { | ||
} | ||
FakeDate.UTC = NativeDate.UTC; | ||
FakeDate.parse = NativeDate.parse; | ||
FakeDate.prototype = NativeDate.prototype; | ||
FakeDate.now = function () { | ||
@@ -185,3 +166,2 @@ if (freezedAt) return freezedAt.getTime(); | ||
}; | ||
var chronokinesis = { | ||
@@ -195,36 +175,26 @@ freeze: freeze, | ||
}; | ||
function freeze() { | ||
useFakeDate(); | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
freezedAt = instantiate(Date, args); | ||
return freezedAt; | ||
} | ||
function defrost() { | ||
freezedAt = null; | ||
} | ||
function travel() { | ||
useFakeDate(); | ||
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
var travelToDate = instantiate(Date, args); | ||
traveledTo = travelToDate.getTime(); | ||
started = NativeDate.now(); | ||
if (freezedAt) { | ||
freezedAt = travelToDate; | ||
} | ||
return travelToDate; | ||
} | ||
function reset() { | ||
@@ -237,7 +207,5 @@ useNativeDate(); | ||
} | ||
function isKeepingTime() { | ||
return Date === FakeDate; | ||
} | ||
function timezone(timeZone) { | ||
@@ -266,3 +234,2 @@ var options = { | ||
}; | ||
function freezeInTimezone() { | ||
@@ -273,3 +240,2 @@ if (!arguments.length && iana === timeZone) return freeze(); | ||
} | ||
function travelInTimezone() { | ||
@@ -280,3 +246,2 @@ if (!arguments.length && iana === timeZone) return travel(); | ||
} | ||
function getTime() { | ||
@@ -286,3 +251,2 @@ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { | ||
} | ||
var realDate = instantiate(Date, args); | ||
@@ -295,3 +259,2 @@ var tz = new NativeDate(toUTC(formatter, realDate)); | ||
} | ||
function useFakeDate() { | ||
@@ -308,3 +271,2 @@ Date = FakeDate; // eslint-disable-line no-global-assign | ||
} | ||
function instantiate(type, args) { | ||
@@ -315,15 +277,11 @@ var ctorArgs = args.slice(); | ||
} | ||
function toUTC(formatter, dt) { | ||
var year, month, day, hour, minute, second; | ||
var _iterator = _createForOfIteratorHelper(formatter.formatToParts(dt)), | ||
_step; | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var _step$value = _step.value, | ||
type = _step$value.type, | ||
value = _step$value.value; | ||
type = _step$value.type, | ||
value = _step$value.value; | ||
switch (type) { | ||
@@ -333,19 +291,14 @@ case 'year': | ||
break; | ||
case 'month': | ||
month = parseInt(value) - 1; | ||
break; | ||
case 'day': | ||
day = parseInt(value); | ||
break; | ||
case 'hour': | ||
hour = parseInt(value) % 24; | ||
break; | ||
case 'minute': | ||
minute = parseInt(value); | ||
break; | ||
case 'second': | ||
@@ -361,3 +314,2 @@ second = parseInt(value); | ||
} | ||
return NativeDate.UTC(year, month, day, hour, minute, second, dt.getMilliseconds()); | ||
@@ -372,3 +324,3 @@ } | ||
exports['default'] = chronokinesis; | ||
exports["default"] = chronokinesis; | ||
exports.defrost = chronokinesis_2; | ||
@@ -385,2 +337,2 @@ exports.freeze = chronokinesis_1; | ||
}({})); | ||
})({}); |
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) { | ||
symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
} | ||
keys.push.apply(keys, symbols); | ||
enumerableOnly && (symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
})), keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
var source = null != arguments[i] ? arguments[i] : {}; | ||
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
return target; | ||
} | ||
function _defineProperty(obj, key, value) { | ||
key = _toPropertyKey(key); | ||
if (key in obj) { | ||
@@ -50,6 +34,4 @@ Object.defineProperty(obj, key, { | ||
} | ||
return obj; | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
@@ -63,14 +45,9 @@ if (!o) return; | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _createForOfIteratorHelper(o, allowArrayLike) { | ||
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; | ||
if (!it) { | ||
@@ -80,5 +57,3 @@ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
var i = 0; | ||
var F = function () {}; | ||
return { | ||
@@ -101,9 +76,7 @@ s: F, | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
var normalCompletion = true, | ||
didErr = false, | ||
err; | ||
didErr = false, | ||
err; | ||
return { | ||
@@ -131,2 +104,16 @@ s: function () { | ||
} | ||
function _toPrimitive(input, hint) { | ||
if (typeof input !== "object" || input === null) return input; | ||
var prim = input[Symbol.toPrimitive]; | ||
if (prim !== undefined) { | ||
var res = prim.call(input, hint || "default"); | ||
if (typeof res !== "object") return res; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return (hint === "string" ? String : Number)(input); | ||
} | ||
function _toPropertyKey(arg) { | ||
var key = _toPrimitive(arg, "string"); | ||
return typeof key === "symbol" ? key : String(key); | ||
} | ||
@@ -145,3 +132,2 @@ /** | ||
var iana = null; | ||
function FakeDate() { | ||
@@ -151,9 +137,6 @@ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
} | ||
var length = args.length; | ||
if (!length) { | ||
if (freezedAt) args = [freezedAt];else if (traveledTo) args = [time()]; | ||
} | ||
var dt = instantiate(NativeDate, args); | ||
@@ -171,7 +154,5 @@ Object.defineProperty(dt, 'getTimezoneOffset', { | ||
} | ||
FakeDate.UTC = NativeDate.UTC; | ||
FakeDate.parse = NativeDate.parse; | ||
FakeDate.prototype = NativeDate.prototype; | ||
FakeDate.now = function () { | ||
@@ -181,3 +162,2 @@ if (freezedAt) return freezedAt.getTime(); | ||
}; | ||
var chronokinesis = { | ||
@@ -191,36 +171,26 @@ freeze: freeze, | ||
}; | ||
function freeze() { | ||
useFakeDate(); | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
freezedAt = instantiate(Date, args); | ||
return freezedAt; | ||
} | ||
function defrost() { | ||
freezedAt = null; | ||
} | ||
function travel() { | ||
useFakeDate(); | ||
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
var travelToDate = instantiate(Date, args); | ||
traveledTo = travelToDate.getTime(); | ||
started = NativeDate.now(); | ||
if (freezedAt) { | ||
freezedAt = travelToDate; | ||
} | ||
return travelToDate; | ||
} | ||
function reset() { | ||
@@ -233,7 +203,5 @@ useNativeDate(); | ||
} | ||
function isKeepingTime() { | ||
return Date === FakeDate; | ||
} | ||
function timezone(timeZone) { | ||
@@ -262,3 +230,2 @@ var options = { | ||
}; | ||
function freezeInTimezone() { | ||
@@ -269,3 +236,2 @@ if (!arguments.length && iana === timeZone) return freeze(); | ||
} | ||
function travelInTimezone() { | ||
@@ -276,3 +242,2 @@ if (!arguments.length && iana === timeZone) return travel(); | ||
} | ||
function getTime() { | ||
@@ -282,3 +247,2 @@ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { | ||
} | ||
var realDate = instantiate(Date, args); | ||
@@ -291,3 +255,2 @@ var tz = new NativeDate(toUTC(formatter, realDate)); | ||
} | ||
function useFakeDate() { | ||
@@ -304,3 +267,2 @@ Date = FakeDate; // eslint-disable-line no-global-assign | ||
} | ||
function instantiate(type, args) { | ||
@@ -311,15 +273,11 @@ var ctorArgs = args.slice(); | ||
} | ||
function toUTC(formatter, dt) { | ||
var year, month, day, hour, minute, second; | ||
var _iterator = _createForOfIteratorHelper(formatter.formatToParts(dt)), | ||
_step; | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var _step$value = _step.value, | ||
type = _step$value.type, | ||
value = _step$value.value; | ||
type = _step$value.type, | ||
value = _step$value.value; | ||
switch (type) { | ||
@@ -329,19 +287,14 @@ case 'year': | ||
break; | ||
case 'month': | ||
month = parseInt(value) - 1; | ||
break; | ||
case 'day': | ||
day = parseInt(value); | ||
break; | ||
case 'hour': | ||
hour = parseInt(value) % 24; | ||
break; | ||
case 'minute': | ||
minute = parseInt(value); | ||
break; | ||
case 'second': | ||
@@ -357,3 +310,2 @@ second = parseInt(value); | ||
} | ||
return NativeDate.UTC(year, month, day, hour, minute, second, dt.getMilliseconds()); | ||
@@ -360,0 +312,0 @@ } |
{ | ||
"name": "chronokinesis", | ||
"version": "3.1.2", | ||
"version": "4.0.0", | ||
"description": "Module for testing time-dependent code", | ||
@@ -18,9 +18,9 @@ "author": { | ||
"engines": { | ||
"node": ">=10" | ||
"node": ">=12" | ||
}, | ||
"scripts": { | ||
"toc": "node generate-api-toc.js", | ||
"test": "lab -vcL", | ||
"posttest": "npm run prepare", | ||
"test:lcov": "npm t -- -r lcov -o coverage.lcov", | ||
"test": "mocha", | ||
"posttest": "eslint . --cache && npm run prepare", | ||
"test:lcov": "c8 -r lcov npm t", | ||
"prepare": "npm run toc && rollup -c" | ||
@@ -53,8 +53,9 @@ }, | ||
"@babel/preset-env": "^7.12.1", | ||
"@hapi/code": "^8.0.2", | ||
"@hapi/lab": "^24.1.0", | ||
"c8": "^7.12.0", | ||
"chai": "^4.3.7", | ||
"coveralls": "^3.1.0", | ||
"eslint": "^7.13.0", | ||
"eslint": "^8.29.0", | ||
"lodash.clonedeep": "^4.5.0", | ||
"markdown-toc": "^1.2.0", | ||
"mocha": "^10.1.0", | ||
"moment": "^2.29.1", | ||
@@ -61,0 +62,0 @@ "rollup": "^2.56.3", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29759
759
13