@operato/utils 2.0.0-alpha.0 → 2.0.0-alpha.110

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 (73) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/demo/index.html +13 -2
  3. package/dist/src/adjust-list-param.d.ts +14 -0
  4. package/dist/src/adjust-list-param.js +8 -0
  5. package/dist/src/adjust-list-param.js.map +1 -1
  6. package/dist/src/async-lock.d.ts +13 -0
  7. package/dist/src/async-lock.js +13 -0
  8. package/dist/src/async-lock.js.map +1 -1
  9. package/dist/src/clipboard.d.ts +7 -0
  10. package/dist/src/clipboard.js +7 -0
  11. package/dist/src/clipboard.js.map +1 -1
  12. package/dist/src/closest-element.d.ts +7 -0
  13. package/dist/src/closest-element.js +7 -0
  14. package/dist/src/closest-element.js.map +1 -1
  15. package/dist/src/context-path.d.ts +15 -0
  16. package/dist/src/context-path.js +20 -0
  17. package/dist/src/context-path.js.map +1 -1
  18. package/dist/src/cookie.d.ts +18 -0
  19. package/dist/src/cookie.js +18 -0
  20. package/dist/src/cookie.js.map +1 -1
  21. package/dist/src/detect-overflow.d.ts +6 -0
  22. package/dist/src/detect-overflow.js +6 -0
  23. package/dist/src/detect-overflow.js.map +1 -1
  24. package/dist/src/format.d.ts +12 -0
  25. package/dist/src/format.js +12 -0
  26. package/dist/src/format.js.map +1 -1
  27. package/dist/src/index.d.ts +1 -1
  28. package/dist/src/index.js +1 -1
  29. package/dist/src/index.js.map +1 -1
  30. package/dist/src/logger.d.ts +15 -0
  31. package/dist/src/logger.js +15 -3
  32. package/dist/src/logger.js.map +1 -1
  33. package/dist/src/mixins/infinite-scrollable.d.ts +24 -0
  34. package/dist/src/mixins/infinite-scrollable.js +24 -0
  35. package/dist/src/mixins/infinite-scrollable.js.map +1 -1
  36. package/dist/src/{checker.js → number-parser.js} +1 -1
  37. package/dist/src/number-parser.js.map +1 -0
  38. package/dist/src/os.d.ts +4 -0
  39. package/dist/src/os.js +4 -0
  40. package/dist/src/os.js.map +1 -1
  41. package/dist/src/password-pattern.d.ts +15 -0
  42. package/dist/src/password-pattern.js +15 -0
  43. package/dist/src/password-pattern.js.map +1 -1
  44. package/dist/src/stringify-bignum.d.ts +11 -0
  45. package/dist/src/stringify-bignum.js +11 -0
  46. package/dist/src/stringify-bignum.js.map +1 -1
  47. package/dist/src/timecapsule/snapshot-taker.d.ts +31 -0
  48. package/dist/src/timecapsule/snapshot-taker.js +36 -3
  49. package/dist/src/timecapsule/snapshot-taker.js.map +1 -1
  50. package/dist/src/timecapsule/timecapsule.d.ts +50 -0
  51. package/dist/src/timecapsule/timecapsule.js +50 -3
  52. package/dist/src/timecapsule/timecapsule.js.map +1 -1
  53. package/dist/tsconfig.tsbuildinfo +1 -1
  54. package/package.json +12 -12
  55. package/src/adjust-list-param.ts +20 -0
  56. package/src/async-lock.ts +13 -0
  57. package/src/clipboard.ts +7 -0
  58. package/src/closest-element.ts +8 -0
  59. package/src/context-path.ts +20 -0
  60. package/src/cookie.ts +18 -0
  61. package/src/detect-overflow.ts +6 -0
  62. package/src/format.ts +12 -0
  63. package/src/index.ts +1 -1
  64. package/src/logger.ts +15 -4
  65. package/src/mixins/infinite-scrollable.ts +24 -0
  66. package/src/os.ts +4 -0
  67. package/src/password-pattern.ts +15 -0
  68. package/src/stringify-bignum.ts +12 -0
  69. package/src/timecapsule/snapshot-taker.ts +41 -4
  70. package/src/timecapsule/timecapsule.ts +50 -4
  71. package/dist/src/checker.js.map +0 -1
  72. /package/dist/src/{checker.d.ts → number-parser.d.ts} +0 -0
  73. /package/src/{checker.ts → number-parser.ts} +0 -0
@@ -1,10 +1,11 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
1
  import { TimeCapsule } from './timecapsule'
6
2
  import debounce from 'lodash-es/debounce'
7
3
 
4
+ /**
5
+ * A function that takes a SnapshotTaker as an argument and initiates snapshot creation
6
+ * using a debouncer to delay the process.
7
+ * @param {SnapshotTaker} taker - The SnapshotTaker instance to trigger snapshots for.
8
+ */
8
9
  var debouncer = debounce(
9
10
  taker => {
10
11
  if (!taker.brake) {
@@ -15,15 +16,28 @@ var debouncer = debounce(
15
16
  { leading: true, trailing: false }
16
17
  )
17
18
 
19
+ /**
20
+ * Function to trigger snapshot creation for a SnapshotTaker instance.
21
+ * Checks if the taker is in a brake state or not dirty before triggering the snapshot.
22
+ * @param {SnapshotTaker} taker - The SnapshotTaker instance to create a snapshot for.
23
+ */
18
24
  function take_snapshot(taker: SnapshotTaker) {
19
25
  if (taker.brake || !taker.dirty) return
20
26
  debouncer(taker)
21
27
  }
22
28
 
29
+ /**
30
+ * Type definition for holding state information.
31
+ * @typedef {Object} StateHolder
32
+ * @property {*} state - The state to be held.
33
+ */
23
34
  export type StateHolder = {
24
35
  state: any
25
36
  }
26
37
 
38
+ /**
39
+ * Class responsible for taking and managing snapshots of state.
40
+ */
27
41
  export class SnapshotTaker {
28
42
  private _brake: boolean = false
29
43
 
@@ -32,23 +46,38 @@ export class SnapshotTaker {
32
46
  state_holder?: StateHolder
33
47
  timecapsule?: TimeCapsule
34
48
 
49
+ /**
50
+ * Creates an instance of SnapshotTaker.
51
+ * @param {*} state_holder - The object that holds the state to be snapshot.
52
+ * @param {TimeCapsule} timecapsule - The TimeCapsule instance associated with this SnapshotTaker.
53
+ */
35
54
  constructor(state_holder: any, timecapsule: TimeCapsule) {
36
55
  this.state_holder = state_holder
37
56
  this.timecapsule = timecapsule
38
57
  this.timecapsule.snapshot_taker = this
39
58
  }
40
59
 
60
+ /**
61
+ * Disposes of the SnapshotTaker and clears associated references.
62
+ */
41
63
  dispose() {
42
64
  delete this.state_holder
43
65
  delete this.timecapsule
44
66
  }
45
67
 
68
+ /**
69
+ * Marks the SnapshotTaker as dirty and initiates snapshot creation.
70
+ */
46
71
  touch() {
47
72
  this.dirty = true
48
73
  take_snapshot(this)
49
74
  }
50
75
 
51
76
  /* 모든 조건에 관계없이 현재 상태를 snapshot으로 취한다. */
77
+ /**
78
+ * Takes a snapshot of the current state.
79
+ * @param {boolean} [force=false] - If true, the snapshot is taken even if not dirty.
80
+ */
52
81
  take(force: boolean = false) {
53
82
  if (this.dirty || force) {
54
83
  this.timecapsule?.snapshot(this.state_holder?.state)
@@ -56,11 +85,19 @@ export class SnapshotTaker {
56
85
  }
57
86
  }
58
87
 
88
+ /**
89
+ * Gets the brake state of the SnapshotTaker.
90
+ * @returns {boolean} - true if the brake is active, false otherwise.
91
+ */
59
92
  get brake() {
60
93
  return this._brake
61
94
  }
62
95
 
63
96
  /* 마우스를 드래깅하는 동안, 보통 brake 를 ON 시킨다. */
97
+ /**
98
+ * Sets the brake state of the SnapshotTaker and initiates snapshot creation.
99
+ * @param {boolean} brake - The new brake state.
100
+ */
64
101
  set brake(brake) {
65
102
  this._brake = !!brake
66
103
  take_snapshot(this)
@@ -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
@@ -1 +0,0 @@
1
- {"version":3,"file":"checker.js","sourceRoot":"","sources":["../../src/checker.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,mBAAmB;AACnB,mBAAmB;AACnB,mBAAmB;AACnB,mBAAmB;AACnB,mBAAmB;AACnB,mBAAmB;AACnB,oBAAoB;AACpB,oBAAoB;AACpB,oBAAoB;AACpB,oBAAoB;AACpB,oBAAoB;AACpB,oBAAoB;AACpB,oBAAoB;AACpB,MAAM,UAAU,mBAAmB,CAAC,KAAU;IAC5C,IAAI,MAAM,GAAkB,IAAI,CAAA;IAEhC,6BAA6B;IAC7B,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,IAAI,KAAK,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAe,CAAC,EAAE,CAAC;QACxG,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;IACxB,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["// 숫자라면 숫자값을, 아니면 null을 반환\n// 0 = true\n// '0' = true\n// 123 = true\n// \"123\" = true\n// -123 = true\n// \"-123\" = true\n// true = false\n// false = false\n// \"\" = false\n// null = false\n// undefined = false\n// {} = false\n// [] = false\nexport function parseToNumberOrNull(value: any): number | null {\n let result: number | null = null\n\n // 숫자나 스트링이면서 NaN이 아니면 숫자로 변환\n if ((typeof value === 'string' || typeof value === 'number') && value !== '' && !isNaN(value as number)) {\n result = Number(value)\n }\n\n return result\n}\n"]}
File without changes
File without changes