@operato/utils 2.0.0-alpha.0 → 2.0.0-alpha.8
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/CHANGELOG.md +9 -0
- package/dist/src/adjust-list-param.d.ts +14 -0
- package/dist/src/adjust-list-param.js +8 -0
- package/dist/src/adjust-list-param.js.map +1 -1
- package/dist/src/async-lock.d.ts +13 -0
- package/dist/src/async-lock.js +13 -0
- package/dist/src/async-lock.js.map +1 -1
- package/dist/src/clipboard.d.ts +7 -0
- package/dist/src/clipboard.js +7 -0
- package/dist/src/clipboard.js.map +1 -1
- package/dist/src/closest-element.d.ts +7 -0
- package/dist/src/closest-element.js +7 -0
- package/dist/src/closest-element.js.map +1 -1
- package/dist/src/context-path.d.ts +15 -0
- package/dist/src/context-path.js +20 -0
- package/dist/src/context-path.js.map +1 -1
- package/dist/src/cookie.d.ts +18 -0
- package/dist/src/cookie.js +18 -0
- package/dist/src/cookie.js.map +1 -1
- package/dist/src/detect-overflow.d.ts +6 -0
- package/dist/src/detect-overflow.js +6 -0
- package/dist/src/detect-overflow.js.map +1 -1
- package/dist/src/format.d.ts +12 -0
- package/dist/src/format.js +12 -0
- package/dist/src/format.js.map +1 -1
- package/dist/src/logger.d.ts +15 -0
- package/dist/src/logger.js +15 -3
- package/dist/src/logger.js.map +1 -1
- package/dist/src/mixins/infinite-scrollable.d.ts +24 -0
- package/dist/src/mixins/infinite-scrollable.js +24 -0
- package/dist/src/mixins/infinite-scrollable.js.map +1 -1
- package/dist/src/os.d.ts +4 -0
- package/dist/src/os.js +4 -0
- package/dist/src/os.js.map +1 -1
- package/dist/src/password-pattern.d.ts +15 -0
- package/dist/src/password-pattern.js +15 -0
- package/dist/src/password-pattern.js.map +1 -1
- package/dist/src/stringify-bignum.d.ts +11 -0
- package/dist/src/stringify-bignum.js +11 -0
- package/dist/src/stringify-bignum.js.map +1 -1
- package/dist/src/timecapsule/snapshot-taker.d.ts +31 -0
- package/dist/src/timecapsule/snapshot-taker.js +36 -3
- package/dist/src/timecapsule/snapshot-taker.js.map +1 -1
- package/dist/src/timecapsule/timecapsule.d.ts +50 -0
- package/dist/src/timecapsule/timecapsule.js +50 -3
- package/dist/src/timecapsule/timecapsule.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/adjust-list-param.ts +20 -0
- package/src/async-lock.ts +13 -0
- package/src/clipboard.ts +7 -0
- package/src/closest-element.ts +8 -0
- package/src/context-path.ts +20 -0
- package/src/cookie.ts +18 -0
- package/src/detect-overflow.ts +6 -0
- package/src/format.ts +12 -0
- package/src/logger.ts +15 -4
- package/src/mixins/infinite-scrollable.ts +24 -0
- package/src/os.ts +4 -0
- package/src/password-pattern.ts +15 -0
- package/src/stringify-bignum.ts +12 -0
- package/src/timecapsule/snapshot-taker.ts +41 -4
- package/src/timecapsule/timecapsule.ts +50 -4
@@ -1,11 +1,10 @@
|
|
1
|
-
/*
|
2
|
-
* Copyright © HatioLab Inc. All rights reserved.
|
3
|
-
*/
|
4
|
-
|
5
1
|
import { debug, error, warn } from '../logger'
|
6
2
|
|
7
3
|
import { SnapshotTaker } from './snapshot-taker'
|
8
4
|
|
5
|
+
/**
|
6
|
+
* A utility class for managing and navigating through a history of snapshots.
|
7
|
+
*/
|
9
8
|
export class TimeCapsule {
|
10
9
|
private q: Array<any> = []
|
11
10
|
private maxsize = 10
|
@@ -13,6 +12,11 @@ export class TimeCapsule {
|
|
13
12
|
|
14
13
|
private _snapshot_taker: SnapshotTaker | null = null
|
15
14
|
|
15
|
+
/**
|
16
|
+
* Creates an instance of TimeCapsule.
|
17
|
+
* @param {number} maxsize - The maximum number of snapshots to store.
|
18
|
+
* @param {any} [start_state] - The initial state to be stored as the first snapshot (optional).
|
19
|
+
*/
|
16
20
|
constructor(maxsize: number, start_state?: any) {
|
17
21
|
maxsize = Number(maxsize)
|
18
22
|
|
@@ -28,10 +32,17 @@ export class TimeCapsule {
|
|
28
32
|
}
|
29
33
|
}
|
30
34
|
|
35
|
+
/**
|
36
|
+
* Disposes of the TimeCapsule and clears all stored snapshots.
|
37
|
+
*/
|
31
38
|
dispose() {
|
32
39
|
this.reset()
|
33
40
|
}
|
34
41
|
|
42
|
+
/**
|
43
|
+
* Captures a snapshot of the current state and stores it.
|
44
|
+
* @param {any} state - The state to be captured as a snapshot.
|
45
|
+
*/
|
35
46
|
snapshot(state: any) {
|
36
47
|
this.q.splice(this.pos + 1, this.q.length - (this.pos + 1), state)
|
37
48
|
|
@@ -42,6 +53,10 @@ export class TimeCapsule {
|
|
42
53
|
this.pos = this.q.length - 1
|
43
54
|
}
|
44
55
|
|
56
|
+
/**
|
57
|
+
* Moves forward to the next snapshot in the history.
|
58
|
+
* @returns {any} The next state snapshot if available, or logs a warning if not.
|
59
|
+
*/
|
45
60
|
forward() {
|
46
61
|
if (this.snapshot_taker) this.snapshot_taker.take()
|
47
62
|
|
@@ -51,6 +66,10 @@ export class TimeCapsule {
|
|
51
66
|
warn('Not forwardable.')
|
52
67
|
}
|
53
68
|
|
69
|
+
/**
|
70
|
+
* Moves backward to the previous snapshot in the history.
|
71
|
+
* @returns {any} The previous state snapshot if available, or logs a warning if not.
|
72
|
+
*/
|
54
73
|
backward() {
|
55
74
|
if (this.snapshot_taker) this.snapshot_taker.take()
|
56
75
|
|
@@ -60,32 +79,59 @@ export class TimeCapsule {
|
|
60
79
|
warn('Not backwardable.')
|
61
80
|
}
|
62
81
|
|
82
|
+
/**
|
83
|
+
* Gets the current state snapshot.
|
84
|
+
* @returns {any} The current state snapshot if available, or logs a warning if not.
|
85
|
+
*/
|
63
86
|
get current() {
|
64
87
|
if (this.pos !== -1) return this.q[this.pos]
|
65
88
|
|
66
89
|
warn('Non state has been recorded.')
|
67
90
|
}
|
68
91
|
|
92
|
+
/**
|
93
|
+
* Gets the number of snapshots stored in the TimeCapsule.
|
94
|
+
* @returns {number} The count of stored snapshots.
|
95
|
+
*/
|
69
96
|
get length() {
|
70
97
|
return this.q.length
|
71
98
|
}
|
72
99
|
|
100
|
+
/**
|
101
|
+
* Checks if there is a snapshot available to move forward.
|
102
|
+
* @returns {boolean} True if moving forward is possible, otherwise false.
|
103
|
+
*/
|
73
104
|
get forwardable() {
|
74
105
|
return this.pos < this.q.length - 1
|
75
106
|
}
|
76
107
|
|
108
|
+
/**
|
109
|
+
* Checks if there is a snapshot available to move backward.
|
110
|
+
* @returns {boolean} True if moving backward is possible, otherwise false.
|
111
|
+
*/
|
77
112
|
get backwardable() {
|
78
113
|
return this.pos > 0
|
79
114
|
}
|
80
115
|
|
116
|
+
/**
|
117
|
+
* Gets the SnapshotTaker associated with this TimeCapsule.
|
118
|
+
* @returns {SnapshotTaker | null} The associated SnapshotTaker, or null if not set.
|
119
|
+
*/
|
81
120
|
get snapshot_taker(): SnapshotTaker | null {
|
82
121
|
return this._snapshot_taker
|
83
122
|
}
|
84
123
|
|
124
|
+
/**
|
125
|
+
* Sets the SnapshotTaker for this TimeCapsule.
|
126
|
+
* @param {SnapshotTaker | null} snapshot_taker - The SnapshotTaker instance to associate with this TimeCapsule.
|
127
|
+
*/
|
85
128
|
set snapshot_taker(snapshot_taker: SnapshotTaker | null) {
|
86
129
|
this._snapshot_taker = snapshot_taker
|
87
130
|
}
|
88
131
|
|
132
|
+
/**
|
133
|
+
* Resets the TimeCapsule, clearing all stored snapshots and resetting the position.
|
134
|
+
*/
|
89
135
|
reset() {
|
90
136
|
this.q = []
|
91
137
|
this.pos = -1
|