@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.
Files changed (63) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/src/adjust-list-param.d.ts +14 -0
  3. package/dist/src/adjust-list-param.js +8 -0
  4. package/dist/src/adjust-list-param.js.map +1 -1
  5. package/dist/src/async-lock.d.ts +13 -0
  6. package/dist/src/async-lock.js +13 -0
  7. package/dist/src/async-lock.js.map +1 -1
  8. package/dist/src/clipboard.d.ts +7 -0
  9. package/dist/src/clipboard.js +7 -0
  10. package/dist/src/clipboard.js.map +1 -1
  11. package/dist/src/closest-element.d.ts +7 -0
  12. package/dist/src/closest-element.js +7 -0
  13. package/dist/src/closest-element.js.map +1 -1
  14. package/dist/src/context-path.d.ts +15 -0
  15. package/dist/src/context-path.js +20 -0
  16. package/dist/src/context-path.js.map +1 -1
  17. package/dist/src/cookie.d.ts +18 -0
  18. package/dist/src/cookie.js +18 -0
  19. package/dist/src/cookie.js.map +1 -1
  20. package/dist/src/detect-overflow.d.ts +6 -0
  21. package/dist/src/detect-overflow.js +6 -0
  22. package/dist/src/detect-overflow.js.map +1 -1
  23. package/dist/src/format.d.ts +12 -0
  24. package/dist/src/format.js +12 -0
  25. package/dist/src/format.js.map +1 -1
  26. package/dist/src/logger.d.ts +15 -0
  27. package/dist/src/logger.js +15 -3
  28. package/dist/src/logger.js.map +1 -1
  29. package/dist/src/mixins/infinite-scrollable.d.ts +24 -0
  30. package/dist/src/mixins/infinite-scrollable.js +24 -0
  31. package/dist/src/mixins/infinite-scrollable.js.map +1 -1
  32. package/dist/src/os.d.ts +4 -0
  33. package/dist/src/os.js +4 -0
  34. package/dist/src/os.js.map +1 -1
  35. package/dist/src/password-pattern.d.ts +15 -0
  36. package/dist/src/password-pattern.js +15 -0
  37. package/dist/src/password-pattern.js.map +1 -1
  38. package/dist/src/stringify-bignum.d.ts +11 -0
  39. package/dist/src/stringify-bignum.js +11 -0
  40. package/dist/src/stringify-bignum.js.map +1 -1
  41. package/dist/src/timecapsule/snapshot-taker.d.ts +31 -0
  42. package/dist/src/timecapsule/snapshot-taker.js +36 -3
  43. package/dist/src/timecapsule/snapshot-taker.js.map +1 -1
  44. package/dist/src/timecapsule/timecapsule.d.ts +50 -0
  45. package/dist/src/timecapsule/timecapsule.js +50 -3
  46. package/dist/src/timecapsule/timecapsule.js.map +1 -1
  47. package/dist/tsconfig.tsbuildinfo +1 -1
  48. package/package.json +2 -2
  49. package/src/adjust-list-param.ts +20 -0
  50. package/src/async-lock.ts +13 -0
  51. package/src/clipboard.ts +7 -0
  52. package/src/closest-element.ts +8 -0
  53. package/src/context-path.ts +20 -0
  54. package/src/cookie.ts +18 -0
  55. package/src/detect-overflow.ts +6 -0
  56. package/src/format.ts +12 -0
  57. package/src/logger.ts +15 -4
  58. package/src/mixins/infinite-scrollable.ts +24 -0
  59. package/src/os.ts +4 -0
  60. package/src/password-pattern.ts +15 -0
  61. package/src/stringify-bignum.ts +12 -0
  62. package/src/timecapsule/snapshot-taker.ts +41 -4
  63. 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