@localnerve/csp-hashes 7.1.0 → 8.0.1
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/lib/index.js +3 -3
- package/package.json +4 -4
- package/readme.md +3 -3
package/lib/index.js
CHANGED
|
@@ -82,11 +82,11 @@ export function createCspHash(input, algo = 'sha256') {
|
|
|
82
82
|
* users who just have a few files to process and will handle I/O themselves,
|
|
83
83
|
* without needing a stream.
|
|
84
84
|
*
|
|
85
|
-
* @param {String} [algo] - hash algorithm, default sha256. Can be sha384, sha512.
|
|
86
85
|
* @param {Buffer|String} content - The HTML content to extract hashes from.
|
|
86
|
+
* @param {String} [algo] - hash algorithm, default sha256. Can be sha384, sha512.
|
|
87
87
|
* @returns {Object} The hashes object with script and style elements and attributes.
|
|
88
88
|
*/
|
|
89
|
-
export function cspHashes (algo = 'sha256'
|
|
89
|
+
export function cspHashes (content, algo = 'sha256') {
|
|
90
90
|
if (!/^sha(256|384|512)$/.test(algo)) {
|
|
91
91
|
throw new Error('algo option must be one of "sha256", "sha384", or "sha512" only.');
|
|
92
92
|
}
|
|
@@ -143,7 +143,7 @@ export function hashstream ({
|
|
|
143
143
|
const path = file.path;
|
|
144
144
|
const content = file.contents;
|
|
145
145
|
|
|
146
|
-
const hashes = cspHashes(
|
|
146
|
+
const hashes = cspHashes(content, algo);
|
|
147
147
|
|
|
148
148
|
if (replace) {
|
|
149
149
|
const s = callback(path, hashes, content.toString());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@localnerve/csp-hashes",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.1",
|
|
4
4
|
"description": "Flexible library to generate CSP hashes",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@eslint/js": "^10.0.1",
|
|
18
|
-
"eslint": "^10.8.
|
|
19
|
-
"eslint-plugin-n": "^18.
|
|
20
|
-
"globals": "^17.
|
|
18
|
+
"eslint": "^10.8.1",
|
|
19
|
+
"eslint-plugin-n": "^18.3.0",
|
|
20
|
+
"globals": "^17.9.0",
|
|
21
21
|
"vinyl": "^3.0.1"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
package/readme.md
CHANGED
|
@@ -54,11 +54,11 @@ See [`hashstream options`](#hashstream-options) for a detailed explanation of th
|
|
|
54
54
|
This library exports a convenience function that takes an algorithm and HTML content, and returns a hashes object containing all CSP hashes for inline scripts and styles. This is useful for users who just have a few files to process and will handle I/O themselves, without needing a stream.
|
|
55
55
|
|
|
56
56
|
```
|
|
57
|
-
Object cspHashes(algo = 'sha256'
|
|
57
|
+
Object cspHashes(content, algo = 'sha256')
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
+ {String} **\[algo\]** - Optional - Defaults to `'sha256'`, can be one of 'sha256', 'sha384' or 'sha512'.
|
|
61
60
|
+ {Buffer|String} **content** - Required - The HTML content to extract hashes from.
|
|
61
|
+
+ {String} **\[algo\]** - Optional - Defaults to `'sha256'`, can be one of 'sha256', 'sha384' or 'sha512'.
|
|
62
62
|
|
|
63
63
|
Returns a [`hashes` object](#callback-hashes-object) with the same structure as the `hashstream` callback receives:
|
|
64
64
|
|
|
@@ -215,7 +215,7 @@ import fs from 'node:fs';
|
|
|
215
215
|
import { cspHashes } from '@localnerve/csp-hashes';
|
|
216
216
|
|
|
217
217
|
const html = fs.readFileSync('./dist/index.html', { encoding: 'utf8' });
|
|
218
|
-
const hashes = cspHashes('sha256'
|
|
218
|
+
const hashes = cspHashes(html, 'sha256');
|
|
219
219
|
|
|
220
220
|
console.log('Script element hashes:', hashes.script.elements.join(' '));
|
|
221
221
|
console.log('Style attribute hashes:', hashes.style.attributes.join(' '));
|