An open API service indexing awesome lists of open source software.

https://github.com/pioner92/react-native-xxhash

💪 A high-performance React Native library for generating xxHash hashes using C++ and JSI
https://github.com/pioner92/react-native-xxhash

android hash ios javascript jni jsi quickhash react react-native react-native-hash react-native-jsi react-native-xxhash xxhash xxhash-library xxhash3

Last synced: about 2 months ago
JSON representation

💪 A high-performance React Native library for generating xxHash hashes using C++ and JSI

Awesome Lists containing this project

README

          

# react-native-xxhash

A React Native library for hashing strings using the fast and deterministic xxHash algorithm, written in C++ with JSI for high performance. This library provides support for both 64-bit and 128-bit hashing.

## Features

- **High Performance**: xxHash is one of the fastest non-cryptographic hash functions.
- **Deterministic Hashing**: Ensures consistent results for the same input.
- **128-bit and 64-bit Support**: Choose between 128-bit and 64-bit hash outputs based on your use case.
- **Cross-Platform**: Supports both iOS and Android in React Native projects.

# Benchmarks (https://xxhash.com)
Screenshot 2025-10-23 at 09 48 25

## Installation

To install the library, use either `npm` or `yarn`:

```sh
npm install react-native-xxhash
```

```sh
yarn add react-native-xxhash
```

## iOS
```sh
pod install
```

---

## Usage

Here’s how to use the `react-native-xxhash` library in your React Native project:

### Import the Functions
```javascript
import { hash128, hash64 } from 'react-native-xxhash';
```

### Hash a String (128-bit)
This function generates a fast and deterministic 128-bit hash for a given string input.

```javascript
const resultHash128 = hash128("hello world");
console.log('128-bit hash:', resultHash128);
// Output: A 128-bit hash string
```

### Hash a String (64-bit)
This function generates a fast and deterministic 64-bit hash for a given string input.

```javascript
const resultHash64 = hash64("hello world");
console.log('64-bit hash:', resultHash64);
// Output: A 64-bit hash string
```

### Example Usage in a Component
```javascript
import React, { useEffect } from 'react';
import { Text, View } from 'react-native';
import { hash128, hash64 } from 'react-native-xxhash';

const App = () => {
useEffect(() => {
const hash128Result = hash128("react-native");
const hash64Result = hash64("react-native");

console.log("128-bit hash:", hash128Result);
console.log("64-bit hash:", hash64Result);
}, []);

return (

Check your console for hash results!

);
};

export default App;
```

---

## API Reference

### `hash128(input: string): string`
- **Description**: Generates a 128-bit hash for the given string input.
- **Parameters**:
- `input` (string): The string to hash.
- **Returns**: A 128-bit hash as a string.

### `hash64(input: string): string`
- **Description**: Generates a 64-bit hash for the given string input.
- **Parameters**:
- `input` (string): The string to hash.
- **Returns**: A 64-bit hash as a string.

---

## License

`react-native-xxhash` is released under the MIT License. See the [LICENSE](LICENSE) file for details.