The JavaScript column already includes lodash, which provides a value named _ with many useful utility functions. lodash is the most popular JavaScript library in the world, so we included it by default even if you do not use it.
@Jeff_Hager recently requestedmathjs support in the JavaScript column. mathjs is another top JavaScript library, but including it by default means that every app that uses the JavaScript column would load this library as well, even though very few people need it.
Today I discovered how you can load any JavaScript package within the JavaScript column using skypack.dev and a newer JavaScript feature called async import.
Example: Load mathjs to evaluate a complex expression:
// Use await import to load the package:
const mathjs = await import("https://cdn.skypack.dev/mathjs");
// Use any function in the package:
return mathjs.evaluate("sin(45 deg) ^ 2");
Alternatively, you could use JavaScript object destructuring syntax to import evaluate more specifically:
Is there a place where we can see our code? Or … does the Glide team ever consider adding low code to the no-code platform for anyone who would like to tweak some code …?
Thank you for finding this. I’ve been playing with this and its working great. One of my uses it to calculate the bearing between two sets of coordinates.
const math = await import("https://cdn.skypack.dev/mathjs");
var LatA = p1.split(',')[0]
var LonA = p1.split(',')[1]
var LatB = p2.split(',')[0]
var LonB = p2.split(',')[1]
var Bearing = math.round(math.mod(math.atan2(
math.sin((LonB-LonA)*math.pi/180)* math.cos(LatB*math.pi/180)
,
math.cos(LatA*math.pi/180)* math.sin(LatB*math.pi/180)-
math.sin(LatA*math.pi/180)* math.cos(LatB*math.pi/180)* math.cos((LonB-LonA)*math.pi/180)
)*180/math.pi+360,360),0)
if (Bearing <=11.25) {return Bearing + '° ⇑ N';}
if (Bearing <=33.75) {return Bearing + '° ⇗ NNE';}
if (Bearing <=56.25) {return Bearing + '° ⇗ NE';}
if (Bearing <=78.75) {return Bearing + '° ⇗ ENE';}
if (Bearing <=101.25) {return Bearing + '° ⇒ E';}
if (Bearing <=123.75) {return Bearing + '° ⇘ ESE';}
if (Bearing <=146.25) {return Bearing + '° ⇘ SE';}
if (Bearing <=168.75) {return Bearing + '° ⇘ SSE';}
if (Bearing <=191.25) {return Bearing + '° ⇓ S';}
if (Bearing <=213.75) {return Bearing + '° ⇙ SSW';}
if (Bearing <=236.25) {return Bearing + '° ⇙ SW';}
if (Bearing <=258.75) {return Bearing + '° ⇙ WSW';}
if (Bearing <=281.25) {return Bearing + '° ⇐ W';}
if (Bearing <=303.75) {return Bearing + '° ⇖ WNW';}
if (Bearing <=326.25) {return Bearing + '° ⇖ NW';}
if (Bearing <=348.75) {return Bearing + '° ⇖ NNW';}
return Bearing + '° ⇑ N';
If they are built in, I haven’t been able to figure it out. At most I could only do add/subtract/multiply/divide. Everything I searched for seemed to refer to math.js or math.xxx functions.
I just realized why I had trouble. The elusive case sensitivity of javascript. I knew about it, but it didn’t click. Big difference between math.xxx and Math.xxx. Probably saw a bunch of examples with the lowercase ‘m’ and it wasn’t working. I’m more accustomed to the more forgiving languages or IDE’s with autocomplete.
Sorry I rose a stink over this, but I’m glad you found a way to import.
I love the elintero’s tweet!!! It would be great make this charts in our apps! I tried pie version, but I would like use line and bar charts. I can’t wait to see it!
That’s cool. I’m guessing the main advantage is not to rely on the Experimental code for simple code samples? Right now, I’m using the package manager in Replit.