@javascriptcommon/react-native-xxhash 0.1.9
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 +104 -0
- package/android/CMakeLists.txt +48 -0
- package/android/build.gradle +154 -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 +55 -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 +27 -0
- package/cpp/xxhash.c +42 -0
- package/cpp/xxhash.h +7238 -0
- package/ios/Xxhash.h +9 -0
- package/ios/Xxhash.mm +62 -0
- package/lib/commonjs/index.js +78 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/module/index.js +71 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/index.d.ts +41 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/package.json +192 -0
- package/react-native-xxhash.podspec +41 -0
- package/src/index.tsx +82 -0
package/ios/Xxhash.h
ADDED
package/ios/Xxhash.mm
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#import "Xxhash.h"
|
|
2
|
+
#import <React/RCTBridge+Private.h>
|
|
3
|
+
#import <ReactCommon/RCTTurboModule.h>
|
|
4
|
+
#import <ReactCommon/RCTTurboModuleWithJSIBindings.h>
|
|
5
|
+
#import <React/RCTBridge.h>
|
|
6
|
+
#import <React/RCTUtils.h>
|
|
7
|
+
#import <jsi/jsi.h>
|
|
8
|
+
|
|
9
|
+
@interface Xxhash () <RCTTurboModule, RCTTurboModuleWithJSIBindings>
|
|
10
|
+
@end
|
|
11
|
+
|
|
12
|
+
@implementation Xxhash
|
|
13
|
+
RCT_EXPORT_MODULE(xxhash)
|
|
14
|
+
|
|
15
|
+
@synthesize bridge = _bridge;
|
|
16
|
+
@synthesize methodQueue = _methodQueue;
|
|
17
|
+
|
|
18
|
+
+ (BOOL)requiresMainQueueSetup {
|
|
19
|
+
return YES;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// New Architecture / bridgeless: route through the TurboModule path so RN calls
|
|
23
|
+
// installJSIBindingsWithRuntime: below. Without getTurboModule: this stays a
|
|
24
|
+
// legacy bridge module and the JSI-install hook is never invoked (it only fires
|
|
25
|
+
// inside the `respondsToSelector:@selector(getTurboModule:)` branch of
|
|
26
|
+
// RCTTurboModuleManager). A generic ObjCTurboModule is enough — the only thing
|
|
27
|
+
// we need is the install hook to receive the live runtime.
|
|
28
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
29
|
+
(const facebook::react::ObjCTurboModule::InitParams &)params {
|
|
30
|
+
return std::make_shared<facebook::react::ObjCTurboModule>(params);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Installs __xxhash128 / __xxhash64 with the live jsi::Runtime, WITHOUT depending
|
|
34
|
+
// on [RCTBridge currentBridge] — which is nil under bridgeless (RN 0.85), leaving
|
|
35
|
+
// the globals uninstalled and making hash128()/hash64() throw "undefined is not
|
|
36
|
+
// a function".
|
|
37
|
+
- (void)installJSIBindingsWithRuntime:(facebook::jsi::Runtime &)runtime
|
|
38
|
+
callInvoker:(const std::shared_ptr<facebook::react::CallInvoker> &)callinvoker {
|
|
39
|
+
xxhash::install(&runtime);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install){
|
|
43
|
+
NSLog(@"Installing JSI bindings for xxhash ...");
|
|
44
|
+
RCTBridge* bridge = [RCTBridge currentBridge];
|
|
45
|
+
RCTCxxBridge* cxxBridge = (RCTCxxBridge*)bridge;
|
|
46
|
+
|
|
47
|
+
if (cxxBridge == nil) {
|
|
48
|
+
return @false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
auto jsiRuntime = (jsi::Runtime*) cxxBridge.runtime;
|
|
52
|
+
if (jsiRuntime == nil) {
|
|
53
|
+
return @false;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
xxhash::install(jsiRuntime);
|
|
57
|
+
|
|
58
|
+
return @true;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@end
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
// Referencing NativeModules.xxhash instantiates the module. Under the New
|
|
11
|
+
// Architecture (RN 0.85 bridgeless) that triggers the native
|
|
12
|
+
// installJSIBindingsWithRuntime hook, which installs __xxhash128/__xxhash64 —
|
|
13
|
+
// so the legacy install() is gone (and calling it would throw "undefined is
|
|
14
|
+
// not a function"). Only call install() when it actually exists (old arch).
|
|
15
|
+
if (_reactNative.NativeModules.xxhash) {
|
|
16
|
+
if (typeof _reactNative.NativeModules.xxhash.install === 'function') {
|
|
17
|
+
_reactNative.NativeModules.xxhash.install();
|
|
18
|
+
}
|
|
19
|
+
xxhashModule = globalThis.__xxhash128;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Hashes the input string using the xxhash128 algorithm.
|
|
25
|
+
* This function provides a fast and deterministic 128-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 128-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 = hash128("hello world");
|
|
34
|
+
* console.log(result); // Example output: "3a2b9e6a2b5e7e5a9e6a2b5e7e5a2a2"
|
|
35
|
+
*
|
|
36
|
+
* @description
|
|
37
|
+
* This function uses the xxhash128 algorithm, which provides a larger hash size (128-bit) compared to xxhash64.
|
|
38
|
+
* It is ideal for scenarios where a reduced collision risk is critical, such as in distributed systems or when hashing larger datasets.
|
|
39
|
+
*/
|
|
40
|
+
const hash128 = input => {
|
|
41
|
+
if (!input) {
|
|
42
|
+
throw new Error('Input is required');
|
|
43
|
+
}
|
|
44
|
+
if (typeof input !== 'string') {
|
|
45
|
+
throw new Error('Input must be a string');
|
|
46
|
+
}
|
|
47
|
+
return globalThis.__xxhash128(input);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Hashes the input string using the xxhash64 algorithm.
|
|
52
|
+
* This function provides a fast and deterministic 64-bit hash for a given string input.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} input - The string to hash.
|
|
55
|
+
* @returns {string} The hashed string as a hexadecimal representation of the 64-bit hash.
|
|
56
|
+
* @throws {Error} If the input is not provided.
|
|
57
|
+
* @throws {Error} If the input is not of type string.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* const result = hash64("hello world");
|
|
61
|
+
* console.log(result); // Example output: "9e6a2b5e7e5a2a2e"
|
|
62
|
+
*
|
|
63
|
+
* @description
|
|
64
|
+
* This function uses the xxhash64 algorithm, known for its high performance and low collision rate.
|
|
65
|
+
* It is ideal for hashing small to medium-sized strings.
|
|
66
|
+
*/
|
|
67
|
+
exports.hash128 = hash128;
|
|
68
|
+
const hash64 = input => {
|
|
69
|
+
if (!input) {
|
|
70
|
+
throw new Error('Input is required');
|
|
71
|
+
}
|
|
72
|
+
if (typeof input !== 'string') {
|
|
73
|
+
throw new Error('Input must be a string');
|
|
74
|
+
}
|
|
75
|
+
return globalThis.__xxhash64(input);
|
|
76
|
+
};
|
|
77
|
+
exports.hash64 = hash64;
|
|
78
|
+
//# 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 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { NativeModules } from 'react-native';
|
|
4
|
+
let xxhashModule = globalThis.__xxhash128;
|
|
5
|
+
if (!xxhashModule) {
|
|
6
|
+
// New Architecture (RN 0.85 bridgeless): the native installJSIBindingsWithRuntime
|
|
7
|
+
// hook installs __xxhash128/__xxhash64, and the legacy install() is gone
|
|
8
|
+
// (calling it throws "undefined is not a function"). Guard it.
|
|
9
|
+
if (NativeModules.xxhash) {
|
|
10
|
+
if (typeof NativeModules.xxhash.install === 'function') {
|
|
11
|
+
NativeModules.xxhash.install();
|
|
12
|
+
}
|
|
13
|
+
xxhashModule = globalThis.__xxhash128;
|
|
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
|
+
export 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
|
+
|
|
62
|
+
export 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
|
+
//# 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":"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,192 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@javascriptcommon/react-native-xxhash",
|
|
3
|
+
"version": "0.1.9",
|
|
4
|
+
"description": "💪 react-native-xxhash fork with New Architecture / bridgeless (RN 0.85+) JSI install fix (iOS + Android). 💪 A high-performance React Native library for generating xxHash hashes using C++ and JSI",
|
|
5
|
+
"main": "./lib/commonjs/index.js",
|
|
6
|
+
"module": "./lib/module/index.js",
|
|
7
|
+
"types": "lib/typescript/index.d.ts",
|
|
8
|
+
"react-native": "src/index",
|
|
9
|
+
"source": "./src/index",
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"lib",
|
|
13
|
+
"android",
|
|
14
|
+
"ios",
|
|
15
|
+
"cpp",
|
|
16
|
+
"*.podspec",
|
|
17
|
+
"react-native.config.js",
|
|
18
|
+
"!ios/build",
|
|
19
|
+
"!android/build",
|
|
20
|
+
"!android/gradle",
|
|
21
|
+
"!android/gradlew",
|
|
22
|
+
"!android/gradlew.bat",
|
|
23
|
+
"!android/local.properties",
|
|
24
|
+
"!**/__tests__",
|
|
25
|
+
"!**/__fixtures__",
|
|
26
|
+
"!**/__mocks__",
|
|
27
|
+
"!**/.*"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"example": "yarn workspace react-native-xxhash-example",
|
|
31
|
+
"test": "jest",
|
|
32
|
+
"typecheck": "tsc",
|
|
33
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
34
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
35
|
+
"release": "release-it"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"react-native",
|
|
39
|
+
"ios",
|
|
40
|
+
"android",
|
|
41
|
+
"xxhash",
|
|
42
|
+
"hash",
|
|
43
|
+
"fast",
|
|
44
|
+
"xxhash3",
|
|
45
|
+
"react-native-xxhash",
|
|
46
|
+
"react-native-xxhash3",
|
|
47
|
+
"xxhash3-react-native",
|
|
48
|
+
"react-native-hash",
|
|
49
|
+
"hash-react-native",
|
|
50
|
+
"hash-xxhash",
|
|
51
|
+
"jsi",
|
|
52
|
+
"cpp",
|
|
53
|
+
"react-native-jsi",
|
|
54
|
+
"fast-hash",
|
|
55
|
+
"quick-hash",
|
|
56
|
+
"react-native-quick-hash",
|
|
57
|
+
"react-native-fast-hash",
|
|
58
|
+
"react-native-xxhash-jsi",
|
|
59
|
+
"react-native-xxhash-cpp",
|
|
60
|
+
"react-native-xxhash3-jsi",
|
|
61
|
+
"react-native-xxhash3-cpp"
|
|
62
|
+
],
|
|
63
|
+
"repository": {
|
|
64
|
+
"type": "git",
|
|
65
|
+
"url": "git+https://github.com/pioner92/react-native-xxhash"
|
|
66
|
+
},
|
|
67
|
+
"author": "pioner921227 <alex.shumihin921227@gmail.com> (https://github.com/pioner92/react-native-xxhash)",
|
|
68
|
+
"license": "MIT",
|
|
69
|
+
"bugs": {
|
|
70
|
+
"url": "https://github.com/pioner92/react-native-xxhash/issues"
|
|
71
|
+
},
|
|
72
|
+
"homepage": "https://github.com/pioner92/react-native-xxhash#readme",
|
|
73
|
+
"publishConfig": {
|
|
74
|
+
"registry": "https://registry.npmjs.org/",
|
|
75
|
+
"access": "public"
|
|
76
|
+
},
|
|
77
|
+
"devDependencies": {
|
|
78
|
+
"@commitlint/config-conventional": "^17.0.2",
|
|
79
|
+
"@evilmartians/lefthook": "^1.5.0",
|
|
80
|
+
"@react-native-community/cli": "15.0.1",
|
|
81
|
+
"@react-native/eslint-config": "^0.73.1",
|
|
82
|
+
"@release-it/conventional-changelog": "^9.0.2",
|
|
83
|
+
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
84
|
+
"@semantic-release/release-notes-generator": "^14.0.3",
|
|
85
|
+
"@types/jest": "^29.5.5",
|
|
86
|
+
"@types/react": "^18.2.44",
|
|
87
|
+
"@types/react-native": "^0.65.5",
|
|
88
|
+
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
|
89
|
+
"commitlint": "^17.0.2",
|
|
90
|
+
"del-cli": "^5.1.0",
|
|
91
|
+
"eslint": "^8.51.0",
|
|
92
|
+
"eslint-config-prettier": "^9.0.0",
|
|
93
|
+
"eslint-plugin-prettier": "^5.0.1",
|
|
94
|
+
"jest": "^29.7.0",
|
|
95
|
+
"prettier": "^3.0.3",
|
|
96
|
+
"react": "18.3.1",
|
|
97
|
+
"react-native": "0.76.6",
|
|
98
|
+
"react-native-builder-bob": "^0.35.2",
|
|
99
|
+
"release-it": "^17.10.0",
|
|
100
|
+
"typescript": "5.0.4"
|
|
101
|
+
},
|
|
102
|
+
"resolutions": {
|
|
103
|
+
"@types/react": "^18.2.44"
|
|
104
|
+
},
|
|
105
|
+
"peerDependencies": {
|
|
106
|
+
"react": "*",
|
|
107
|
+
"react-native": "*"
|
|
108
|
+
},
|
|
109
|
+
"workspaces": [
|
|
110
|
+
"example"
|
|
111
|
+
],
|
|
112
|
+
"packageManager": "yarn@3.6.1",
|
|
113
|
+
"jest": {
|
|
114
|
+
"preset": "react-native",
|
|
115
|
+
"modulePathIgnorePatterns": [
|
|
116
|
+
"<rootDir>/example/node_modules",
|
|
117
|
+
"<rootDir>/lib/"
|
|
118
|
+
]
|
|
119
|
+
},
|
|
120
|
+
"commitlint": {
|
|
121
|
+
"extends": [
|
|
122
|
+
"@commitlint/config-conventional"
|
|
123
|
+
]
|
|
124
|
+
},
|
|
125
|
+
"release-it": {
|
|
126
|
+
"git": {
|
|
127
|
+
"commitMessage": "chore: release ${version}",
|
|
128
|
+
"tagName": "v${version}"
|
|
129
|
+
},
|
|
130
|
+
"npm": {
|
|
131
|
+
"publish": true
|
|
132
|
+
},
|
|
133
|
+
"github": {
|
|
134
|
+
"release": true
|
|
135
|
+
},
|
|
136
|
+
"plugins": {
|
|
137
|
+
"@release-it/conventional-changelog": {
|
|
138
|
+
"preset": "angular"
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
"eslintConfig": {
|
|
143
|
+
"root": true,
|
|
144
|
+
"extends": [
|
|
145
|
+
"@react-native",
|
|
146
|
+
"prettier"
|
|
147
|
+
],
|
|
148
|
+
"rules": {
|
|
149
|
+
"react/react-in-jsx-scope": "off",
|
|
150
|
+
"prettier/prettier": [
|
|
151
|
+
"error",
|
|
152
|
+
{
|
|
153
|
+
"quoteProps": "consistent",
|
|
154
|
+
"singleQuote": true,
|
|
155
|
+
"tabWidth": 2,
|
|
156
|
+
"trailingComma": "es5",
|
|
157
|
+
"useTabs": false
|
|
158
|
+
}
|
|
159
|
+
]
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
"eslintIgnore": [
|
|
163
|
+
"node_modules/",
|
|
164
|
+
"lib/"
|
|
165
|
+
],
|
|
166
|
+
"prettier": {
|
|
167
|
+
"quoteProps": "consistent",
|
|
168
|
+
"singleQuote": true,
|
|
169
|
+
"tabWidth": 2,
|
|
170
|
+
"trailingComma": "es5",
|
|
171
|
+
"useTabs": false
|
|
172
|
+
},
|
|
173
|
+
"react-native-builder-bob": {
|
|
174
|
+
"source": "src",
|
|
175
|
+
"output": "lib",
|
|
176
|
+
"targets": [
|
|
177
|
+
"commonjs",
|
|
178
|
+
"module",
|
|
179
|
+
[
|
|
180
|
+
"typescript",
|
|
181
|
+
{
|
|
182
|
+
"project": "tsconfig.build.json"
|
|
183
|
+
}
|
|
184
|
+
]
|
|
185
|
+
]
|
|
186
|
+
},
|
|
187
|
+
"create-react-native-library": {
|
|
188
|
+
"type": "legacy-module",
|
|
189
|
+
"languages": "cpp",
|
|
190
|
+
"version": "0.45.5"
|
|
191
|
+
}
|
|
192
|
+
}
|
|
@@ -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,82 @@
|
|
|
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
|
+
// Referencing NativeModules.xxhash instantiates the module. Under the New
|
|
12
|
+
// Architecture (RN 0.85 bridgeless) that triggers the native
|
|
13
|
+
// installJSIBindingsWithRuntime hook, which installs __xxhash128/__xxhash64 —
|
|
14
|
+
// so the legacy install() no longer exists (calling it throws "undefined is
|
|
15
|
+
// not a function"). Only call install() when it actually exists (old arch).
|
|
16
|
+
if(NativeModules.xxhash){
|
|
17
|
+
if(typeof NativeModules.xxhash.install === 'function'){
|
|
18
|
+
NativeModules.xxhash.install();
|
|
19
|
+
}
|
|
20
|
+
xxhashModule = globalThis.__xxhash128;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Hashes the input string using the xxhash128 algorithm.
|
|
27
|
+
* This function provides a fast and deterministic 128-bit hash for a given string input.
|
|
28
|
+
*
|
|
29
|
+
* @param {string} input - The string to hash.
|
|
30
|
+
* @returns {string} The hashed string as a hexadecimal representation of the 128-bit hash.
|
|
31
|
+
* @throws {Error} If the input is not provided.
|
|
32
|
+
* @throws {Error} If the input is not of type string.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* const result = hash128("hello world");
|
|
36
|
+
* console.log(result); // Example output: "3a2b9e6a2b5e7e5a9e6a2b5e7e5a2a2"
|
|
37
|
+
*
|
|
38
|
+
* @description
|
|
39
|
+
* This function uses the xxhash128 algorithm, which provides a larger hash size (128-bit) compared to xxhash64.
|
|
40
|
+
* It is ideal for scenarios where a reduced collision risk is critical, such as in distributed systems or when hashing larger datasets.
|
|
41
|
+
*/
|
|
42
|
+
export const hash128 = (input: string): string => {
|
|
43
|
+
if(!input){
|
|
44
|
+
throw new Error('Input is required');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if(typeof input !== 'string'){
|
|
48
|
+
throw new Error('Input must be a string');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return globalThis.__xxhash128(input);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Hashes the input string using the xxhash64 algorithm.
|
|
56
|
+
* This function provides a fast and deterministic 64-bit hash for a given string input.
|
|
57
|
+
*
|
|
58
|
+
* @param {string} input - The string to hash.
|
|
59
|
+
* @returns {string} The hashed string as a hexadecimal representation of the 64-bit hash.
|
|
60
|
+
* @throws {Error} If the input is not provided.
|
|
61
|
+
* @throws {Error} If the input is not of type string.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* const result = hash64("hello world");
|
|
65
|
+
* console.log(result); // Example output: "9e6a2b5e7e5a2a2e"
|
|
66
|
+
*
|
|
67
|
+
* @description
|
|
68
|
+
* This function uses the xxhash64 algorithm, known for its high performance and low collision rate.
|
|
69
|
+
* It is ideal for hashing small to medium-sized strings.
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
export const hash64 = (input: string): string => {
|
|
73
|
+
if(!input){
|
|
74
|
+
throw new Error('Input is required');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if(typeof input !== 'string'){
|
|
78
|
+
throw new Error('Input must be a string');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return globalThis.__xxhash64(input);
|
|
82
|
+
}
|