Skip to content

Commit eeb0185

Browse files
Mohit TejaniMohit Tejani
authored andcommitted
use fast-text-encoding for react native instead outdated fast-encoding
1 parent 9032b02 commit eeb0185

File tree

4 files changed

+26
-22
lines changed

4 files changed

+26
-22
lines changed

lib/react_native/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
33
return (mod && mod.__esModule) ? mod : { "default": mod };
44
};
55
Object.defineProperty(exports, "__esModule", { value: true });
6-
const text_encoding_1 = require("text-encoding");
76
require("react-native-url-polyfill/auto");
7+
require("fast-text-encoding");
88
const cbor_js_1 = __importDefault(require("cbor-js"));
99
const buffer_1 = require("buffer");
1010
const stringify_buffer_keys_1 = require("../core/components/stringify_buffer_keys");
@@ -19,9 +19,7 @@ const LegacyCryptoModule_1 = __importDefault(require("../crypto/modules/LegacyCr
1919
const pubnub_common_1 = require("../core/pubnub-common");
2020
const configuration_2 = require("./configuration");
2121
const common_1 = __importDefault(require("../cbor/common"));
22-
// Polyfill global environment
23-
global.TextEncoder = global.TextEncoder || text_encoding_1.TextEncoder;
24-
global.TextDecoder = global.TextDecoder || text_encoding_1.TextDecoder;
22+
// Polyfill global Buffer for React Native environment
2523
global.Buffer = global.Buffer || buffer_1.Buffer;
2624
/**
2725
* PubNub client for React Native platform.

package-lock.json

Lines changed: 18 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@
6060
"buffer": "^6.0.3",
6161
"cbor-js": "^0.1.0",
6262
"cbor-sync": "^1.0.4",
63+
"fast-text-encoding": "^1.0.6",
6364
"fflate": "^0.8.2",
6465
"form-data": "^4.0.4",
6566
"lil-uuid": "^0.1.1",
6667
"node-fetch": "^2.7.0",
6768
"proxy-agent": "^6.3.0",
68-
"react-native-url-polyfill": "^2.0.0",
69-
"text-encoding": "^0.7.0"
69+
"react-native-url-polyfill": "^2.0.0"
7070
},
7171
"devDependencies": {
7272
"@rollup/plugin-commonjs": "^25.0.7",
@@ -79,6 +79,7 @@
7979
"@types/chai": "^4.3.14",
8080
"@types/chai-as-promised": "^7.1.8",
8181
"@types/expect": "^24.3.0",
82+
"@types/fast-text-encoding": "^1.0.3",
8283
"@types/lil-uuid": "^0.1.3",
8384
"@types/mocha": "^9.1.0",
8485
"@types/nock": "^9.3.1",
@@ -118,8 +119,8 @@
118119
"sinon": "^7.5.0",
119120
"sinon-chai": "^3.3.0",
120121
"source-map-support": "^0.5.21",
121-
"ts-mocha": "^10.0.0",
122122
"ts-loader": "^9.5.2",
123+
"ts-mocha": "^10.0.0",
123124
"ts-node": "^10.9.2",
124125
"tsx": "^4.7.1",
125126
"typescript": "^5.4.5",

src/react_native/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { TextEncoder, TextDecoder } from 'text-encoding';
21
import 'react-native-url-polyfill/auto';
2+
import 'fast-text-encoding';
33
import CborReader from 'cbor-js';
44
import { Buffer } from 'buffer';
55

@@ -29,9 +29,7 @@ export type {
2929
} from '../core/components/retry-policy';
3030
export type { PubNubConfiguration };
3131

32-
// Polyfill global environment
33-
global.TextEncoder = global.TextEncoder || TextEncoder;
34-
global.TextDecoder = global.TextDecoder || TextDecoder;
32+
// Polyfill global Buffer for React Native environment
3533
global.Buffer = global.Buffer || Buffer;
3634

3735
/**

0 commit comments

Comments
 (0)