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
- Host: GitHub
- URL: https://github.com/pioner92/react-native-xxhash
- Owner: pioner92
- License: mit
- Created: 2025-01-17T21:17:28.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-09-27T19:14:42.000Z (8 months ago)
- Last Synced: 2025-10-07T05:45:20.229Z (8 months ago)
- Topics: android, hash, ios, javascript, jni, jsi, quickhash, react, react-native, react-native-hash, react-native-jsi, react-native-xxhash, xxhash, xxhash-library, xxhash3
- Language: C++
- Homepage:
- Size: 1.67 MB
- Stars: 18
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
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)

## 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.