get-sri
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

get-sri

Node.js Version Travis CI - Build Status AppVeyor CI - Build Status Coveralls - Code Coverage Status JavaScript Style Guide PRs Welcome

Generates the SRI (Subresource Integrity) hash of the given string to use as the SRIs of CDN files without publishing the content to CDN (e.g. when generating the readme file before release and publish).

With get-sri, you can just simply generate the sha256-j7UhB[...]5ni2s= part of the integrity attribute for <link> and <script> elements, e.g.:

<script src="https://example.com/example-framework.js" 
        integrity="sha256-j7UhB8zxegHMV59uYb38Ho75sqloISge2+fsjN5ni2s=" 
        crossorigin="anonymous"></script> 

Installation

# Using NPM 
npm install get-sri --save-dev
# Using Yarn 
yarn add get-sri --dev

Usage

The API documentation can be found here.

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

Contribution

Any contribution is appreciated. To get going, check out the contribution guidelines. Thank you and have fun!

License

MIT @ Richard Szakacs

Package Sidebar

Install

npm i get-sri

Weekly Downloads

145

Version

1.0.2

License

MIT

Unpacked Size

10.9 kB

Total Files

6

Last publish

Collaborators

  • richardszkcs