mentie 0.1.23 → 0.2.24
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 +2 -1
- package/modules/crypto.js +27 -0
- package/modules/environment.js +1 -1
- package/package.json +3 -2
package/index.js
CHANGED
|
@@ -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/modules/environment.js
CHANGED
|
@@ -21,7 +21,7 @@ env.is_web = () => typeof window !== 'undefined'
|
|
|
21
21
|
*
|
|
22
22
|
* @returns {boolean} True if running in a web browser and the URL includes 'localhost', otherwise false.
|
|
23
23
|
*/
|
|
24
|
-
env.is_localhost = () => env.is_web() && `${ location.href }`.includes(
|
|
24
|
+
env.is_localhost = () => env.is_web() && [ 'localhost', '127.0.0.1', '::1' ].some( host => `${ location.href }`.includes( host ) )
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Checks if the code is running in the Cypress testing environment within a web browser.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mentie",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.24",
|
|
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"
|