react-native-xxhash 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +74 -12
- package/ios/Xxhash.mm +14 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
# react-native-xxhash
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A React Native library for hashing strings using the fast and deterministic xxHash algorithm. This library provides support for both 64-bit and 128-bit hashing.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **High Performance**: xxHash is one of the fastest non-cryptographic hash functions.
|
|
8
|
+
- **Deterministic Hashing**: Ensures consistent results for the same input.
|
|
9
|
+
- **128-bit and 64-bit Support**: Choose between 128-bit and 64-bit hash outputs based on your use case.
|
|
10
|
+
- **Cross-Platform**: Supports both iOS and Android in React Native projects.
|
|
4
11
|
|
|
5
12
|
## Installation
|
|
6
13
|
|
|
14
|
+
To install the library, use either `npm` or `yarn`:
|
|
15
|
+
|
|
7
16
|
```sh
|
|
8
17
|
npm install react-native-xxhash
|
|
9
18
|
```
|
|
@@ -12,30 +21,83 @@ npm install react-native-xxhash
|
|
|
12
21
|
yarn add react-native-xxhash
|
|
13
22
|
```
|
|
14
23
|
|
|
24
|
+
## iOS
|
|
25
|
+
```sh
|
|
26
|
+
pod install
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
15
31
|
## Usage
|
|
16
32
|
|
|
33
|
+
Here’s how to use the `react-native-xxhash` library in your React Native project:
|
|
17
34
|
|
|
18
|
-
|
|
35
|
+
### Import the Functions
|
|
36
|
+
```javascript
|
|
19
37
|
import { hash128, hash64 } from 'react-native-xxhash';
|
|
38
|
+
```
|
|
20
39
|
|
|
21
|
-
|
|
40
|
+
### Hash a String (128-bit)
|
|
41
|
+
This function generates a fast and deterministic 128-bit hash for a given string input.
|
|
42
|
+
|
|
43
|
+
```javascript
|
|
44
|
+
const resultHash128 = hash128("hello world");
|
|
45
|
+
console.log('128-bit hash:', resultHash128);
|
|
46
|
+
// Output: A 128-bit hash string
|
|
47
|
+
```
|
|
22
48
|
|
|
23
|
-
|
|
24
|
-
|
|
49
|
+
### Hash a String (64-bit)
|
|
50
|
+
This function generates a fast and deterministic 64-bit hash for a given string input.
|
|
25
51
|
|
|
26
|
-
|
|
27
|
-
const
|
|
52
|
+
```javascript
|
|
53
|
+
const resultHash64 = hash64("hello world");
|
|
54
|
+
console.log('64-bit hash:', resultHash64);
|
|
55
|
+
// Output: A 64-bit hash string
|
|
28
56
|
```
|
|
29
57
|
|
|
58
|
+
### Example Usage in a Component
|
|
59
|
+
```javascript
|
|
60
|
+
import React, { useEffect } from 'react';
|
|
61
|
+
import { Text, View } from 'react-native';
|
|
62
|
+
import { hash128, hash64 } from 'react-native-xxhash';
|
|
30
63
|
|
|
31
|
-
|
|
64
|
+
const App = () => {
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
const hash128Result = hash128("react-native");
|
|
67
|
+
const hash64Result = hash64("react-native");
|
|
32
68
|
|
|
33
|
-
|
|
69
|
+
console.log("128-bit hash:", hash128Result);
|
|
70
|
+
console.log("64-bit hash:", hash64Result);
|
|
71
|
+
}, []);
|
|
34
72
|
|
|
35
|
-
|
|
73
|
+
return (
|
|
74
|
+
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
|
|
75
|
+
<Text>Check your console for hash results!</Text>
|
|
76
|
+
</View>
|
|
77
|
+
);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export default App;
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## API Reference
|
|
86
|
+
|
|
87
|
+
### `hash128(input: string): string`
|
|
88
|
+
- **Description**: Generates a 128-bit hash for the given string input.
|
|
89
|
+
- **Parameters**:
|
|
90
|
+
- `input` (string): The string to hash.
|
|
91
|
+
- **Returns**: A 128-bit hash as a string.
|
|
36
92
|
|
|
37
|
-
|
|
93
|
+
### `hash64(input: string): string`
|
|
94
|
+
- **Description**: Generates a 64-bit hash for the given string input.
|
|
95
|
+
- **Parameters**:
|
|
96
|
+
- `input` (string): The string to hash.
|
|
97
|
+
- **Returns**: A 64-bit hash as a string.
|
|
38
98
|
|
|
39
99
|
---
|
|
40
100
|
|
|
41
|
-
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
`react-native-xxhash` is released under the MIT License. See the [LICENSE](LICENSE) file for details.
|
package/ios/Xxhash.mm
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
#import <jsi/jsi.h>
|
|
7
7
|
|
|
8
8
|
@implementation Xxhash
|
|
9
|
-
RCT_EXPORT_MODULE()
|
|
9
|
+
RCT_EXPORT_MODULE(xxhash)
|
|
10
10
|
|
|
11
11
|
@synthesize bridge = _bridge;
|
|
12
12
|
@synthesize methodQueue = _methodQueue;
|
|
@@ -15,20 +15,24 @@ RCT_EXPORT_MODULE()
|
|
|
15
15
|
return YES;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install){
|
|
19
|
+
NSLog(@"Installing JSI bindings for xxhash ...");
|
|
20
|
+
RCTBridge* bridge = [RCTBridge currentBridge];
|
|
21
|
+
RCTCxxBridge* cxxBridge = (RCTCxxBridge*)bridge;
|
|
18
22
|
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
if (cxxBridge == nil) {
|
|
24
|
+
return @false;
|
|
25
|
+
}
|
|
21
26
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
auto jsiRuntime = (jsi::Runtime*) cxxBridge.runtime;
|
|
28
|
+
if (jsiRuntime == nil) {
|
|
29
|
+
return @false;
|
|
30
|
+
}
|
|
26
31
|
|
|
27
|
-
|
|
32
|
+
xxhash::install(jsiRuntime);
|
|
28
33
|
|
|
29
|
-
|
|
34
|
+
return @true;
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
|
|
33
|
-
|
|
34
38
|
@end
|