New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

timecontroljs

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

timecontroljs

Time control for your project. Fake javascript time.

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

Time Control for Javascript

Fake the javascript time for your projects.

import { sleep, setTime } from "timecontrol";

setTime(0); // It's 1970

console.log(Date.now()); // 0

sleep(6000); // Instantly fakes 6000 milliseconds

console.log(new Date().getTime()); // 6000

await sleep(2000); // Also if you await sleep, it works such a normal sleep function

console.log(Date.now()); // 8000

Also there are a lot of functions to manipulate time, from modify time speed to stop the time.

import * as time from "timecontrol";

time.set(0); // It's 1970

time.increaseSpeed(2); // speed *= 2

const promise = new Promise((resolve) =>
  setTimeout(() => {
    resolve(Date.now());
  }, 2000)
);

console.log(await promise); // 4000, the time goes x2

time.pause(); // stop the time, now always be fixed to the current 4000 time.

const { sleep } = time;

await sleep(1000);
console.log(Date.now()); // 4000

time.unpause();

await sleep(1000, 100);
// first param, the time that will be advanced
// second param, the real time that sleep function will do

time.restore(); // It also reverts time speed

time.switchUnit("y"); // now time is on year unit.

time.advance(5); // time will advance 5 years

console.log(Date.now()); // From now 5 years on future

time.back(100); // 95 years from now to the past

Keywords

time

FAQs

Package last updated on 28 Apr 2024

Did you know?

Socket

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.

Install

Related posts