mentie 0.3.7 → 0.3.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/modules/cache.js CHANGED
@@ -42,6 +42,47 @@ export function cache( key, value, expires_in_ms=Infinity ) {
42
42
  return _cache[key]?.value
43
43
  }
44
44
 
45
+ /**
46
+ *
47
+ * @returns {Object} - A copy of the cache object.
48
+ */
49
+ cache.dump = () => {
50
+
51
+ // Return a copy of the cache object
52
+ return { ..._cache }
53
+
54
+ }
55
+
56
+ /**
57
+ *
58
+ * @returns {Object} stats - An object containing statistics about the cache.
59
+ * @returns {number} stats.keys - The number of keys in the cache.
60
+ * @returns {number} stats.size_bytes - The size of the cache in bytes.
61
+ * @returns {string} stats.size_mib - The size of the cache in MiB, rounded to 2 decimal places.
62
+ * @returns {string} stats.size_gib - The size of the cache in GiB, rounded to 2 decimal places.
63
+ */
64
+ cache.stats = () => {
65
+
66
+ // Get the number of keys in the cache
67
+ const keys = Object.keys( _cache ).length
68
+
69
+ // Get the size in bytes of the cache
70
+ const size_bytes = keys.reduce( ( acc, key ) => acc + JSON.stringify( _cache[key] ).length, 0 )
71
+
72
+ // Calculate side to MiB and GiB, both rounded to 2 decimal places
73
+ const size_mib = ( size_bytes / ( 1024 * 1024 ) ).toFixed( 2 )
74
+ const size_gib = ( size_bytes / ( 1024 * 1024 * 1024 ) ).toFixed( 2 )
75
+
76
+ // Return the stats
77
+ return {
78
+ keys,
79
+ size_bytes,
80
+ size_mib,
81
+ size_gib
82
+ }
83
+
84
+ }
85
+
45
86
  /**
46
87
  * Function to inspect concurrency.
47
88
  *
@@ -81,13 +81,13 @@ env.loglevel = () => env.web_loglevel() || env.node_loglevel() || env.dev() ? 'i
81
81
  * Retrieves the log annotations set via URL parameters in a web environment.
82
82
  * @returns {Array<string>|boolean} An array of log annotations from URL parameters, or false if not set.
83
83
  */
84
- env.web_log_annotations = () => env.is_web() && new URLSearchParams( location?.search ).get( 'log_annotations' ).split( ',' ).filter( Boolean ).map( annotation => annotation.trim() )
84
+ env.web_log_annotations = () => env.is_web() && new URLSearchParams( location?.search ).get( 'log_annotations' )?.split( ',' )?.filter( Boolean )?.map( annotation => annotation?.trim() )
85
85
 
86
86
  /**
87
87
  * Retrieves the log annotations set via environment variables in a Node.js environment.
88
88
  * @returns {Array<string>|boolean} An array of log annotations from environment variables, or false if not set.
89
89
  */
90
- env.node_log_annotations = () => env.is_node() && process.env?.LOG_ANNOTATIONS?.split( ',' ).filter( Boolean ).map( annotation => annotation.trim() )
90
+ env.node_log_annotations = () => env.is_node() && process.env?.LOG_ANNOTATIONS?.split( ',' )?.filter( Boolean )?.map( annotation => annotation?.trim() )
91
91
 
92
92
  /**
93
93
  * Retrieves the effective log annotations based on the environment. Defaults to an empty array if not set.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mentie",
3
- "version": "0.3.7",
3
+ "version": "0.3.9",
4
4
  "description": "Mentor's toolbelt",
5
5
  "type": "module",
6
6
  "main": "index.js",