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

farmhash-modern

v1.1.0

Published

FarmHash functions compiled using Rust and WebAssembly to make them easy to use in node.js and the browser

Downloads

2,811,138

Readme

farmhash-modern

WASM/Web-Assembly implementation of Google's FarmHash family of very fast hash functions for use in node.js and the browser. FarmHash is the successor to CityHash. Functions in the FarmHash family are not suitable for cryptography.

The existing farmhash npm packge works great if you can get it to build, but this can create a lot of pain. This WASM build should work on any operating system that uses node.js with zero extra configuration. It should be 100% consistent across different platforms. You can even use it in the browser. This package also includes TypeScript types, and a handy bigqueryFingerprint that matches BigQuery's FARM_FINGERPRINT function.

This WASM implementation is built using the farmhash Rust Crate. The 64-bit APIs use JavaScript's BigInt type to represent results. If you need a base-10 string, you can simply call .toString() on the result.

Build Status Rolling Versions NPM version

Click here for a live demo

Node.js

Installation

Install using npm or yarn.

npm install farmhash-modern
# or
yarn install farmhash-modern

Usage

Import using ES Module syntax or CommonJS syntax.

import * as farmhash from 'farmhash-modern';

console.log(farmhash.fingerprint32('hello world'));

or

const farmhash = require('farmhash-modern');

console.log(farmhash.fingerprint32('hello world'));

Webpack

Installation

npm install farmhash-modern
# or
yarn install farmhash-modern

In your webpack.config.js file, make sure you have set:

module.exports = {
  // ...
  experiments: {asyncWebAssembly: true},
  // ...
};

Also, make sure you do not have any rules that will capture .wasm files and turn them into URLs or some other format.

Usage

Import using ES Module syntax syntax.

import * as farmhash from 'farmhash-modern';

console.log(farmhash.fingerprint32('hello world'));

API

fingerprint32(input: string | Uint8Array): number

Create a new farmhash based u32 for a string or an array of bytes. Fingerprint value should be portable and stable across library versions and platforms.

fingerprint64(input: string | Uint8Array): bigint

Create a new farmhash based u64 for a string or an array of bytes. Fingerprint value should be portable and stable across library versions and platforms.

bigqueryFingerprint(input: string | Uint8Array): bigint

Create a new farmhash based i64 for a string or an array of bytes. Fingerprint value should be portable and stable across library versions and platforms.

This matches the format used by BigQuery's FARM_FINGERPRINT function.

hash32(input: string | Uint8Array): number

Create a new farmhash based u32 for an array of bytes. Hash value may vary with library version.

`hash32WithSeed(input: string | Uint8Array, seed: number): number

Create a new farmhash based u32 for an array of bytes with a given seed. Hash value may vary with library version.

hash64(input: string | Uint8Array): bigint

Create a new farmhash based u64 for an array of bytes. Hash value may vary with library version.

`hash64WithSeed(input: string | Uint8Array, seed: bigint): bigint

Create a new farmhash based u64 for an array of bytes with a given seed. Hash value may vary with library version.

Building the web-app example

  1. Install dependencies for farmhash-modern: yarn install
  2. Build farmhash-modern: yarn build
  3. Install dependencies for web-app: cd web-app && npm install
  4. Build the web-app: cd web-app && npm build

License

MIT