🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

mockdate

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mockdate - npm Package Compare versions

Comparing version

to
3.0.5

rollup.config.js

14

CHANGELOG.md

@@ -0,1 +1,13 @@

## 3.0.5
- Use Rollup to build a proper UMD package.
## 3.0.4
- Properly exposed window.MockDate when loaded in the browser.
## 3.0.3
- Switched TypeScript build from CommonJS to UMD.
## 3.0.0

@@ -5,2 +17,2 @@

Support for `timezoneOffset` parameter was removed. It was a foot gun and caused many issues because it was only half-implemented. Implementing full timezone support is outside the scope of this library.
- Support for `timezoneOffset` parameter was removed. It was a foot gun and caused many issues because it was only half-implemented. Implementing full timezone support is outside the scope of this library.

8

component.json
{
"name": "mockdate",
"version": "1.0.1",
"version": "3.0.2",
"keywords": [

@@ -11,4 +11,6 @@ "date",

"license": "MIT",
"main": "src/mockdate.js",
"scripts": ["src/mockdate.js"]
"main": "lib/mockdate.js",
"scripts": [
"lib/mockdate.js"
]
}

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

export declare function set(date: string | number | Date): void;
export declare function reset(): void;
declare const _default: {
set: typeof set;
reset: typeof reset;
};
export default _default;
declare module "mockdate" {
export function set(date: string | number | Date): void;
export function reset(): void;
const _default: {
set: typeof set;
reset: typeof reset;
};
export default _default;
}

@@ -1,81 +0,104 @@

"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MockDate = {}));
}(this, (function (exports) { 'use strict';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
function __extends(d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var RealDate = Date;
var now = null;
var MockDate = /** @class */ (function (_super) {
__extends(Date, _super);
function Date(y, m, d, h, M, s, ms) {
_super.call(this) || this;
var date;
switch (arguments.length) {
case 0:
if (now !== null) {
date = new RealDate(now.valueOf());
}
else {
date = new RealDate();
}
break;
case 1:
date = new RealDate(y);
break;
default:
d = typeof d === 'undefined' ? 1 : d;
h = h || 0;
M = M || 0;
s = s || 0;
ms = ms || 0;
date = new RealDate(y, m, d, h, M, s, ms);
break;
}
return date;
}
return Date;
}(RealDate));
MockDate.prototype = RealDate.prototype;
MockDate.UTC = RealDate.UTC;
MockDate.now = function () {
return new MockDate().valueOf();
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.reset = exports.set = void 0;
var RealDate = Date;
var now = null;
var MockDate = /** @class */ (function (_super) {
__extends(MockDate, _super);
function MockDate(y, m, d, h, M, s, ms) {
var _this = _super.call(this) || this;
var date;
switch (arguments.length) {
case 0:
if (now !== null) {
date = new RealDate(now.valueOf());
}
else {
date = new RealDate();
}
break;
case 1:
date = new RealDate(y);
break;
default:
d = typeof d === 'undefined' ? 1 : d;
h = h || 0;
M = M || 0;
s = s || 0;
ms = ms || 0;
date = new RealDate(y, m, d, h, M, s, ms);
break;
MockDate.parse = function (dateString) {
return RealDate.parse(dateString);
};
MockDate.toString = function () {
return RealDate.toString();
};
function set(date) {
var dateObj = new Date(date.valueOf());
if (isNaN(dateObj.getTime())) {
throw new TypeError('mockdate: The time set is an invalid date: ' + date);
}
return date;
// @ts-ignore
Date = MockDate;
now = dateObj.valueOf();
}
return MockDate;
}(Date));
MockDate.prototype = RealDate.prototype;
MockDate.UTC = RealDate.UTC;
MockDate.now = function () {
return new MockDate().valueOf();
};
MockDate.parse = function (dateString) {
return RealDate.parse(dateString);
};
MockDate.toString = function () {
return RealDate.toString();
};
function set(date) {
var dateObj = new Date(date.valueOf());
if (isNaN(dateObj.getTime())) {
throw new TypeError('mockdate: The time set is an invalid date: ' + date);
function reset() {
Date = RealDate;
}
// @ts-ignore
Date = MockDate;
if (date.valueOf) {
date = date.valueOf();
}
now = dateObj.valueOf();
}
exports.set = set;
function reset() {
Date = RealDate;
}
exports.reset = reset;
exports.default = {
set: set,
reset: reset,
};
//# sourceMappingURL=mockdate.js.map
var mockdate = {
set: set,
reset: reset,
};
exports.default = mockdate;
exports.reset = reset;
exports.set = set;
Object.defineProperty(exports, '__esModule', { value: true });
})));
{
"name": "mockdate",
"version": "3.0.2",
"version": "3.0.5",
"description": "A JavaScript mock Date object that can be used to change when \"now\" is.",

@@ -10,2 +10,4 @@ "main": "lib/mockdate.js",

"mocha": "7.1.2",
"rollup": "2.42.4",
"rollup-plugin-typescript2": "0.30.0",
"should": "13.2.3",

@@ -15,3 +17,5 @@ "typescript": "3.9.3"

"scripts": {
"build": "tsc",
"build": "npm run build:js && npm run build:types",
"build:types": "tsc -t esnext --moduleResolution node -d --emitDeclarationOnly --outFile lib/mockdate.d.ts src/mockdate.ts",
"build:js": "rollup -c rollup.config.js",
"test": "npm run build && mocha",

@@ -37,4 +41,4 @@ "prepare": "npm run build",

"spm": {
"main": "src/mockdate.js"
"main": "lib/mockdate.js"
}
}

@@ -9,3 +9,3 @@ MockDate

## Installation ##
`npm install mockdate`
`npm install mockdate --save-dev`

@@ -12,0 +12,0 @@ ## Environment Support ##

const RealDate = Date;
let now: null | number = null;
class MockDate extends Date {
const MockDate = class Date extends RealDate {
constructor();

@@ -66,6 +66,2 @@ constructor(value: number | string);

if (date.valueOf) {
date = date.valueOf();
}
now = dateObj.valueOf();

@@ -81,2 +77,2 @@ }

reset,
}
}
const should = require('should');
const MockDate = require('..');
const MockDate = require('../lib/mockdate');
describe('MockDate', function() {
const mockDate = '1/1/2000';
const currentYear = new Date().getFullYear();
const nativeToString = Date.toString();
var mockDate = '1/1/2000';
var currentYear = new Date().getFullYear();
var nativeToString = Date.toString();
var mockDateRealOffset = new Date(mockDate).getTimezoneOffset();
var currentDateRealOffset = new Date().getTimezoneOffset();
beforeEach(function () {

@@ -20,2 +17,6 @@ MockDate.set(new Date(mockDate));

it('should check date constructor name', function() {
should.equal(Date.name, 'Date');
});
it('should throw for bad date', function() {

@@ -22,0 +23,0 @@ should.throws(function () {

{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"module": "ES2015",
"declaration": true,

@@ -12,2 +12,2 @@ "noImplicitAny": true,

"exclude": ["node_modules", "test"]
}
}

Sorry, the diff of this file is not supported yet