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”:
- /*! p5.js v1.1.9 July 22, 2020 */:
cdn.JsDelivr.net/npm/p5@1.1.9 - /*! p5.min.js v0.2.22 July 30, 2014 */:
Unpkg.com/p5@0.2.23/lib/p5.min.js
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+)/
And here’s the HTML which grabs “v1.0.0”:
Bl.ocks.org/GoToLoop/raw/6125a5806872f7d4d93d11870b607851/v1.0.0.html
However, you’re gonna need to look for other unique features which “v1.0.0” has & “v0.10.2” doesn’t, so you can tell them apart. ![]()
For more tests here’s the complete list of 10 HTML links, each pointing to a different p5js lib version: ![]()
- Bl.ocks.org/GoToLoop/raw/6125a5806872f7d4d93d11870b607851
- Bl.ocks.org/GoToLoop/raw/6125a5806872f7d4d93d11870b607851/latest.html
- Bl.ocks.org/GoToLoop/raw/6125a5806872f7d4d93d11870b607851/v1.0.0.html
- Bl.ocks.org/GoToLoop/raw/6125a5806872f7d4d93d11870b607851/v0.10.2.html
- Bl.ocks.org/GoToLoop/raw/6125a5806872f7d4d93d11870b607851/v0.6.1.html
- Bl.ocks.org/GoToLoop/raw/6125a5806872f7d4d93d11870b607851/v0.5.16.html
- Bl.ocks.org/GoToLoop/raw/6125a5806872f7d4d93d11870b607851/v0.4.24.html
- Bl.ocks.org/GoToLoop/raw/6125a5806872f7d4d93d11870b607851/v0.3.16.html
- Bl.ocks.org/GoToLoop/raw/6125a5806872f7d4d93d11870b607851/v0.2.23.html
- Bl.ocks.org/GoToLoop/raw/6125a5806872f7d4d93d11870b607851/v0.2.22.html
P.S.: The 10th link (v0.2.22) fails to grab its version b/c it doesn’t have a comment block! ![]()
Apparently that versioning model starts at “v0.2.23”. ![]()