Hey Retool,
I am trying to import a package into my app to do intelligent parsing of phone numbers.
Its called libphonenumber-js
.
Adding the /min-js/ to the libraries didn't seem to help.
Pasting the whole JavaScript code blob into the preloaded code also didn't seem to work.
https://cdnjs.cloudflare.com/ajax/libs/libphonenumber-js/1.10.59/libphonenumber-js.min.js
I imported this one using the library manager: https://cdnjs.cloudflare.com/ajax/libs/libphonenumber-js/1.10.59/libphonenumber-js.min.js
Then I put this into the Preloaded JS. It was not apparent to me that the libphonenumber variable was in the state.
var scrape=libphonenumber.findPhoneNumbersInText;
Then I can make a variable like this:
{{(()=>{
// var x=libphonenumber;
// var foo=libphonenumber.findPhoneNumbersInText;
var foo=scrape;
// return JSON.stringify(''+foo)
var x='';
x= foo(`
For tech support call +7 (800) 555-35-35 internationally
or reach a local US branch at (213) 373-4253 ext. 1234.
`, 'US')
// x=libphonenumber;
return JSON.stringify(x);
})()}}
The result looks like
"[{"startsAt":25,"endsAt":43,"number":{"country":"RU","countryCallingCode":"7","nationalNumber":"8005553535","number":"+78005553535","__countryCallingCodeSource":"FROM_NUMBER_WITH_PLUS_SIGN"}},{"startsAt":92,"endsAt":116,"number":{"country":"US","countryCallingCode":"1","nationalNumber":"2133734253","number":"+12133734253","ext":"1234"}}]"
Its amazing!