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

twoxhash-wasm

v0.2.1

Published

xxhash implementation in WebAssembly using Rust twox-hash crate

Downloads

4

Readme

twoxhash-wasm

A WebAssembly implementation of the xxhash hashing algorithm. Written in Rust using the twox-hash crate and wasm-bindgen.

Using WebAssembly doesn't mean you have to give up the nice things Javascript has to offer. twoxhash-wasm offload the heavy computation to WebAssembly while you continue to write Javascript!

Usage

The main bundle and WebAssembly code are loaded in only when needed, thus an initialization function needs to be called before any additional functionalities are available. Everything are scoped under the twoxhash namespace.

// The `init()` function returns a promise when all external modules are loaded
twoxhash.init().then(() => {
	// Create a 64-bit xxhash hasher instance
	const hasher = new twoxhash.XXHash64();

	// Simple one line hash, this is always independent of hasher's internal state
	let result = hasher.hash("Hello, world!"); // f58336a78b6f9476

	// Initialize hasher with a seed
	hasher.init(42);
	// Update internal state of hasher
	hasher.update("One");
	hasher.update("Two");
	hasher.update("Three");
	// Get hash result
	result = hasher.digest(); // 76cfb4ada0be05cd
	// The hasher can be continually updated with data even after calling `digest()`
	// Call `hasher.init()` again to reset hasher's internal state
});

Available hasher constructors are:

  • XXHash32
  • XXHash64
  • XXHash3 - xxhash3 with 64-bit output
  • XXHash128 - xxhash3 with 128-bit output

All hasher instances regardless of constructors have the same methods:

  • hasher.init([seed: number]): Initialize the hasher with an optional seed value. wasm-bindgen converts the input value into a u64, truncation may occur near upper limit of possible value.
  • hasher.update(value: String|Uint8Array): Update internal state of the hasher with provided value. Both String or Uint8Array can be passed in, more value types may be added in the future.
  • hasher.digest(): Returns the value of the hash at the hasher's current state. Does not reset the hasher. Result returned as a base 16 string, more flexible ways to return data may be added in the future.
  • hasher.hash(value: String|Uint8Array, [seed: number]): One off hashing that does not use nor alter the internal state of the hasher. Optional seed can be provided the same way as hasher.init(). Result returned the same wat as hasher.digest().

Future

I had fun coding this up and still have plenty of ideas about extending it! The ultimate aim is to create an easy to use interface while leveraging the performance of WebAssembly.

This project does not have lofty claims of having the smallest package size or the fastest implementation, while it does take those into account, the point is to make something fast while easy to use. There's no point in creating the smallest bundle size if the code is spaghetti all the way down, that's code golf. There's also no point in creating the fastest bundle size if it feels like you are using C/C++/Rust or some other programming language, I'll leave that exercise to someone else.