NFTfi-Genesis / nftfi.js

JavaScript SDK for interacting with the NFTfi Protocol
https://www.nftfi.com
14 stars 14 forks source link

Fix browser error where `global` is not defined #4

Open Kipitup opened 1 year ago

Kipitup commented 1 year ago

Problem

The global object is used in Node.js environments, but in browser environments the global object is window. So it's important to check the context of the execution before using the global object.

Proposed fix

In JavaScript, you can use the typeof process to check if your code is running in a Node.js environment or not. The process object is a global object that is only available in Node.js, so if typeof process returns "object", it means your code is running in a Node.js environment. If it returns "undefined", it means your code is running in a browser environment.

Additionally, the ?. operator is a new feature in javascript and it's not supported in all environments, so you should check if your environment supports it or use a polyfill. But this is beyond the scope of this pull request.