react-native-xxhash 0.1.0
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/LICENSE +20 -0
- package/README.md +37 -0
- package/android/CMakeLists.txt +55 -0
- package/android/build.gradle +153 -0
- package/android/cpp-adapter.cpp +38 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/xxhash/XxhashModule.kt +41 -0
- package/android/src/main/java/com/xxhash/XxhashPackage.kt +17 -0
- package/cpp/react-native-xxhash.cpp +43 -0
- package/cpp/react-native-xxhash.h +43 -0
- package/cpp/xxhash.c +42 -0
- package/cpp/xxhash.h +7238 -0
- package/ios/Xxhash.h +9 -0
- package/ios/Xxhash.mm +34 -0
- package/lib/commonjs/index.js +72 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/index.js +67 -0
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +41 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/src/index.d.ts +41 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/package.json +193 -0
- package/react-native-xxhash.podspec +41 -0
- package/src/index.tsx +76 -0
package/ios/Xxhash.h
ADDED
package/ios/Xxhash.mm
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#import "Xxhash.h"
|
|
2
|
+
#import <React/RCTBridge+Private.h>
|
|
3
|
+
#import <ReactCommon/RCTTurboModule.h>
|
|
4
|
+
#import <React/RCTBridge.h>
|
|
5
|
+
#import <React/RCTUtils.h>
|
|
6
|
+
#import <jsi/jsi.h>
|
|
7
|
+
|
|
8
|
+
@implementation Xxhash
|
|
9
|
+
RCT_EXPORT_MODULE()
|
|
10
|
+
|
|
11
|
+
@synthesize bridge = _bridge;
|
|
12
|
+
@synthesize methodQueue = _methodQueue;
|
|
13
|
+
|
|
14
|
+
+ (BOOL)requiresMainQueueSetup {
|
|
15
|
+
return YES;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
- (void)setBridge:(RCTBridge *)bridge {
|
|
20
|
+
_bridge = bridge;
|
|
21
|
+
|
|
22
|
+
RCTCxxBridge *cxxBridge = (RCTCxxBridge *)self.bridge;
|
|
23
|
+
if (!cxxBridge.runtime) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
auto jsiRuntime = (jsi::Runtime*)cxxBridge.runtime;
|
|
28
|
+
|
|
29
|
+
xxhash::install(jsiRuntime);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.hash64 = exports.hash128 = void 0;
|
|
7
|
+
var _reactNative = require("react-native");
|
|
8
|
+
let xxhashModule = globalThis.__xxhash128;
|
|
9
|
+
if (!xxhashModule) {
|
|
10
|
+
if (_reactNative.NativeModules.xxhash) {
|
|
11
|
+
_reactNative.NativeModules.xxhash.install();
|
|
12
|
+
xxhashModule = globalThis.__xxhash128;
|
|
13
|
+
console.log('✅ xxhash initialized successfully');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Hashes the input string using the xxhash128 algorithm.
|
|
19
|
+
* This function provides a fast and deterministic 128-bit hash for a given string input.
|
|
20
|
+
*
|
|
21
|
+
* @param {string} input - The string to hash.
|
|
22
|
+
* @returns {string} The hashed string as a hexadecimal representation of the 128-bit hash.
|
|
23
|
+
* @throws {Error} If the input is not provided.
|
|
24
|
+
* @throws {Error} If the input is not of type string.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const result = hash128("hello world");
|
|
28
|
+
* console.log(result); // Example output: "3a2b9e6a2b5e7e5a9e6a2b5e7e5a2a2"
|
|
29
|
+
*
|
|
30
|
+
* @description
|
|
31
|
+
* This function uses the xxhash128 algorithm, which provides a larger hash size (128-bit) compared to xxhash64.
|
|
32
|
+
* It is ideal for scenarios where a reduced collision risk is critical, such as in distributed systems or when hashing larger datasets.
|
|
33
|
+
*/
|
|
34
|
+
const hash128 = input => {
|
|
35
|
+
if (!input) {
|
|
36
|
+
throw new Error('Input is required');
|
|
37
|
+
}
|
|
38
|
+
if (typeof input !== 'string') {
|
|
39
|
+
throw new Error('Input must be a string');
|
|
40
|
+
}
|
|
41
|
+
return globalThis.__xxhash128(input);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Hashes the input string using the xxhash64 algorithm.
|
|
46
|
+
* This function provides a fast and deterministic 64-bit hash for a given string input.
|
|
47
|
+
*
|
|
48
|
+
* @param {string} input - The string to hash.
|
|
49
|
+
* @returns {string} The hashed string as a hexadecimal representation of the 64-bit hash.
|
|
50
|
+
* @throws {Error} If the input is not provided.
|
|
51
|
+
* @throws {Error} If the input is not of type string.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* const result = hash64("hello world");
|
|
55
|
+
* console.log(result); // Example output: "9e6a2b5e7e5a2a2e"
|
|
56
|
+
*
|
|
57
|
+
* @description
|
|
58
|
+
* This function uses the xxhash64 algorithm, known for its high performance and low collision rate.
|
|
59
|
+
* It is ideal for hashing small to medium-sized strings.
|
|
60
|
+
*/
|
|
61
|
+
exports.hash128 = hash128;
|
|
62
|
+
const hash64 = input => {
|
|
63
|
+
if (!input) {
|
|
64
|
+
throw new Error('Input is required');
|
|
65
|
+
}
|
|
66
|
+
if (typeof input !== 'string') {
|
|
67
|
+
throw new Error('Input must be a string');
|
|
68
|
+
}
|
|
69
|
+
return globalThis.__xxhash64(input);
|
|
70
|
+
};
|
|
71
|
+
exports.hash64 = hash64;
|
|
72
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","xxhashModule","globalThis","__xxhash128","NativeModules","xxhash","install","console","log","hash128","input","Error","exports","hash64","__xxhash64"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAOA,IAAIC,YAAY,GAAGC,UAAU,CAACC,WAAW;AAEzC,IAAG,CAACF,YAAY,EAAC;EACf,IAAGG,0BAAa,CAACC,MAAM,EAAC;IACtBD,0BAAa,CAACC,MAAM,CAACC,OAAO,CAAC,CAAC;IAC9BL,YAAY,GAAGC,UAAU,CAACC,WAAW;IACrCI,OAAO,CAACC,GAAG,CAAC,mCAAmC,CAAC;EAClD;AACF;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACQ,MAAMC,OAAO,GAAIC,KAAa,IAAa;EACjD,IAAG,CAACA,KAAK,EAAC;IACR,MAAM,IAAIC,KAAK,CAAC,mBAAmB,CAAC;EACtC;EAEA,IAAG,OAAOD,KAAK,KAAK,QAAQ,EAAC;IAC3B,MAAM,IAAIC,KAAK,CAAC,wBAAwB,CAAC;EAC3C;EAEA,OAAOT,UAAU,CAACC,WAAW,CAACO,KAAK,CAAC;AACrC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAhBAE,OAAA,CAAAH,OAAA,GAAAA,OAAA;AAkBQ,MAAMI,MAAM,GAAIH,KAAa,IAAa;EAChD,IAAG,CAACA,KAAK,EAAC;IACR,MAAM,IAAIC,KAAK,CAAC,mBAAmB,CAAC;EACtC;EAEA,IAAG,OAAOD,KAAK,KAAK,QAAQ,EAAC;IAC3B,MAAM,IAAIC,KAAK,CAAC,wBAAwB,CAAC;EAC3C;EAEA,OAAOT,UAAU,CAACY,UAAU,CAACJ,KAAK,CAAC;AACpC,CAAC;AAAAE,OAAA,CAAAC,MAAA,GAAAA,MAAA","ignoreList":[]}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { NativeModules } from 'react-native';
|
|
4
|
+
let xxhashModule = globalThis.__xxhash128;
|
|
5
|
+
if (!xxhashModule) {
|
|
6
|
+
if (NativeModules.xxhash) {
|
|
7
|
+
NativeModules.xxhash.install();
|
|
8
|
+
xxhashModule = globalThis.__xxhash128;
|
|
9
|
+
console.log('✅ xxhash initialized successfully');
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Hashes the input string using the xxhash128 algorithm.
|
|
15
|
+
* This function provides a fast and deterministic 128-bit hash for a given string input.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} input - The string to hash.
|
|
18
|
+
* @returns {string} The hashed string as a hexadecimal representation of the 128-bit hash.
|
|
19
|
+
* @throws {Error} If the input is not provided.
|
|
20
|
+
* @throws {Error} If the input is not of type string.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const result = hash128("hello world");
|
|
24
|
+
* console.log(result); // Example output: "3a2b9e6a2b5e7e5a9e6a2b5e7e5a2a2"
|
|
25
|
+
*
|
|
26
|
+
* @description
|
|
27
|
+
* This function uses the xxhash128 algorithm, which provides a larger hash size (128-bit) compared to xxhash64.
|
|
28
|
+
* It is ideal for scenarios where a reduced collision risk is critical, such as in distributed systems or when hashing larger datasets.
|
|
29
|
+
*/
|
|
30
|
+
export const hash128 = input => {
|
|
31
|
+
if (!input) {
|
|
32
|
+
throw new Error('Input is required');
|
|
33
|
+
}
|
|
34
|
+
if (typeof input !== 'string') {
|
|
35
|
+
throw new Error('Input must be a string');
|
|
36
|
+
}
|
|
37
|
+
return globalThis.__xxhash128(input);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Hashes the input string using the xxhash64 algorithm.
|
|
42
|
+
* This function provides a fast and deterministic 64-bit hash for a given string input.
|
|
43
|
+
*
|
|
44
|
+
* @param {string} input - The string to hash.
|
|
45
|
+
* @returns {string} The hashed string as a hexadecimal representation of the 64-bit hash.
|
|
46
|
+
* @throws {Error} If the input is not provided.
|
|
47
|
+
* @throws {Error} If the input is not of type string.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* const result = hash64("hello world");
|
|
51
|
+
* console.log(result); // Example output: "9e6a2b5e7e5a2a2e"
|
|
52
|
+
*
|
|
53
|
+
* @description
|
|
54
|
+
* This function uses the xxhash64 algorithm, known for its high performance and low collision rate.
|
|
55
|
+
* It is ideal for hashing small to medium-sized strings.
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
export const hash64 = input => {
|
|
59
|
+
if (!input) {
|
|
60
|
+
throw new Error('Input is required');
|
|
61
|
+
}
|
|
62
|
+
if (typeof input !== 'string') {
|
|
63
|
+
throw new Error('Input must be a string');
|
|
64
|
+
}
|
|
65
|
+
return globalThis.__xxhash64(input);
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NativeModules","xxhashModule","globalThis","__xxhash128","xxhash","install","console","log","hash128","input","Error","hash64","__xxhash64"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAAQA,aAAa,QAAO,cAAc;AAO1C,IAAIC,YAAY,GAAGC,UAAU,CAACC,WAAW;AAEzC,IAAG,CAACF,YAAY,EAAC;EACf,IAAGD,aAAa,CAACI,MAAM,EAAC;IACtBJ,aAAa,CAACI,MAAM,CAACC,OAAO,CAAC,CAAC;IAC9BJ,YAAY,GAAGC,UAAU,CAACC,WAAW;IACrCG,OAAO,CAACC,GAAG,CAAC,mCAAmC,CAAC;EAClD;AACF;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACC,OAAO,MAAMC,OAAO,GAAIC,KAAa,IAAa;EACjD,IAAG,CAACA,KAAK,EAAC;IACR,MAAM,IAAIC,KAAK,CAAC,mBAAmB,CAAC;EACtC;EAEA,IAAG,OAAOD,KAAK,KAAK,QAAQ,EAAC;IAC3B,MAAM,IAAIC,KAAK,CAAC,wBAAwB,CAAC;EAC3C;EAEA,OAAOR,UAAU,CAACC,WAAW,CAACM,KAAK,CAAC;AACrC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEC,OAAO,MAAME,MAAM,GAAIF,KAAa,IAAa;EAChD,IAAG,CAACA,KAAK,EAAC;IACR,MAAM,IAAIC,KAAK,CAAC,mBAAmB,CAAC;EACtC;EAEA,IAAG,OAAOD,KAAK,KAAK,QAAQ,EAAC;IAC3B,MAAM,IAAIC,KAAK,CAAC,wBAAwB,CAAC;EAC3C;EAEA,OAAOR,UAAU,CAACU,UAAU,CAACH,KAAK,CAAC;AACpC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
var __xxhash128: (input: string) => string;
|
|
3
|
+
var __xxhash64: (input: string) => string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Hashes the input string using the xxhash128 algorithm.
|
|
7
|
+
* This function provides a fast and deterministic 128-bit hash for a given string input.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} input - The string to hash.
|
|
10
|
+
* @returns {string} The hashed string as a hexadecimal representation of the 128-bit hash.
|
|
11
|
+
* @throws {Error} If the input is not provided.
|
|
12
|
+
* @throws {Error} If the input is not of type string.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const result = hash128("hello world");
|
|
16
|
+
* console.log(result); // Example output: "3a2b9e6a2b5e7e5a9e6a2b5e7e5a2a2"
|
|
17
|
+
*
|
|
18
|
+
* @description
|
|
19
|
+
* This function uses the xxhash128 algorithm, which provides a larger hash size (128-bit) compared to xxhash64.
|
|
20
|
+
* It is ideal for scenarios where a reduced collision risk is critical, such as in distributed systems or when hashing larger datasets.
|
|
21
|
+
*/
|
|
22
|
+
export declare const hash128: (input: string) => string;
|
|
23
|
+
/**
|
|
24
|
+
* Hashes the input string using the xxhash64 algorithm.
|
|
25
|
+
* This function provides a fast and deterministic 64-bit hash for a given string input.
|
|
26
|
+
*
|
|
27
|
+
* @param {string} input - The string to hash.
|
|
28
|
+
* @returns {string} The hashed string as a hexadecimal representation of the 64-bit hash.
|
|
29
|
+
* @throws {Error} If the input is not provided.
|
|
30
|
+
* @throws {Error} If the input is not of type string.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const result = hash64("hello world");
|
|
34
|
+
* console.log(result); // Example output: "9e6a2b5e7e5a2a2e"
|
|
35
|
+
*
|
|
36
|
+
* @description
|
|
37
|
+
* This function uses the xxhash64 algorithm, known for its high performance and low collision rate.
|
|
38
|
+
* It is ideal for hashing small to medium-sized strings.
|
|
39
|
+
*/
|
|
40
|
+
export declare const hash64: (input: string) => string;
|
|
41
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAC3C,IAAI,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3C;AAcD;;;;;;;;;;;;;;;;GAgBG;AACF,eAAO,MAAM,OAAO,UAAW,MAAM,KAAG,MAUvC,CAAA;AAEF;;;;;;;;;;;;;;;;GAgBG;AAEF,eAAO,MAAM,MAAM,UAAW,MAAM,KAAG,MAUtC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
var __xxhash128: (input: string) => string;
|
|
3
|
+
var __xxhash64: (input: string) => string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Hashes the input string using the xxhash128 algorithm.
|
|
7
|
+
* This function provides a fast and deterministic 128-bit hash for a given string input.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} input - The string to hash.
|
|
10
|
+
* @returns {string} The hashed string as a hexadecimal representation of the 128-bit hash.
|
|
11
|
+
* @throws {Error} If the input is not provided.
|
|
12
|
+
* @throws {Error} If the input is not of type string.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const result = hash128("hello world");
|
|
16
|
+
* console.log(result); // Example output: "3a2b9e6a2b5e7e5a9e6a2b5e7e5a2a2"
|
|
17
|
+
*
|
|
18
|
+
* @description
|
|
19
|
+
* This function uses the xxhash128 algorithm, which provides a larger hash size (128-bit) compared to xxhash64.
|
|
20
|
+
* It is ideal for scenarios where a reduced collision risk is critical, such as in distributed systems or when hashing larger datasets.
|
|
21
|
+
*/
|
|
22
|
+
export declare const hash128: (input: string) => string;
|
|
23
|
+
/**
|
|
24
|
+
* Hashes the input string using the xxhash64 algorithm.
|
|
25
|
+
* This function provides a fast and deterministic 64-bit hash for a given string input.
|
|
26
|
+
*
|
|
27
|
+
* @param {string} input - The string to hash.
|
|
28
|
+
* @returns {string} The hashed string as a hexadecimal representation of the 64-bit hash.
|
|
29
|
+
* @throws {Error} If the input is not provided.
|
|
30
|
+
* @throws {Error} If the input is not of type string.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const result = hash64("hello world");
|
|
34
|
+
* console.log(result); // Example output: "9e6a2b5e7e5a2a2e"
|
|
35
|
+
*
|
|
36
|
+
* @description
|
|
37
|
+
* This function uses the xxhash64 algorithm, known for its high performance and low collision rate.
|
|
38
|
+
* It is ideal for hashing small to medium-sized strings.
|
|
39
|
+
*/
|
|
40
|
+
export declare const hash64: (input: string) => string;
|
|
41
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAC3C,IAAI,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3C;AAcD;;;;;;;;;;;;;;;;GAgBG;AACF,eAAO,MAAM,OAAO,UAAW,MAAM,KAAG,MAUvC,CAAA;AAEF;;;;;;;;;;;;;;;;GAgBG;AAEF,eAAO,MAAM,MAAM,UAAW,MAAM,KAAG,MAUtC,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-native-xxhash",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "react-native-xxhash",
|
|
5
|
+
"source": "./src/index.tsx",
|
|
6
|
+
"main": "./lib/commonjs/index.js",
|
|
7
|
+
"module": "./lib/module/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./lib/typescript/module/src/index.d.ts",
|
|
12
|
+
"default": "./lib/module/index.js"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./lib/typescript/commonjs/src/index.d.ts",
|
|
16
|
+
"default": "./lib/commonjs/index.js"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"src",
|
|
22
|
+
"lib",
|
|
23
|
+
"android",
|
|
24
|
+
"ios",
|
|
25
|
+
"cpp",
|
|
26
|
+
"*.podspec",
|
|
27
|
+
"react-native.config.js",
|
|
28
|
+
"!ios/build",
|
|
29
|
+
"!android/build",
|
|
30
|
+
"!android/gradle",
|
|
31
|
+
"!android/gradlew",
|
|
32
|
+
"!android/gradlew.bat",
|
|
33
|
+
"!android/local.properties",
|
|
34
|
+
"!**/__tests__",
|
|
35
|
+
"!**/__fixtures__",
|
|
36
|
+
"!**/__mocks__",
|
|
37
|
+
"!**/.*"
|
|
38
|
+
],
|
|
39
|
+
"scripts": {
|
|
40
|
+
"example": "yarn workspace react-native-xxhash-example",
|
|
41
|
+
"test": "jest",
|
|
42
|
+
"typecheck": "tsc",
|
|
43
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
44
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
45
|
+
"prepare": "bob build",
|
|
46
|
+
"release": "release-it"
|
|
47
|
+
},
|
|
48
|
+
"keywords": [
|
|
49
|
+
"react-native",
|
|
50
|
+
"ios",
|
|
51
|
+
"android",
|
|
52
|
+
"xxhash",
|
|
53
|
+
"hash"
|
|
54
|
+
],
|
|
55
|
+
"repository": {
|
|
56
|
+
"type": "git",
|
|
57
|
+
"url": "git+https://github.com/pioner92/react-native-xxhash"
|
|
58
|
+
},
|
|
59
|
+
"author": "pioner921227 <alex.shumihin921227@gmail.com> (https://github.com/pioner92/react-native-xxhash)",
|
|
60
|
+
"license": "MIT",
|
|
61
|
+
"bugs": {
|
|
62
|
+
"url": "https://github.com/pioner92/react-native-xxhash/issues"
|
|
63
|
+
},
|
|
64
|
+
"homepage": "https://github.com/pioner92/react-native-xxhash#readme",
|
|
65
|
+
"publishConfig": {
|
|
66
|
+
"registry": "https://registry.npmjs.org/"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@commitlint/config-conventional": "^17.0.2",
|
|
70
|
+
"@evilmartians/lefthook": "^1.5.0",
|
|
71
|
+
"@react-native-community/cli": "15.0.1",
|
|
72
|
+
"@react-native/eslint-config": "^0.73.1",
|
|
73
|
+
"@release-it/conventional-changelog": "^9.0.2",
|
|
74
|
+
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
75
|
+
"@semantic-release/release-notes-generator": "^14.0.3",
|
|
76
|
+
"@types/jest": "^29.5.5",
|
|
77
|
+
"@types/react": "^18.2.44",
|
|
78
|
+
"commitlint": "^17.0.2",
|
|
79
|
+
"del-cli": "^5.1.0",
|
|
80
|
+
"eslint": "^8.51.0",
|
|
81
|
+
"eslint-config-prettier": "^9.0.0",
|
|
82
|
+
"eslint-plugin-prettier": "^5.0.1",
|
|
83
|
+
"jest": "^29.7.0",
|
|
84
|
+
"prettier": "^3.0.3",
|
|
85
|
+
"react": "18.3.1",
|
|
86
|
+
"react-native": "0.76.6",
|
|
87
|
+
"react-native-builder-bob": "^0.35.2",
|
|
88
|
+
"release-it": "^17.10.0",
|
|
89
|
+
"turbo": "^1.10.7",
|
|
90
|
+
"typescript": "^5.2.2"
|
|
91
|
+
},
|
|
92
|
+
"resolutions": {
|
|
93
|
+
"@types/react": "^18.2.44"
|
|
94
|
+
},
|
|
95
|
+
"peerDependencies": {
|
|
96
|
+
"react": "*",
|
|
97
|
+
"react-native": "*"
|
|
98
|
+
},
|
|
99
|
+
"workspaces": [
|
|
100
|
+
"example"
|
|
101
|
+
],
|
|
102
|
+
"packageManager": "yarn@3.6.1",
|
|
103
|
+
"jest": {
|
|
104
|
+
"preset": "react-native",
|
|
105
|
+
"modulePathIgnorePatterns": [
|
|
106
|
+
"<rootDir>/example/node_modules",
|
|
107
|
+
"<rootDir>/lib/"
|
|
108
|
+
]
|
|
109
|
+
},
|
|
110
|
+
"commitlint": {
|
|
111
|
+
"extends": [
|
|
112
|
+
"@commitlint/config-conventional"
|
|
113
|
+
]
|
|
114
|
+
},
|
|
115
|
+
"release-it": {
|
|
116
|
+
"git": {
|
|
117
|
+
"commitMessage": "chore: release ${version}",
|
|
118
|
+
"tagName": "v${version}"
|
|
119
|
+
},
|
|
120
|
+
"npm": {
|
|
121
|
+
"publish": true
|
|
122
|
+
},
|
|
123
|
+
"github": {
|
|
124
|
+
"release": true
|
|
125
|
+
},
|
|
126
|
+
"plugins": {
|
|
127
|
+
"@release-it/conventional-changelog": {
|
|
128
|
+
"preset": "angular"
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
"eslintConfig": {
|
|
133
|
+
"root": true,
|
|
134
|
+
"extends": [
|
|
135
|
+
"@react-native",
|
|
136
|
+
"prettier"
|
|
137
|
+
],
|
|
138
|
+
"rules": {
|
|
139
|
+
"react/react-in-jsx-scope": "off",
|
|
140
|
+
"prettier/prettier": [
|
|
141
|
+
"error",
|
|
142
|
+
{
|
|
143
|
+
"quoteProps": "consistent",
|
|
144
|
+
"singleQuote": true,
|
|
145
|
+
"tabWidth": 2,
|
|
146
|
+
"trailingComma": "es5",
|
|
147
|
+
"useTabs": false
|
|
148
|
+
}
|
|
149
|
+
]
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
"eslintIgnore": [
|
|
153
|
+
"node_modules/",
|
|
154
|
+
"lib/"
|
|
155
|
+
],
|
|
156
|
+
"prettier": {
|
|
157
|
+
"quoteProps": "consistent",
|
|
158
|
+
"singleQuote": true,
|
|
159
|
+
"tabWidth": 2,
|
|
160
|
+
"trailingComma": "es5",
|
|
161
|
+
"useTabs": false
|
|
162
|
+
},
|
|
163
|
+
"react-native-builder-bob": {
|
|
164
|
+
"source": "src",
|
|
165
|
+
"output": "lib",
|
|
166
|
+
"targets": [
|
|
167
|
+
[
|
|
168
|
+
"commonjs",
|
|
169
|
+
{
|
|
170
|
+
"esm": true
|
|
171
|
+
}
|
|
172
|
+
],
|
|
173
|
+
[
|
|
174
|
+
"module",
|
|
175
|
+
{
|
|
176
|
+
"esm": true
|
|
177
|
+
}
|
|
178
|
+
],
|
|
179
|
+
[
|
|
180
|
+
"typescript",
|
|
181
|
+
{
|
|
182
|
+
"project": "tsconfig.build.json",
|
|
183
|
+
"esm": true
|
|
184
|
+
}
|
|
185
|
+
]
|
|
186
|
+
]
|
|
187
|
+
},
|
|
188
|
+
"create-react-native-library": {
|
|
189
|
+
"type": "legacy-module",
|
|
190
|
+
"languages": "cpp",
|
|
191
|
+
"version": "0.45.5"
|
|
192
|
+
}
|
|
193
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
|
|
5
|
+
|
|
6
|
+
Pod::Spec.new do |s|
|
|
7
|
+
s.name = "react-native-xxhash"
|
|
8
|
+
s.version = package["version"]
|
|
9
|
+
s.summary = package["description"]
|
|
10
|
+
s.homepage = package["homepage"]
|
|
11
|
+
s.license = package["license"]
|
|
12
|
+
s.authors = package["author"]
|
|
13
|
+
|
|
14
|
+
s.platforms = { :ios => min_ios_version_supported }
|
|
15
|
+
s.source = { :git => "https://google.com.git", :tag => "#{s.version}" }
|
|
16
|
+
|
|
17
|
+
s.source_files = "ios/**/*.{h,m,mm}", "cpp/**/*.{hpp,cpp,c,h}"
|
|
18
|
+
|
|
19
|
+
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
|
|
20
|
+
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
|
|
21
|
+
if respond_to?(:install_modules_dependencies, true)
|
|
22
|
+
install_modules_dependencies(s)
|
|
23
|
+
else
|
|
24
|
+
s.dependency "React-Core"
|
|
25
|
+
|
|
26
|
+
# Don't install the dependencies when we run `pod install` in the old architecture.
|
|
27
|
+
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
|
|
28
|
+
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
|
|
29
|
+
s.pod_target_xcconfig = {
|
|
30
|
+
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
|
|
31
|
+
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
|
|
32
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
|
|
33
|
+
}
|
|
34
|
+
s.dependency "React-Codegen"
|
|
35
|
+
s.dependency "RCT-Folly"
|
|
36
|
+
s.dependency "RCTRequired"
|
|
37
|
+
s.dependency "RCTTypeSafety"
|
|
38
|
+
s.dependency "ReactCommon/turbomodule/core"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import {NativeModules} from 'react-native'
|
|
2
|
+
declare global {
|
|
3
|
+
var __xxhash128: (input: string) => string;
|
|
4
|
+
var __xxhash64: (input: string) => string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
let xxhashModule = globalThis.__xxhash128;
|
|
9
|
+
|
|
10
|
+
if(!xxhashModule){
|
|
11
|
+
if(NativeModules.xxhash){
|
|
12
|
+
NativeModules.xxhash.install();
|
|
13
|
+
xxhashModule = globalThis.__xxhash128;
|
|
14
|
+
console.log('✅ xxhash initialized successfully')
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Hashes the input string using the xxhash128 algorithm.
|
|
21
|
+
* This function provides a fast and deterministic 128-bit hash for a given string input.
|
|
22
|
+
*
|
|
23
|
+
* @param {string} input - The string to hash.
|
|
24
|
+
* @returns {string} The hashed string as a hexadecimal representation of the 128-bit hash.
|
|
25
|
+
* @throws {Error} If the input is not provided.
|
|
26
|
+
* @throws {Error} If the input is not of type string.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* const result = hash128("hello world");
|
|
30
|
+
* console.log(result); // Example output: "3a2b9e6a2b5e7e5a9e6a2b5e7e5a2a2"
|
|
31
|
+
*
|
|
32
|
+
* @description
|
|
33
|
+
* This function uses the xxhash128 algorithm, which provides a larger hash size (128-bit) compared to xxhash64.
|
|
34
|
+
* It is ideal for scenarios where a reduced collision risk is critical, such as in distributed systems or when hashing larger datasets.
|
|
35
|
+
*/
|
|
36
|
+
export const hash128 = (input: string): string => {
|
|
37
|
+
if(!input){
|
|
38
|
+
throw new Error('Input is required');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if(typeof input !== 'string'){
|
|
42
|
+
throw new Error('Input must be a string');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return globalThis.__xxhash128(input);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Hashes the input string using the xxhash64 algorithm.
|
|
50
|
+
* This function provides a fast and deterministic 64-bit hash for a given string input.
|
|
51
|
+
*
|
|
52
|
+
* @param {string} input - The string to hash.
|
|
53
|
+
* @returns {string} The hashed string as a hexadecimal representation of the 64-bit hash.
|
|
54
|
+
* @throws {Error} If the input is not provided.
|
|
55
|
+
* @throws {Error} If the input is not of type string.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* const result = hash64("hello world");
|
|
59
|
+
* console.log(result); // Example output: "9e6a2b5e7e5a2a2e"
|
|
60
|
+
*
|
|
61
|
+
* @description
|
|
62
|
+
* This function uses the xxhash64 algorithm, known for its high performance and low collision rate.
|
|
63
|
+
* It is ideal for hashing small to medium-sized strings.
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
export const hash64 = (input: string): string => {
|
|
67
|
+
if(!input){
|
|
68
|
+
throw new Error('Input is required');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if(typeof input !== 'string'){
|
|
72
|
+
throw new Error('Input must be a string');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return globalThis.__xxhash64(input);
|
|
76
|
+
}
|