nzcp-js
nzcp-js copied to clipboard
Get the library to work in React Native
Tests should pass in React Native environment
Polyfilling TextEncoding (seems to) work currently, stuck on finding a suitable implementation of BigInt currently (that supports 0x... notation). I'm not sure what other core libraries don't have inbuilt React Native equivalents.
Also (attempting to) ping @meshcollider
Successfully got polyfills working for a react native implementation (soon to be public), based on modified code from this. Imo using a helper package is a bit clunky, but it's a possible way forward.
Specifically:
import 'text-encoding-polyfill'
global.Buffer = global.Buffer || require('buffer').Buffer
if (typeof BigInt === 'undefined') {
const bi = require('big-integer')
function myBigInt(value) {
if (typeof value === 'string') {
const match = value.match(/^0([xo])([0-9a-f]+)$/i)
if (match) {
return bi(match[2], match[1].toLowerCase() === 'x' ? 16 : 8)
}
}
return bi(value)
}
global.BigInt = myBigInt
if (process === undefined) {
process = require('process')
} else if (process.nextTick === undefined) {
process.nextTick = require('process').nextTick
}
}
We have two React Native apps now using this package, I suggest this closes.
Let's write down some documentation, maybe create REACT_NATIVE.md and link it in README.md?