mentie 0.1.23 → 0.2.23

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 CHANGED
@@ -5,4 +5,5 @@ export * from './modules/validations.js'
5
5
  export * from './modules/text.js'
6
6
  export * from './modules/numbers.js'
7
7
  export * from './modules/promises.js'
8
- export * from './modules/cache.js'
8
+ export * from './modules/cache.js'
9
+ export * from './modules/crypto.js'
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Calculates the hash of the given data using the specified algorithm.
3
+ *
4
+ * @param {string} data - The data to be hashed.
5
+ * @param {string} [algo='sha256'] - The algorithm to be used for hashing. Defaults to 'sha256'.
6
+ * @param {string} [_digest='hex'] - The encoding of the output hash. Defaults to '
7
+ * @returns {Promise<string>} The hashed value of the data.
8
+ */
9
+ export async function hash( data, algo='sha256', _digest='hex' ) {
10
+
11
+ try {
12
+
13
+ // Native node way
14
+ const { createHash } = await import( 'crypto' )
15
+ const _hash = createHash( algo ).update( data ).digest( _digest )
16
+ return _hash
17
+
18
+ } catch {
19
+
20
+ // Dependency-based way
21
+ const { default: hash } = await import( 'hash.js' )
22
+ const _hash = hash[ algo ]().update( data ).digest( _digest )
23
+ return _hash
24
+
25
+ }
26
+
27
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mentie",
3
- "version": "0.1.23",
3
+ "version": "0.2.23",
4
4
  "description": "Mentor's toolbelt",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -29,7 +29,8 @@
29
29
  },
30
30
  "peerDependencies": {
31
31
  "promise-parallel-throttle": "^3.5.0",
32
- "promise-retry": "^2.0.1"
32
+ "promise-retry": "^2.0.1",
33
+ "hash.js": "^1.1.7"
33
34
  },
34
35
  "dependencies": {
35
36
  "safe-stable-stringify": "^2.4.3"