Home > Enterprise >  Convert USPS Manager class C# code to JavaScript
Convert USPS Manager class C# code to JavaScript

Time:05-04

I have some working USPS Manager C# code but need to execute it from Google Apps Script in JavaScript.

How would I convert the below to JavaScript format?

USPSManager m = new USPSManager("YOUR_USER_ID", true);
Address a = new Address();
a.Address2 = "6406 Ivy Lane";
a.City = "Greenbelt";
a.State = "MD";
Address addressWithZip = m.GetZipcode(a);
string zip = addressWithZip.Zip;

Thanks in advance for any tips.

CodePudding user response:

Here it is "translated" into JavaScript. Thing is, if USPS doesn't have a USPSManager class written in JavaScript, then this isn't going to work - or you'll have to write one yourself.

const m = new USPSManager("YOUR_USER_ID", true);
const a = new Address();
a.Address2 = "6406 Ivy Lane";
a.City = "Greenbelt";
a.State = "MD";
const addressWithZip = m.GetZipcode(a);
const zip = addressWithZip.Zip;

CodePudding user response:

If you are writing code in JavaScript, using a C# library will not work. You need to use a JavaScript library.

A quick search on NPM found this usps-webtools package.

  • Related