Generates the SRI hash of the given string to use with CDN resources without publishing the content to a CDN.
Version: 1.0.2
Author: Richard Szakacs richardszkcs@gmail.com (www.richardszkcs.com)
License: MIT
- get-sri
- getSRI(string, [algorithm], [prefix]) ⇒
string
⏏
- getSRI(string, [algorithm], [prefix]) ⇒
Generates the SRI hash of the given string.
Kind: Exported function
Returns: string
- The generated SRI string.
Param | Type | Default | Description |
---|---|---|---|
string | string | The string to use to calculate the SRI hash. |
|
[algorithm] | string | "'sha256'" | The hash algorithm to use to generate the SRI hash. |
[prefix] | boolean | false | Whether to prefix the algorithm type to the generated hash (e.g.: 'sha256-...'). |
Example
const getSRI = require('get-sri')
// returns the SRI hash without prefix ('sha256' by default)
getSRI('... file content as string ...') // 'OXPgIukyI[...]6SgMU3pmfURI='
// returns the SRI hash with prefix ('sha256' by default, can be 'sha256', 'sha384', or 'sha512')
getSRI('... file content as string ...', getSRI.SHA256, true) // 'sha256-OXPgIukyI[...]6SgMU3pmfURI='
The 'sha256' hash algorithm constant.
Kind: static constant of getSRI
The 'sha384' hash algorithm constant.
Kind: static constant of getSRI
The 'sha512' hash algorithm constant.
Kind: static constant of getSRI