usps-webtools-promise
Version:
API wrapper for the USPS Web-Tools, with Promises!
23 lines (22 loc) • 618 B
JavaScript
import properCase from "../utils/proper-case.js";
import callUSPS from "../utils/request.js";
export default async function (zip) {
let response;
try {
response = (await callUSPS("CityStateLookup", "CityStateLookup", "ZipCode", this.config, {
ZipCode: {
Zip5: zip,
},
}));
if (response) {
if (this.config.properCase) {
response.City = properCase(response?.City);
}
return response;
}
throw new Error("Can't find result");
}
catch (error) {
return error;
}
}