Skip to content

Latest commit

 

History

History
70 lines (55 loc) · 2.54 KB

API.md

File metadata and controls

70 lines (55 loc) · 2.54 KB

get-sri

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

getSRI(string, [algorithm], [prefix]) ⇒ string

Generates the SRI hash of the given string.

Kind: Exported function
Returns: string - The generated SRI string.

ParamTypeDefaultDescription
stringstring

The string to use to calculate the SRI hash.

[algorithm]string"'sha256'"

The hash algorithm to use to generate the SRI hash.

[prefix]booleanfalse

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='

getSRI.SHA256 : string

The 'sha256' hash algorithm constant.

Kind: static constant of getSRI

getSRI.SHA384 : string

The 'sha384' hash algorithm constant.

Kind: static constant of getSRI

getSRI.SHA512 : string

The 'sha512' hash algorithm constant.

Kind: static constant of getSRI