Since p5.js 0.7.2 I’ve been able to distinguish what release I’m running on by checking that “typeof” some function or constant is “undefined” or not. This relies on new functions etc. being available to check, but release 1.1.9 is not documented as having any major new “names” like that. There are some new optional parameters to some calls, and maybe you could detect that with JS exception handling, but my JS exception skills are not up to that at present.
Does anyone have any suggestion as to how to detect whether you’re running on 1.0.0 or 1.1.9 ?
(To answer the obvious, I’ve requested in the Github issues to include a “version number” but it has not gained approval).
I’m also puzzled why devs from both Processing Java & p5js flavors so adamantly refuse to add some way for a sketch to inspect which version it is running on.
Indeed the p5 constructor doesn’t contain any info about its version.
The only place I’ve found it was inside the “p5.js” file itself on its 1st line as a comment block.
Take a look at these 2 examples below.
1st is from the current “v1.1.9” and 2nd is from a very old “v.0.2.3”:
Notice on the 2nd example its comment shows “v0.2.22”, although it shoulda been “v0.2.23”!
Unfortunately “v1.0.0” displays “v0.10.2”. Same problem some p5js versions are having: /*! p5.js v0.10.2 February 29, 2020 */: cdn.JsDelivr.net/npm/p5@1.0.0
BtW, I’ve finished creating a new p5 method called getVersion() which uses loadStrings() to download the p5js library as text and then grab its comment block version via a regex expression I’ve made up: /p5(?:\.min)?\.js v(\d+)\.(\d+)\.(\d+)/
Hi @GoToLoop I’m back on deck. I am looking at your tools to get the p5.js version, thanks. I only need to distinguish the last few versions, so oddities from very early versions are not an issue for me. I’m pleased to find one can look at the source text of the p5.js or p5.min.js from within a p5 sketch, and with an ingenious regexp find the version string, I will spend some time on that. Ciao for now.
On the latest version of my sketch (v1.1.0), I’m also capturing the release date values: p5jsVER = /p5(?:\.min)?\.js v(\d+)\.(\d+)\.(\d+) (\w+) (\d+), (\d+)/
And storing them in p5.prototype._release as 1 string: p5.prototype._release = this._release = matches.slice(4).join(SPC);