time-machine-js 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/index.d.mts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +5 -0
- package/dist/index.mjs +4 -0
- package/package.json +9 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ npm install time-machine-js
|
|
|
18
18
|
|
|
19
19
|
## API
|
|
20
20
|
|
|
21
|
-
The core API consists of
|
|
21
|
+
The core API consists of five main functions:
|
|
22
22
|
|
|
23
23
|
### `travel(timestamp: number, mode: 'flowing' | 'frozen'): void`
|
|
24
24
|
Moves the environment time to the specified Unix timestamp.
|
|
@@ -34,6 +34,9 @@ Returns the current offset in ms (flowing mode) or the frozen timestamp (frozen
|
|
|
34
34
|
### `isActive(): boolean`
|
|
35
35
|
Returns `true` if the time machine is currently active.
|
|
36
36
|
|
|
37
|
+
### `getMode(): 'flowing' | 'frozen' | null`
|
|
38
|
+
Returns the current mode of the time machine, or `null` if inactive.
|
|
39
|
+
|
|
37
40
|
## Persistence (Browser Only)
|
|
38
41
|
|
|
39
42
|
For environments with `localStorage`, you can manually save and restore the time machine state across page reloads:
|
package/dist/index.d.mts
CHANGED
|
@@ -31,6 +31,12 @@ declare function getOffset(): number | null;
|
|
|
31
31
|
* @returns True if active, false otherwise.
|
|
32
32
|
*/
|
|
33
33
|
declare function isActive(): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Returns the current mode of the time machine.
|
|
36
|
+
*
|
|
37
|
+
* @returns 'flowing', 'frozen', or null if inactive.
|
|
38
|
+
*/
|
|
39
|
+
declare function getMode(): TimeMachineMode | null;
|
|
34
40
|
/**
|
|
35
41
|
* Saves the current time machine state to localStorage (browser only).
|
|
36
42
|
*
|
|
@@ -45,4 +51,4 @@ declare function save(storageKey?: string): void;
|
|
|
45
51
|
*/
|
|
46
52
|
declare function restore(storageKey?: string): boolean;
|
|
47
53
|
|
|
48
|
-
export { type TimeMachineMode, getOffset, isActive, restore, returnToPresent, save, travel };
|
|
54
|
+
export { type TimeMachineMode, getMode, getOffset, isActive, restore, returnToPresent, save, travel };
|
package/dist/index.d.ts
CHANGED
|
@@ -31,6 +31,12 @@ declare function getOffset(): number | null;
|
|
|
31
31
|
* @returns True if active, false otherwise.
|
|
32
32
|
*/
|
|
33
33
|
declare function isActive(): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Returns the current mode of the time machine.
|
|
36
|
+
*
|
|
37
|
+
* @returns 'flowing', 'frozen', or null if inactive.
|
|
38
|
+
*/
|
|
39
|
+
declare function getMode(): TimeMachineMode | null;
|
|
34
40
|
/**
|
|
35
41
|
* Saves the current time machine state to localStorage (browser only).
|
|
36
42
|
*
|
|
@@ -45,4 +51,4 @@ declare function save(storageKey?: string): void;
|
|
|
45
51
|
*/
|
|
46
52
|
declare function restore(storageKey?: string): boolean;
|
|
47
53
|
|
|
48
|
-
export { type TimeMachineMode, getOffset, isActive, restore, returnToPresent, save, travel };
|
|
54
|
+
export { type TimeMachineMode, getMode, getOffset, isActive, restore, returnToPresent, save, travel };
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
getMode: () => getMode,
|
|
23
24
|
getOffset: () => getOffset,
|
|
24
25
|
isActive: () => isActive,
|
|
25
26
|
restore: () => restore,
|
|
@@ -62,6 +63,9 @@ function getOffset() {
|
|
|
62
63
|
function isActive() {
|
|
63
64
|
return state.isActive;
|
|
64
65
|
}
|
|
66
|
+
function getMode() {
|
|
67
|
+
return state.mode;
|
|
68
|
+
}
|
|
65
69
|
function save(storageKey = "__timeMachine__") {
|
|
66
70
|
if (typeof localStorage === "undefined" || !state.isActive) return;
|
|
67
71
|
const savedState = {
|
|
@@ -89,6 +93,7 @@ function restore(storageKey = "__timeMachine__") {
|
|
|
89
93
|
}
|
|
90
94
|
// Annotate the CommonJS export names for ESM import in node:
|
|
91
95
|
0 && (module.exports = {
|
|
96
|
+
getMode,
|
|
92
97
|
getOffset,
|
|
93
98
|
isActive,
|
|
94
99
|
restore,
|
package/dist/index.mjs
CHANGED
|
@@ -33,6 +33,9 @@ function getOffset() {
|
|
|
33
33
|
function isActive() {
|
|
34
34
|
return state.isActive;
|
|
35
35
|
}
|
|
36
|
+
function getMode() {
|
|
37
|
+
return state.mode;
|
|
38
|
+
}
|
|
36
39
|
function save(storageKey = "__timeMachine__") {
|
|
37
40
|
if (typeof localStorage === "undefined" || !state.isActive) return;
|
|
38
41
|
const savedState = {
|
|
@@ -59,6 +62,7 @@ function restore(storageKey = "__timeMachine__") {
|
|
|
59
62
|
}
|
|
60
63
|
}
|
|
61
64
|
export {
|
|
65
|
+
getMode,
|
|
62
66
|
getOffset,
|
|
63
67
|
isActive,
|
|
64
68
|
restore,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "time-machine-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A zero-dependency utility to monkey-patch Date.now() globally.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -28,6 +28,14 @@
|
|
|
28
28
|
"date",
|
|
29
29
|
"manipulation"
|
|
30
30
|
],
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/WilliamPinto-Olmos/time-machine-js.git"
|
|
34
|
+
},
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/WilliamPinto-Olmos/time-machine-js/issues"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://github.com/WilliamPinto-Olmos/time-machine-js#readme",
|
|
31
39
|
"author": "",
|
|
32
40
|
"license": "MIT",
|
|
33
41
|
"devDependencies": {
|