Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

farmhashjs

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

farmhashjs

Pure JavaScript implementation of Google's FarmHash - compatible with farmhash v3.x and v5.x

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
39
-37.1%
Maintainers
1
Weekly downloads
 
Created
Source

farmhashjs

Test and Build NPM Downloads

Pure JavaScript implementation of Google's FarmHash algorithm. No native dependencies, works in Node.js and browsers.

😘 Maintainer: @baptistejamin

Why?

The native farmhash npm package requires C++ compilation, which can be problematic:

  • Fails on some platforms (Windows, Alpine Linux, etc.)
  • Requires node-gyp and build tools
  • Doesn't work in browsers or edge runtimes

farmhashjs provides the same hash outputs with zero native dependencies.

Installation

npm install farmhashjs

Usage

import { 
  fingerprint64, fingerprint32,
  legacyHash64_arm, legacyHash64_x86,
  legacyHash32_arm, legacyHash32_x86
} from 'farmhashjs';

// Modern stable fingerprints (recommended - same on all platforms)
fingerprint64('hello world');  // "6381520714923946011"
fingerprint32('hello world');  // 430397466

// Legacy hashes (compatible with farmhash@3.3.1)
// Use _arm or _x86 suffix based on your target platform
legacyHash64_arm('hello world');  // "16022978042064026561"
legacyHash64_x86('hello world');  // "16022978042064026561" (same for <512 bytes)

legacyHash32_arm('hello world');  // 3314386015
legacyHash32_x86('hello world');  // 1955099599

API

Modern Functions (Stable Fingerprints)

These produce stable hashes guaranteed to be consistent across all platforms and versions.

FunctionReturnsDescription
fingerprint64(input)string64-bit hash as decimal string
fingerprint64BigInt(input)bigint64-bit hash as BigInt
fingerprint32(input)number32-bit hash as number

Legacy Functions (farmhash v3.x Compatible)

These are compatible with farmhash@3.3.1 which was compiled with FARMHASH_DEBUG=1.

Important: The native farmhash@3.3.1 produces different outputs on ARM64 vs x86_64 architectures. Choose the _arm or _x86 variant based on your target platform.

FunctionReturnsDescription
legacyHash64_arm(input)string64-bit hash (ARM64)
legacyHash64_x86(input)string64-bit hash (x86_64, <512 bytes)
legacyHash64BigInt_arm(input)bigint64-bit hash as BigInt (ARM64)
legacyHash64BigInt_x86(input)bigint64-bit hash as BigInt (x86_64, <512 bytes)
legacyHash32_arm(input)number32-bit hash (ARM64)
legacyHash32_x86(input)number32-bit hash (x86_64, <512 bytes)

Notes:

  • For hash64: ARM64 and x86_64 produce the same output for strings <512 bytes. For ≥512 bytes, different algorithms are used.
  • For hash32: ARM64 and x86_64 produce different outputs for ALL strings (different algorithms).
  • The x86_64 SIMD algorithm (farmhashte) is fully implemented in pure JavaScript.

Aliases

import { hash64, hash32 } from 'farmhashjs';

// hash64 = fingerprint64
// hash32 = fingerprint32

Compatibility

Tested against native implementations:

FunctionCompared Against
fingerprint64farmhash@5.0.0 fingerprint64
fingerprint32farmhash@5.0.0 fingerprint32
legacyHash64_armfarmhash@3.3.1 hash64 on ARM64
legacyHash64_x86farmhash@3.3.1 hash64 on x86_64 (<512 bytes)
legacyHash32_armfarmhash@3.3.1 hash32 on ARM64
legacyHash32_x86farmhash@3.3.1 hash32 on x86_64 (<512 bytes)

Performance

Benchmarked on Apple M1:

Function44 bytes500 bytes5 KB
fingerprint32251 ns/op903 ns/op9 µs/op
fingerprint64843 ns/op7 µs/op65 µs/op
legacyHash32_arm302 ns/op974 ns/op9 µs/op
legacyHash64_arm1.1 µs/op6.8 µs/op58 µs/op

32-bit functions are faster because they use native number operations. 64-bit functions use BigInt which has more overhead.

For comparison, native C++ (farmhash@5.0.0) is ~2-10x faster depending on input size.

When to Use

Use farmhashjs when:

  • You need cross-platform compatibility
  • You're running in browsers, Cloudflare Workers, or edge runtimes
  • You can't compile native modules
  • You're hashing moderate volumes (< 100K hashes/second)

Use native farmhash when:

  • Maximum performance is critical
  • You're in a Node.js environment that supports native modules
  • You're hashing millions of strings per second

License

Apache-2.0

This is a port of Google's FarmHash. Original FarmHash is Copyright 2014 Google Inc.

Keywords

farmhash

FAQs

Package last updated on 01 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts