browserify / node-util

node.js util module as a module
MIT License
247 stars 88 forks source link

TextEncoder, TextDecoder #46

Closed ekkis closed 3 years ago

ekkis commented 4 years ago

I typically do:

const {TextEncoder, TextDecoder} = require('util')

but now I'm building a React Native app and had to actually install this package npm i util, however the methods above I see are missing. where can I get them from and why are they not included in this package?

goto-bus-stop commented 4 years ago

It's not included because I don't currently know of a high-quality polyfill, and if I did it would probably be too large to include by default when targeting a browser bundle. One thing i've wanted to add is a reexport of window.TextDecoder and window.TextEncoder in the browser if they are available, but i don't know if react native provides those.

shristov-iMeniu commented 3 years ago

Hi, is there any solution of this issue?

goto-bus-stop commented 3 years ago

@shristov-iMeniu Node.js and browsers both provide these as global variables, so you can use those instead of importing the util package.

ekkis commented 3 years ago

I think the above is a good solution. closing the issue. thank you

tex0l commented 2 years ago

React-native doesn't provide any polyfill for TextEncoder, it would be great if util implemented it.

elliotsayes commented 2 years ago

For those who want basic text-encoding (TextEncoder/TextDecoder), I made a fork that includes this. Based on text-encoding-polyfill as it is the most node-compatible (e.g. supports options such as fatal). This lets you drop in support for libraries that rely on TextEncoder/TextDecoder from node's util package.

Find it here: https://github.com/elliotsayes/node-util-text-encoding