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 🙏

© 2026 – Pkg Stats / Ryan Hefner

pra-decode

v2.0.0

Published

A lightweight JavaScript library for secure SHA-256 hashing and decoding.

Downloads

7

Readme

pra-decode

pra-decode is a comprehensive JavaScript hashing utility featuring SHA-256 implementation with multiple encoding options and comparison functionality.

Features

  • 🔒 Secure Hashing: SHA-256 algorithm implementation
  • 🔄 Multiple Encodings: Support for hex, base64, and binary formats
  • ↔️ Comparison Utility: Easily verify hashes against plaintext
  • Lightweight: Zero external dependencies
  • 🛠 Utility Functions: Encoding conversion helpers

Installation

npm install pra-decode
# or
yarn add pra-decode

Basic Usage

const praDecode = require('pra-decode');

// Hash a string (defaults to hex output)
const hash = praDecode.toHash('password123');
console.log('Hashed password:', hash);

// Verify a password
const isValid = praDecode.toCompare('password123', hash);
console.log('Password valid:', isValid); // true

API Reference

Core Methods

toHash(input, [options])

Generates SHA-256 hash of input.

Parameters:

  • input (string|Buffer): Input to hash
  • options (object): Optional settings
    • inputEncoding (string): 'utf8' (default), 'hex', or 'base64'
    • outputEncoding (string): 'hex' (default), 'base64', or 'binary'

Returns:
string (hex/base64) or Uint8Array (binary)

Examples:

// Hex output (default)
praDecode.toHash('hello');

// Base64 output
praDecode.toHash('hello', { outputEncoding: 'base64' });

// Binary output
praDecode.toHash('hello', { outputEncoding: 'binary' });

// Hex input
praDecode.toHash('68656c6c6f', { inputEncoding: 'hex' });

toCompare(input, hash, [options])

Compares input with a hash.

Parameters:

  • input (string|Buffer): Input to compare
  • hash (string): Hash to compare against
  • options (object): Optional settings
    • inputEncoding (string): 'utf8' (default), 'hex', or 'base64'
    • hashEncoding (string): 'hex' (default), 'base64', or 'binary'

Returns:
boolean - true if input matches hash

Example:

const valid = praDecode.toCompare('password123', storedHash, {
  hashEncoding: 'base64'
});

sha256(input, [options])

Alias for toHash() with identical parameters and return values.

Utility Methods

Access encoding utilities through praDecode.utils:

const { utils } = praDecode;

// Convert between formats
const bytes = new Uint8Array([72, 101, 108, 108, 111]);
const hex = utils.bytesToHex(bytes);        // '48656c6c6f'
const base64 = utils.bytesToBase64(bytes); // 'SGVsbG8='

// Convert back
const newBytes = utils.hexToBytes('48656c6c6f');

Available utility functions:

  • bytesToHex(bytes)
  • hexToBytes(hex)
  • bytesToBase64(bytes)
  • base64ToBytes(base64)

Advanced Usage

File Hashing Example

const fs = require('fs');
const praDecode = require('pra-decode');

const fileBuffer = fs.readFileSync('example.txt');
const fileHash = praDecode.toHash(fileBuffer, {
  inputEncoding: 'binary',
  outputEncoding: 'hex'
});

console.log('File hash:', fileHash);

Performance

The implementation is optimized for performance:

  • Processes data in 512-bit chunks
  • Uses bitwise operations for efficient computation
  • Minimal memory overhead

Security Notes

  • SHA-256 is cryptographically secure for most applications
  • For password storage, consider using PBKDF2 or bcrypt with salt
  • Always compare hashes using constant-time comparison in security contexts

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Open a Pull Request

License

MIT

Contact

For support or questions: