-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require Node.js 12.20 and move to ESM
- Loading branch information
1 parent
b17317d
commit 69bb2cf
Showing
13 changed files
with
88 additions
and
120 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
yarn.lock | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './index.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,27 @@ | ||
/* eslint-env browser */ | ||
/* global globalThis:readonly */ | ||
'use strict'; | ||
|
||
// Ponyfill for `globalThis` | ||
const _globalThis = (() => { | ||
if (typeof globalThis !== 'undefined') { | ||
return globalThis; | ||
} | ||
|
||
if (typeof self !== 'undefined') { | ||
return self; | ||
} | ||
|
||
/* istanbul ignore next */ | ||
if (typeof window !== 'undefined') { | ||
return window; | ||
} | ||
|
||
/* istanbul ignore next */ | ||
if (typeof global !== 'undefined') { | ||
return global; | ||
} | ||
})(); | ||
|
||
const bufferToHex = buffer => { | ||
const view = new DataView(buffer); | ||
|
||
let hexCodes = ''; | ||
for (let i = 0; i < view.byteLength; i += 4) { | ||
hexCodes += view.getUint32(i).toString(16).padStart(8, '0'); | ||
for (let index = 0; index < view.byteLength; index += 4) { | ||
hexCodes += view.getUint32(index).toString(16).padStart(8, '0'); | ||
} | ||
|
||
return hexCodes; | ||
}; | ||
|
||
const create = algorithm => async (buffer, options) => { | ||
const create = algorithm => async (buffer, {outputFormat = 'hex'} = {}) => { | ||
if (typeof buffer === 'string') { | ||
buffer = new _globalThis.TextEncoder().encode(buffer); | ||
buffer = new globalThis.TextEncoder().encode(buffer); | ||
} | ||
|
||
options = { | ||
outputFormat: 'hex', | ||
...options | ||
}; | ||
|
||
const hash = await _globalThis.crypto.subtle.digest(algorithm, buffer); | ||
const hash = await globalThis.crypto.subtle.digest(algorithm, buffer); | ||
|
||
return options.outputFormat === 'hex' ? bufferToHex(hash) : hash; | ||
return outputFormat === 'hex' ? bufferToHex(hash) : hash; | ||
}; | ||
|
||
exports.sha1 = create('SHA-1'); | ||
exports.sha256 = create('SHA-256'); | ||
exports.sha384 = create('SHA-384'); | ||
exports.sha512 = create('SHA-512'); | ||
export const sha1 = create('SHA-1'); | ||
export const sha256 = create('SHA-256'); | ||
export const sha384 = create('SHA-384'); | ||
export const sha512 = create('SHA-512'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters