Detect p5 1.1.9 vs 1.0.0?

Hi folks,

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).

Grazie, GE.

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. :crazy_face:

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”:

  1. /*! p5.js v1.1.9 July 22, 2020 */:
    cdn.JsDelivr.net/npm/p5@1.1.9
  2. /*! 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”! :unamused:

Unfortunately “v1.0.0” displays “v0.10.2”. Same problem some p5js versions are having: :face_with_head_bandage:
/*! 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. :male_detective:

For more tests here’s the complete list of 10 HTML links, each pointing to a different p5js lib version: :scroll:

  1. Bl.ocks.org/GoToLoop/raw/6125a5806872f7d4d93d11870b607851
  2. Bl.ocks.org/GoToLoop/raw/6125a5806872f7d4d93d11870b607851/latest.html
  3. Bl.ocks.org/GoToLoop/raw/6125a5806872f7d4d93d11870b607851/v1.0.0.html
  4. Bl.ocks.org/GoToLoop/raw/6125a5806872f7d4d93d11870b607851/v0.10.2.html
  5. Bl.ocks.org/GoToLoop/raw/6125a5806872f7d4d93d11870b607851/v0.6.1.html
  6. Bl.ocks.org/GoToLoop/raw/6125a5806872f7d4d93d11870b607851/v0.5.16.html
  7. Bl.ocks.org/GoToLoop/raw/6125a5806872f7d4d93d11870b607851/v0.4.24.html
  8. Bl.ocks.org/GoToLoop/raw/6125a5806872f7d4d93d11870b607851/v0.3.16.html
  9. Bl.ocks.org/GoToLoop/raw/6125a5806872f7d4d93d11870b607851/v0.2.23.html
  10. 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! :no_entry:
Apparently that versioning model starts at “v0.2.23”. :ok:

2 Likes

Hi @GoToLoop thanks for that info. I’m away for a few days but will look more maybe on Wednesday. Cheers.

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.

1 Like

Despite many releases not matching their actual version number:

They can still be told apart if we also take into account their release date:

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);

Woo hoo. As of p5 1.3.1, there is a VERSION identifier.

example:

function setup() {
console.log(“p5 version is:”, VERSION);

2 Likes