npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

browser-checksum

v1.0.5

Published

A browser based solution for calculating checksums of various types.

Downloads

20

Readme

⚡ About

Browser CheckSum is a straightforward checksum library that enables you to generate checksums for various data types. It supports strings, numbers, arrays, objects, and more. Browser CheckSum is a lightweight library that is easy to use and provides a simple API for generating checksums.

Browser CheckSum came around when I needed a universal function to generate checksums for various data types. I wanted a simple and easy-to-use library that could generate checksums for strings, numbers, arrays, objects and most importantly files. I couldn't find a library that met my requirements, so I decided to create Browser CheckSum.

Essentially, it's like running the cli tool sha1sum (any of the sha*sum commands) on a file

❓ Why Browser CheckSum?

Have you ever needed to generate a checksum for a file in the browser? You need to use the poorly designed FileReader API on said file, read the file in as an ArrayBuffer, and then pass this off to the browsers native crypto API and convert that back into human readable hex.

So instead of this: File -> Promise Wrapped FileReader -> ArrayBuffer -> Crypto API -> HashBuffer -> Hexed Hash (And this is just the workflow for a file, not even a string or object!)

You can do this: File -> Browser CheckSum -> Hexed Hash

const checksum: string = await BrowserCheckSum.fileChecksum(file, "SHA-256");

Why should it be anymore complicated than that?

So why would you use Browser CheckSum? Edge computing, client-side security, content-addressable storage keys or just to generate checksums in the browser. Let's say, you operate a p2p browser file sharing service, and you want to validate the integrity of the files being shared. You could use Browser CheckSum to generate checksums for the files and validate them on the client-side.

💻 Usage

  1. Installation using npm:
npm browser-checksum
  1. Import it into your project:
import { BrowserCheckSum } from "browser-checksum";

🤖 Examples

import { BrowserCheckSum } from "browser-checksum";

// Calculate the checksum of 'Hello, World!' in SHA1
const checksum = await BrowserCheckSum.checkSum("Hello, World!");

// Calculate the checksum of a file in SHA2-56
const file = document.getElementById("FileForm").files[0];
const fileChecksum = await BrowserCheckSum.fileChecksum(file, "SHA-256");

// Calculate the checksum of an object in SHA-384
const object = { key: "value" };
const objectChecksum = await BrowserCheckSum.checkSum(object, "SHA-384");

// Calculate the checksum of an array in SHA1
const array = [1, 2, 3, 4, 5];
const arrayChecksum = await BrowserCheckSum.checkSum(array, "SHA-1");

// Calculate the checksum of an array buffer in SHA-256
const arrayBuffer = new ArrayBuffer(16);
const arrayBufferChecksum = await BrowserCheckSum.checkSum(arrayBuffer, "SHA-256");

🐔 Limitations

The library is limited to the algorithms supported by the browser's native crypto API. This means that the library does not support MD5 or SHA-0 etc. Therefore it's limited to the following algorithms:

  • SHA-1
  • SHA-256
  • SHA-384
  • SHA-512

Due to its reliance on the browser's native crypto API, the library is only compatible with es2017 / ES8 browsers and above (Which is 98% of browsers).