This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

View File

@@ -0,0 +1,29 @@
/**
* react-loadable-ssr-addon
* @author Marcos Gonçalves <contact@themgoncalves.com>
* @version 1.0.1
*/
import crypto from 'crypto';
/**
* Compute SRI Integrity
* @func computeIntegrity
* See {@link https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity Subresource Integrity} at MDN
* @param {array} algorithms - The algorithms you want to use when hashing `content`
* @param {string} source - File contents you want to hash
* @return {string} SRI hash
*/
function computeIntegrity(algorithms, source) {
return Array.isArray(algorithms)
? algorithms.map((algorithm) => {
const hash = crypto
.createHash(algorithm)
.update(source, 'utf8')
.digest('base64');
return `${algorithm}-${hash}`;
}).join(' ')
: '';
}
export default computeIntegrity;