|
1 | | -# 🚀 react-native-config-jsi |
| 1 | +# react-native-xxhash |
2 | 2 |
|
3 | | -**Fast JSI-based React Native library to access `.env` variables natively with C++ performance.** |
| 3 | +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. |
4 | 4 |
|
5 | | ---- |
6 | 5 |
|
7 | | -## 📦 Install |
| 6 | +## Features |
8 | 7 |
|
9 | | -```sh |
10 | | -npm install react-native-config-jsi # or yarn add react-native-config-jsi |
11 | | -``` |
| 8 | +- **High Performance**: xxHash is one of the fastest non-cryptographic hash functions. |
| 9 | +- **Deterministic Hashing**: Ensures consistent results for the same input. |
| 10 | +- **128-bit and 64-bit Support**: Choose between 128-bit and 64-bit hash outputs based on your use case. |
| 11 | +- **Cross-Platform**: Supports both iOS and Android in React Native projects. |
12 | 12 |
|
13 | | ---- |
| 13 | +## Installation |
14 | 14 |
|
15 | | -## 🔧 Quick Setup |
| 15 | +To install the library, use either `npm` or `yarn`: |
16 | 16 |
|
17 | | -1. Create `.env` at project root: |
18 | | -```env |
19 | | -API_KEY=your_api_key |
20 | | -APP_NAME=MyAwesomeApp |
| 17 | +```sh |
| 18 | +npm install react-native-xxhash |
21 | 19 | ``` |
22 | 20 |
|
23 | | -2. **iOS:** |
24 | | -```bash |
25 | | -cd ios && pod install |
26 | | -``` |
27 | | -Add to Xcode → Target → Build Phases → **+ New Run Script Phase**: |
28 | | -```bash |
29 | | -bash "${SRCROOT}/../node_modules/react-native-config-jsi/src/scripts/generate.sh" |
| 21 | +```sh |
| 22 | +yarn add react-native-xxhash |
30 | 23 | ``` |
31 | 24 |
|
32 | | -3. **Android:** |
33 | | -Add to bottom of `android/app/build.gradle`: |
34 | | -```gradle |
35 | | -apply from: project(':react-native-config-jsi').projectDir.getPath() + "/dotenv.gradle" |
| 25 | +## iOS |
| 26 | +```sh |
| 27 | +pod install |
36 | 28 | ``` |
37 | 29 |
|
38 | 30 | --- |
39 | 31 |
|
40 | | -## 🚀 Usage |
| 32 | +## Usage |
41 | 33 |
|
42 | | -```js |
43 | | -import { RNConfig } from "react-native-config-jsi"; |
| 34 | +Here’s how to use the `react-native-xxhash` library in your React Native project: |
44 | 35 |
|
45 | | -const apiKey = RNConfig.get("API_KEY"); |
46 | | -console.log("API_KEY:", apiKey); |
| 36 | +### Import the Functions |
| 37 | +```javascript |
| 38 | +import { hash128, hash64 } from 'react-native-xxhash'; |
47 | 39 | ``` |
48 | 40 |
|
49 | | ---- |
| 41 | +### Hash a String (128-bit) |
| 42 | +This function generates a fast and deterministic 128-bit hash for a given string input. |
| 43 | + |
| 44 | +```javascript |
| 45 | +const resultHash128 = hash128("hello world"); |
| 46 | +console.log('128-bit hash:', resultHash128); |
| 47 | +// Output: A 128-bit hash string |
| 48 | +``` |
| 49 | + |
| 50 | +### Hash a String (64-bit) |
| 51 | +This function generates a fast and deterministic 64-bit hash for a given string input. |
50 | 52 |
|
51 | | -## ⚡ Highlights |
| 53 | +```javascript |
| 54 | +const resultHash64 = hash64("hello world"); |
| 55 | +console.log('64-bit hash:', resultHash64); |
| 56 | +// Output: A 64-bit hash string |
| 57 | +``` |
52 | 58 |
|
53 | | -- 🔥 Ultra-fast JSI native access |
54 | | -- ⚙️ Built in C++ |
55 | | -- 🧩 Synchronous API |
56 | | -- 🪶 No extra dependencies |
| 59 | +### Example Usage in a Component |
| 60 | +```javascript |
| 61 | +import React, { useEffect } from 'react'; |
| 62 | +import { Text, View } from 'react-native'; |
| 63 | +import { hash128, hash64 } from 'react-native-xxhash'; |
| 64 | + |
| 65 | +const App = () => { |
| 66 | + useEffect(() => { |
| 67 | + const hash128Result = hash128("react-native"); |
| 68 | + const hash64Result = hash64("react-native"); |
| 69 | + |
| 70 | + console.log("128-bit hash:", hash128Result); |
| 71 | + console.log("64-bit hash:", hash64Result); |
| 72 | + }, []); |
| 73 | + |
| 74 | + return ( |
| 75 | + <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}> |
| 76 | + <Text>Check your console for hash results!</Text> |
| 77 | + </View> |
| 78 | + ); |
| 79 | +}; |
| 80 | + |
| 81 | +export default App; |
| 82 | +``` |
57 | 83 |
|
58 | 84 | --- |
59 | 85 |
|
60 | | -## 📜 License |
| 86 | +## API Reference |
61 | 87 |
|
62 | | -MIT |
| 88 | +### `hash128(input: string): string` |
| 89 | +- **Description**: Generates a 128-bit hash for the given string input. |
| 90 | +- **Parameters**: |
| 91 | + - `input` (string): The string to hash. |
| 92 | +- **Returns**: A 128-bit hash as a string. |
| 93 | + |
| 94 | +### `hash64(input: string): string` |
| 95 | +- **Description**: Generates a 64-bit hash for the given string input. |
| 96 | +- **Parameters**: |
| 97 | + - `input` (string): The string to hash. |
| 98 | +- **Returns**: A 64-bit hash as a string. |
63 | 99 |
|
64 | 100 | --- |
65 | 101 |
|
66 | | -🎉 **Enjoy using react-native-config-jsi!** 🚀 |
| 102 | +## License |
| 103 | + |
| 104 | +`react-native-xxhash` is released under the MIT License. See the [LICENSE](LICENSE) file for details. |
0 commit comments