react-native-ultra-base64 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.
@@ -0,0 +1,6 @@
1
+ #pragma once
2
+ #import <React/RCTBridgeModule.h>
3
+
4
+ @interface RNUltraBase64 : NSObject <RCTBridgeModule>
5
+
6
+ @end
@@ -0,0 +1,41 @@
1
+ #import "UltraBase64.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
+ #import "react-native-ultra-base64.h"
8
+
9
+ using namespace facebook;
10
+
11
+ @implementation RNUltraBase64
12
+ RCT_EXPORT_MODULE(RNUltraBase64)
13
+
14
+ @synthesize bridge = _bridge;
15
+ @synthesize methodQueue = _methodQueue;
16
+
17
+ + (BOOL)requiresMainQueueSetup {
18
+ return NO;
19
+ }
20
+
21
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install){
22
+ NSLog(@"Installing JSI bindings for react-native-ultra-base64 ...");
23
+ RCTBridge* bridge = [RCTBridge currentBridge];
24
+ RCTCxxBridge* cxxBridge = (RCTCxxBridge*)bridge;
25
+
26
+ if (cxxBridge == nil) {
27
+ return @false;
28
+ }
29
+
30
+ auto jsiRuntime = (jsi::Runtime*) cxxBridge.runtime;
31
+ if (jsiRuntime == nil) {
32
+ return @false;
33
+ }
34
+
35
+ rnub_base64::install(jsiRuntime);
36
+
37
+ return @true;
38
+ }
39
+
40
+
41
+ @end
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.byteLength = byteLength;
7
+ exports.fromByteArray = fromByteArray;
8
+ exports.getNative = void 0;
9
+ exports.toByteArray = toByteArray;
10
+ exports.trimBase64Padding = void 0;
11
+ var _reactNative = require("react-native");
12
+ let RNUltraBase64Initialized = !!globalThis.encodeBase64FromArrayBuffer;
13
+ if (!RNUltraBase64Initialized) {
14
+ if (_reactNative.NativeModules.RNUltraBase64) {
15
+ _reactNative.NativeModules.RNUltraBase64.install();
16
+ RNUltraBase64Initialized = !!globalThis.encodeBase64FromArrayBuffer;
17
+ console.log('✅ react-native-ultra-base64 initialized successfully');
18
+ }
19
+ }
20
+
21
+ /**
22
+ * Calculates valid length and placeholder length for base64 string
23
+ */
24
+ function getLens(b64) {
25
+ const len = b64.length;
26
+ if (len % 4 > 0) {
27
+ throw new Error('Invalid string. Length must be a multiple of 4');
28
+ }
29
+ let validLen = b64.indexOf('=');
30
+ if (validLen === -1) validLen = len;
31
+ const placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4;
32
+ return [validLen, placeHoldersLen];
33
+ }
34
+
35
+ /**
36
+ * Calculates the byte length of a base64 string
37
+ */
38
+ function byteLength(b64) {
39
+ const [validLen, placeHoldersLen] = getLens(b64);
40
+ return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
41
+ }
42
+
43
+ /**
44
+ * Removes padding characters from base64 string
45
+ */
46
+ const trimBase64Padding = str => {
47
+ return str.replace(/[.=]{1,2}$/, '');
48
+ };
49
+ exports.trimBase64Padding = trimBase64Padding;
50
+ function fromByteArray(uint8, urlSafe = false) {
51
+ if (uint8.buffer.byteLength > uint8.byteLength || uint8.byteOffset > 0) {
52
+ const buffer = uint8.buffer instanceof ArrayBuffer ? uint8.buffer.slice(uint8.byteOffset, uint8.byteOffset + uint8.byteLength) : new ArrayBuffer(uint8.byteLength);
53
+ if (buffer instanceof ArrayBuffer) {
54
+ return global.encodeBase64FromArrayBuffer(buffer, urlSafe);
55
+ }
56
+ }
57
+ const buffer = uint8.buffer instanceof ArrayBuffer ? uint8.buffer : new ArrayBuffer(uint8.byteLength);
58
+ return global.encodeBase64FromArrayBuffer(buffer, urlSafe);
59
+ }
60
+ function toByteArray(input, removeLinebreaks = false) {
61
+ if (typeof input !== 'string') {
62
+ throw new TypeError('Input must be a string');
63
+ }
64
+ if (!input.length) {
65
+ return new Uint8Array(0);
66
+ }
67
+ return new Uint8Array(globalThis.decodeBase64ToArrayBuffer(input, removeLinebreaks));
68
+ }
69
+
70
+ /**
71
+ * Returns native base64 functions
72
+ */
73
+ const getNative = () => ({
74
+ encodeBase64FromArrayBuffer: globalThis.encodeBase64FromArrayBuffer,
75
+ decodeBase64ToArrayBuffer: globalThis.decodeBase64ToArrayBuffer
76
+ });
77
+ exports.getNative = getNative;
78
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","RNUltraBase64Initialized","globalThis","encodeBase64FromArrayBuffer","NativeModules","RNUltraBase64","install","console","log","getLens","b64","len","length","Error","validLen","indexOf","placeHoldersLen","byteLength","trimBase64Padding","str","replace","exports","fromByteArray","uint8","urlSafe","buffer","byteOffset","ArrayBuffer","slice","global","toByteArray","input","removeLinebreaks","TypeError","Uint8Array","decodeBase64ToArrayBuffer","getNative"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAQA,IAAIC,wBAAwB,GAAG,CAAC,CAACC,UAAU,CAACC,2BAA2B;AAEvE,IAAI,CAACF,wBAAwB,EAAE;EAC7B,IAAIG,0BAAa,CAACC,aAAa,EAAE;IAC/BD,0BAAa,CAACC,aAAa,CAACC,OAAO,CAAC,CAAC;IACrCL,wBAAwB,GAAG,CAAC,CAACC,UAAU,CAACC,2BAA2B;IACnEI,OAAO,CAACC,GAAG,CAAC,sDAAsD,CAAC;EACrE;AACF;;AAEA;AACA;AACA;AACA,SAASC,OAAOA,CAACC,GAAW,EAAE;EAC5B,MAAMC,GAAG,GAAGD,GAAG,CAACE,MAAM;EAEtB,IAAID,GAAG,GAAG,CAAC,GAAG,CAAC,EAAE;IACf,MAAM,IAAIE,KAAK,CAAC,gDAAgD,CAAC;EACnE;EAEA,IAAIC,QAAQ,GAAGJ,GAAG,CAACK,OAAO,CAA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IE,WAAW,CAACJ,KAAK,CAACN,UAAU,CAAC;EACvC,OAAOY,MAAM,CAAC1B,2BAA2B,CAACsB,MAAM,EAAED,OAAO,CAAC;AAE5D;AAEO,SAASM,WAAWA,CAACC,KAAa,EAAGC,gBAAyB,GAAG,KAAK,EAAc;EACzF,IAAI,OAAOD,KAAK,KAAK,QAAQ,EAAE;IAC7B,MAAM,IAAIE,SAAS,CAAC,wBAAwB,CAAC;EAC/C;EACA,IAAI,CAACF,KAAK,CAACnB,MAAM,EAAE;IACjB,OAAO,IAAIsB,UAAU,CAAC,CAAC,CAAC;EAC1B;EACA,OAAO,IAAIA,UAAU,CAAChC,UAAU,CAACiC,yBAAyB,CAACJ,KAAK,EAAEC,gBAAgB,CAAC,CAAC;AACtF;;AAGA;AACA;AACA;AACO,MAAMI,SAAS,GAAGA,CAAA,MAAO;EAC9BjC,2BAA2B,EAAED,UAAU,CAACC,2BAA2B;EACnEgC,yBAAyB,EAAEjC,UAAU,CAACiC;AACxC,CAAC,CAAC;AAAAd,OAAA,CAAAe,SAAA,GAAAA,SAAA","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ import { NativeModules } from 'react-native';
4
+ let RNUltraBase64Initialized = !!globalThis.encodeBase64FromArrayBuffer;
5
+ if (!RNUltraBase64Initialized) {
6
+ if (NativeModules.RNUltraBase64) {
7
+ NativeModules.RNUltraBase64.install();
8
+ RNUltraBase64Initialized = !!globalThis.encodeBase64FromArrayBuffer;
9
+ console.log('✅ react-native-ultra-base64 initialized successfully');
10
+ }
11
+ }
12
+
13
+ /**
14
+ * Calculates valid length and placeholder length for base64 string
15
+ */
16
+ function getLens(b64) {
17
+ const len = b64.length;
18
+ if (len % 4 > 0) {
19
+ throw new Error('Invalid string. Length must be a multiple of 4');
20
+ }
21
+ let validLen = b64.indexOf('=');
22
+ if (validLen === -1) validLen = len;
23
+ const placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4;
24
+ return [validLen, placeHoldersLen];
25
+ }
26
+
27
+ /**
28
+ * Calculates the byte length of a base64 string
29
+ */
30
+ export function byteLength(b64) {
31
+ const [validLen, placeHoldersLen] = getLens(b64);
32
+ return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
33
+ }
34
+
35
+ /**
36
+ * Removes padding characters from base64 string
37
+ */
38
+ export const trimBase64Padding = str => {
39
+ return str.replace(/[.=]{1,2}$/, '');
40
+ };
41
+ export function fromByteArray(uint8, urlSafe = false) {
42
+ if (uint8.buffer.byteLength > uint8.byteLength || uint8.byteOffset > 0) {
43
+ const buffer = uint8.buffer instanceof ArrayBuffer ? uint8.buffer.slice(uint8.byteOffset, uint8.byteOffset + uint8.byteLength) : new ArrayBuffer(uint8.byteLength);
44
+ if (buffer instanceof ArrayBuffer) {
45
+ return global.encodeBase64FromArrayBuffer(buffer, urlSafe);
46
+ }
47
+ }
48
+ const buffer = uint8.buffer instanceof ArrayBuffer ? uint8.buffer : new ArrayBuffer(uint8.byteLength);
49
+ return global.encodeBase64FromArrayBuffer(buffer, urlSafe);
50
+ }
51
+ export function toByteArray(input, removeLinebreaks = false) {
52
+ if (typeof input !== 'string') {
53
+ throw new TypeError('Input must be a string');
54
+ }
55
+ if (!input.length) {
56
+ return new Uint8Array(0);
57
+ }
58
+ return new Uint8Array(globalThis.decodeBase64ToArrayBuffer(input, removeLinebreaks));
59
+ }
60
+
61
+ /**
62
+ * Returns native base64 functions
63
+ */
64
+ export const getNative = () => ({
65
+ encodeBase64FromArrayBuffer: globalThis.encodeBase64FromArrayBuffer,
66
+ decodeBase64ToArrayBuffer: globalThis.decodeBase64ToArrayBuffer
67
+ });
68
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NativeModules","RNUltraBase64Initialized","globalThis","encodeBase64FromArrayBuffer","RNUltraBase64","install","console","log","getLens","b64","len","length","Error","validLen","indexOf","placeHoldersLen","byteLength","trimBase64Padding","str","replace","fromByteArray","uint8","urlSafe","buffer","byteOffset","ArrayBuffer","slice","global","toByteArray","input","removeLinebreaks","TypeError","Uint8Array","decodeBase64ToArrayBuffer","getNative"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,aAAa,QAAQ,cAAc;AAQ5C,IAAIC,wBAAwB,GAAG,CAAC,CAACC,UAAU,CAACC,2BAA2B;AAEvE,IAAI,CAACF,wBAAwB,EAAE;EAC7B,IAAID,aAAa,CAACI,aAAa,EAAE;IAC/BJ,aAAa,CAACI,aAAa,CAACC,OAAO,CAAC,CAAC;IACrCJ,wBAAwB,GAAG,CAAC,CAACC,UAAU,CAACC,2BAA2B;IACnEG,OAAO,CAACC,GAAG,CAAC,sDAAsD,CAAC;EACrE;AACF;;AAEA;AACA;AACA;AACA,SAASC,OAAOA,CAACC,GAAW,EAAE;EAC5B,MAAMC,GAAG,GAAGD,GAAG,CAACE,MAAM;EAEtB,IAAID,GAAG,GAAG,CAAC,GAAG,CAAC,EAAE;IACf,MAAM,IAAIE,KAAK,CAAC,gDAAgD,CAAC;EACnE;EAEA,IAAIC,QAAQ,GAAGJ,GAAG,CAACK,OAAO,CAAC,GAAG,CAAC;EAC/B,IAAID,QAAQ,KAAK,CAAC,CAAC,EAAEA,QAAQ,GAAGH,GAAG;EAEnC,MAAMK,eAAe,GAAGF,QAAQ,KAAKH,GAAG,GAAG,CAAC,GAAG,CAAC,GAAIG,QAAQ,GAAG,CAAE;EAEjE,OAAO,CAACA,QAAQ,EAAEE,eAAe,CAAC;AACpC;;AAGA;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CAACP,GAAW,EAAE;EACtC,MAAM,CAACI,QAAQ,EAAEE,eAAe,CAAC,GAAGP,OAAO,CAACC,GAAG,CAAC;EAChD,OAAQ,CAACI,QAAQ,GAAGE,eAAe,IAAI,CAAC,GAAI,CAAC,GAAGA,eAAe;AACjE;;AAEA;AACA;AACA;AACA,OAAO,MAAME,iBAAiB,GAAIC,GAAW,IA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MAAO;EAC9B/B,2BAA2B,EAAED,UAAU,CAACC,2BAA2B;EACnE8B,yBAAyB,EAAE/B,UAAU,CAAC+B;AACxC,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,22 @@
1
+ declare global {
2
+ var encodeBase64FromArrayBuffer: (input: ArrayBuffer, urlSafe: boolean) => string;
3
+ var decodeBase64ToArrayBuffer: (input: string, removeLinebreaks: boolean) => Uint8Array;
4
+ }
5
+ /**
6
+ * Calculates the byte length of a base64 string
7
+ */
8
+ export declare function byteLength(b64: string): number;
9
+ /**
10
+ * Removes padding characters from base64 string
11
+ */
12
+ export declare const trimBase64Padding: (str: string) => string;
13
+ export declare function fromByteArray(uint8: Uint8Array, urlSafe?: boolean): string;
14
+ export declare function toByteArray(input: string, removeLinebreaks?: boolean): Uint8Array;
15
+ /**
16
+ * Returns native base64 functions
17
+ */
18
+ export declare const getNative: () => {
19
+ encodeBase64FromArrayBuffer: (input: ArrayBuffer, urlSafe: boolean) => string;
20
+ decodeBase64ToArrayBuffer: (input: string, removeLinebreaks: boolean) => Uint8Array;
21
+ };
22
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAEA,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,2BAA2B,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,KAAK,MAAM,CAAC;IAClF,IAAI,yBAAyB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,OAAO,KAAK,UAAU,CAAC;CACzF;AAgCD;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,UAGrC;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,KAAK,MAAM,WAE5C,CAAA;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,EAAI,OAAO,GAAE,OAAe,GAAG,MAAM,CAqBnF;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAG,gBAAgB,GAAE,OAAe,GAAG,UAAU,CAQzF;AAGD;;GAEG;AACH,eAAO,MAAM,SAAS;yCAtFqB,WAAW,WAAW,OAAO,KAAK,MAAM;uCAC1C,MAAM,oBAAoB,OAAO,KAAK,UAAU;CAwFvF,CAAA"}
package/package.json ADDED
@@ -0,0 +1,128 @@
1
+ {
2
+ "name": "react-native-ultra-base64",
3
+ "version": "0.1.5",
4
+ "description": "⚡ The fastest base64 encoding/decoding library for React Native. Up to 5x faster with highly optimized C++ and JSI bindings.",
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-ultra-base64-example",
31
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
32
+ "prepare": "bob build",
33
+ "typecheck": "tsc",
34
+ "release": "release-it --only-version"
35
+ },
36
+ "keywords": [
37
+ "react-native",
38
+ "base64",
39
+ "encoding",
40
+ "decoding",
41
+ "encode",
42
+ "decode",
43
+ "fast",
44
+ "performance",
45
+ "jsi",
46
+ "ultra",
47
+ "native",
48
+ "cpp",
49
+ "ios",
50
+ "android",
51
+ "url-safe",
52
+ "buffer",
53
+ "uint8array",
54
+ "arraybuffer",
55
+ "binary",
56
+ "crypto"
57
+ ],
58
+ "repository": {
59
+ "type": "git",
60
+ "url": "git+https://github.com/pioner92/react-native-ultra-base64.git"
61
+ },
62
+ "author": "Alex Shumihin <shumolek@gmail.com> (https://github.com/pioner92)",
63
+ "license": "MIT",
64
+ "bugs": {
65
+ "url": "https://github.com/pioner92/react-native-ultra-base64/issues"
66
+ },
67
+ "homepage": "https://github.com/pioner92/react-native-ultra-base64#readme",
68
+ "publishConfig": {
69
+ "registry": "https://registry.npmjs.org/"
70
+ },
71
+ "devDependencies": {
72
+ "@react-native/babel-preset": "0.83.0",
73
+ "@release-it/conventional-changelog": "^10.0.1",
74
+ "@types/react": "^19.2.0",
75
+ "del-cli": "^6.0.0",
76
+ "react": "19.2.0",
77
+ "react-native": "0.83.0",
78
+ "react-native-builder-bob": "^0.35.2",
79
+ "release-it": "^19.0.4",
80
+ "typescript": "^5.9.2"
81
+ },
82
+ "peerDependencies": {
83
+ "react": "*",
84
+ "react-native": "*"
85
+ },
86
+ "workspaces": [
87
+ "example"
88
+ ],
89
+ "packageManager": "yarn@4.11.0",
90
+ "react-native-builder-bob": {
91
+ "source": "src",
92
+ "output": "lib",
93
+ "targets": [
94
+ "commonjs",
95
+ "module",
96
+ [
97
+ "typescript",
98
+ {
99
+ "project": "tsconfig.build.json"
100
+ }
101
+ ]
102
+ ]
103
+ },
104
+ "release-it": {
105
+ "git": {
106
+ "commitMessage": "chore: release ${version}",
107
+ "tagName": "v${version}"
108
+ },
109
+ "npm": {
110
+ "publish": true
111
+ },
112
+ "github": {
113
+ "release": true
114
+ },
115
+ "plugins": {
116
+ "@release-it/conventional-changelog": {
117
+ "preset": {
118
+ "name": "angular"
119
+ }
120
+ }
121
+ }
122
+ },
123
+ "create-react-native-library": {
124
+ "type": "legacy-module",
125
+ "languages": "cpp",
126
+ "version": "0.45.5"
127
+ }
128
+ }
@@ -0,0 +1,39 @@
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-ultra-base64"
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://github.com/pioner92/react-native-ultra-base64.git", :tag => "#{s.version}" }
16
+
17
+ s.source_files = "ios/**/*.{h,m,mm}", "cpp/**/*.{hpp,cpp,c,h}"
18
+
19
+ if respond_to?(:install_modules_dependencies, true)
20
+ install_modules_dependencies(s)
21
+ else
22
+ s.dependency "React-Core"
23
+
24
+ # Don't install the dependencies when we run `pod install` in the old architecture.
25
+ if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
26
+ s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
27
+ s.pod_target_xcconfig = {
28
+ "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
29
+ "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
30
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
31
+ }
32
+ s.dependency "React-Codegen"
33
+ s.dependency "RCT-Folly"
34
+ s.dependency "RCTRequired"
35
+ s.dependency "RCTTypeSafety"
36
+ s.dependency "ReactCommon/turbomodule/core"
37
+ end
38
+ end
39
+ end
package/src/index.tsx ADDED
@@ -0,0 +1,93 @@
1
+ import { NativeModules } from 'react-native'
2
+
3
+ declare global {
4
+ var encodeBase64FromArrayBuffer: (input: ArrayBuffer, urlSafe: boolean) => string;
5
+ var decodeBase64ToArrayBuffer: (input: string, removeLinebreaks: boolean) => Uint8Array;
6
+ }
7
+
8
+
9
+ let RNUltraBase64Initialized = !!globalThis.encodeBase64FromArrayBuffer;
10
+
11
+ if (!RNUltraBase64Initialized) {
12
+ if (NativeModules.RNUltraBase64) {
13
+ NativeModules.RNUltraBase64.install();
14
+ RNUltraBase64Initialized = !!globalThis.encodeBase64FromArrayBuffer;
15
+ console.log('✅ react-native-ultra-base64 initialized successfully')
16
+ }
17
+ }
18
+
19
+ /**
20
+ * Calculates valid length and placeholder length for base64 string
21
+ */
22
+ function getLens(b64: string) {
23
+ const len = b64.length
24
+
25
+ if (len % 4 > 0) {
26
+ throw new Error('Invalid string. Length must be a multiple of 4')
27
+ }
28
+
29
+ let validLen = b64.indexOf('=')
30
+ if (validLen === -1) validLen = len
31
+
32
+ const placeHoldersLen = validLen === len ? 0 : 4 - (validLen % 4)
33
+
34
+ return [validLen, placeHoldersLen] as const
35
+ }
36
+
37
+
38
+ /**
39
+ * Calculates the byte length of a base64 string
40
+ */
41
+ export function byteLength(b64: string) {
42
+ const [validLen, placeHoldersLen] = getLens(b64)
43
+ return ((validLen + placeHoldersLen) * 3) / 4 - placeHoldersLen
44
+ }
45
+
46
+ /**
47
+ * Removes padding characters from base64 string
48
+ */
49
+ export const trimBase64Padding = (str: string) => {
50
+ return str.replace(/[.=]{1,2}$/, '')
51
+ }
52
+
53
+ export function fromByteArray(uint8: Uint8Array, urlSafe: boolean = false): string {
54
+ if (uint8.buffer.byteLength > uint8.byteLength || uint8.byteOffset > 0) {
55
+ const buffer =
56
+ uint8.buffer instanceof ArrayBuffer
57
+ ? uint8.buffer.slice(
58
+ uint8.byteOffset,
59
+ uint8.byteOffset + uint8.byteLength
60
+ )
61
+ : new ArrayBuffer(uint8.byteLength)
62
+
63
+ if (buffer instanceof ArrayBuffer) {
64
+ return global.encodeBase64FromArrayBuffer(buffer, urlSafe)
65
+ }
66
+ }
67
+
68
+ const buffer =
69
+ uint8.buffer instanceof ArrayBuffer
70
+ ? uint8.buffer
71
+ : new ArrayBuffer(uint8.byteLength)
72
+ return global.encodeBase64FromArrayBuffer(buffer, urlSafe)
73
+
74
+ }
75
+
76
+ export function toByteArray(input: string, removeLinebreaks: boolean = false): Uint8Array {
77
+ if (typeof input !== 'string') {
78
+ throw new TypeError('Input must be a string');
79
+ }
80
+ if (!input.length) {
81
+ return new Uint8Array(0);
82
+ }
83
+ return new Uint8Array(globalThis.decodeBase64ToArrayBuffer(input, removeLinebreaks));
84
+ }
85
+
86
+
87
+ /**
88
+ * Returns native base64 functions
89
+ */
90
+ export const getNative = () => ({
91
+ encodeBase64FromArrayBuffer: globalThis.encodeBase64FromArrayBuffer,
92
+ decodeBase64ToArrayBuffer: globalThis.decodeBase64ToArrayBuffer
93
+ })