@tadashi/hash

3.0.1 • Public • Published

hash

NPM version Node.js CI Coverage Status

XO code style

Create a hash from any data (Node.js).
Create a hash from string (Browser).

Install

$ npm i @tadashi/hash

API (Node.js)

hash(data[, options])

Return: Buffer | string

data

Type: string | Buffer | TypedArray | DataView
Default: -

options

Type: Object
Default: see below

parameter type required default description
alg string no sha256 algorithm
encoding string no - encoding of the return value

API (Browser)

hash(data[, options])

Return: Promise<string|Buffer>

data

Type: string
Default: -

options

Type: Object
Default: see below

parameter type required default description
alg string no sha256 algorithm
asBuffer boolean no false return hash as buffer

Usage

Via Node

import hash from '@tadashi/hash'

const data = hash('test', {encoding: 'hex'})
// => 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08

Via Browser

⚠️ Warning

This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

import hash from 'https://unpkg.com/@tadashi/hash@{version}/src/browser.js'

const data = await hash('test', {encoding: 'hex'})
// => 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08

License

MIT © Thiago Lagden

Readme

Keywords

Package Sidebar

Install

npm i @tadashi/hash

Weekly Downloads

1

Version

3.0.1

License

MIT

Unpacked Size

5.67 kB

Total Files

5

Last publish

Collaborators

  • lagden