@icgio/icg-utils 1.9.7 → 1.9.9
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/index.js +0 -1
- package/lib/utils.js +7 -2
- package/package.json +1 -1
- package/lib/observable.js +0 -53
package/index.js
CHANGED
|
@@ -7,7 +7,6 @@ module.exports = {
|
|
|
7
7
|
ip: require('./lib/ip.js'),
|
|
8
8
|
logger: require('./lib/logger.js'),
|
|
9
9
|
mail: require('./lib/mail.js'),
|
|
10
|
-
observable: require('./lib/observable.js'),
|
|
11
10
|
ohlcv: require('./lib/ohlcv'),
|
|
12
11
|
rate_limiter_logger: require('./lib/rate-limit-logger.js'),
|
|
13
12
|
rate_limiter: require('./lib/rate-limiter.js'),
|
package/lib/utils.js
CHANGED
|
@@ -847,8 +847,13 @@ module.exports.random_normal_range = (mean, std_dev, a, b) => {
|
|
|
847
847
|
let v = Math.random()
|
|
848
848
|
let z = Math.sqrt(-2.0 * Math.log(u)) * Math.cos(2.0 * Math.PI * v) // Box-Muller Transform
|
|
849
849
|
let num = mean + z * std_dev
|
|
850
|
-
// Clip to range
|
|
851
850
|
return Math.max(min, Math.min(max, num))
|
|
852
851
|
}
|
|
853
852
|
|
|
854
|
-
|
|
853
|
+
// module.exports.random_beta_range = (alpha, beta, a, b) => {
|
|
854
|
+
// let u = Math.random()
|
|
855
|
+
// let v = Math.random()
|
|
856
|
+
// let value = Math.pow(u, 1 / alpha) / (Math.pow(u, 1 / alpha) + Math.pow(v, 1 / beta))
|
|
857
|
+
// return a + value * (b - a) // Scale result into [a, b] range
|
|
858
|
+
// }
|
|
859
|
+
// console.log(module.exports.random_beta_range(1, 100, 0.02, 0.03))
|
package/package.json
CHANGED
package/lib/observable.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
class Observable {
|
|
2
|
-
constructor() {
|
|
3
|
-
this.listeners = []
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Subscribe to changes
|
|
8
|
-
* @param {Function} callback - Function to call when an update occurs
|
|
9
|
-
*/
|
|
10
|
-
subscribe(callback) {
|
|
11
|
-
if (typeof callback !== 'function') {
|
|
12
|
-
throw new Error('Callback must be a function')
|
|
13
|
-
}
|
|
14
|
-
this.listeners.push(callback)
|
|
15
|
-
return () => this.unsubscribe(callback) // Return an unsubscribe function
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Unsubscribe from changes
|
|
20
|
-
* @param {Function} callback - The callback to remove
|
|
21
|
-
*/
|
|
22
|
-
unsubscribe(callback) {
|
|
23
|
-
this.listeners = this.listeners.filter((listener) => listener !== callback)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Notify all subscribers about an update
|
|
28
|
-
* @param {*} data - The data to pass to subscribers
|
|
29
|
-
*/
|
|
30
|
-
notify(data) {
|
|
31
|
-
this.listeners.forEach((callback) => callback(data))
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
module.exports = Observable
|
|
36
|
-
|
|
37
|
-
// // Example Usage
|
|
38
|
-
// const observable = new Observable()
|
|
39
|
-
|
|
40
|
-
// // Subscribe to updates
|
|
41
|
-
// const unsubscribe = observable.subscribe((update) => {
|
|
42
|
-
// console.log('Received update:', update)
|
|
43
|
-
// })
|
|
44
|
-
|
|
45
|
-
// // Emit updates
|
|
46
|
-
// observable.notify({ message: 'Hello, world!' }) // Logs: Received update: { message: 'Hello, world!' }
|
|
47
|
-
// observable.notify({ message: 'Another update!' }) // Logs: Received update: { message: 'Another update!' }
|
|
48
|
-
|
|
49
|
-
// // Unsubscribe from updates
|
|
50
|
-
// unsubscribe()
|
|
51
|
-
|
|
52
|
-
// // No logs after unsubscribe
|
|
53
|
-
// observable.notify({ message: 'No one will see this' })
|