@@ -144,6 +144,8 @@ export const p5Versions = [
144
144
145
145
export const currentP5Version = '1.11.5' ; // Don't update to 2.x until 2026
146
146
147
+ export const majorVersion = ( version ) => version . split ( '.' ) [ 0 ] ;
148
+
147
149
export const p5SoundURLOldTemplate =
148
150
'https://cdnjs.cloudflare.com/ajax/libs/p5.js/$VERSION/addons/p5.sound.min.js' ;
149
151
export const p5SoundURLOld = p5SoundURLOldTemplate . replace (
@@ -227,7 +229,7 @@ export function P5VersionProvider(props) {
227
229
const newNode = document . createElement ( 'script' ) ;
228
230
newNode . setAttribute (
229
231
'src' ,
230
- version . startsWith ( '2' )
232
+ majorVersion ( version ) === '2'
231
233
? p5SoundURL
232
234
: p5SoundURLOldTemplate . replace ( '$VERSION' , version )
233
235
) ;
@@ -255,14 +257,14 @@ export function P5VersionProvider(props) {
255
257
) ;
256
258
257
259
if ( p5SoundNode ) {
258
- if ( version . startsWith ( '2.' ) !== newVersion . startsWith ( '2.' ) ) {
260
+ if ( majorVersion ( version ) !== majorVersion ( newVersion ) ) {
259
261
// Turn off p5.sound if the user switched from 1.x to 2.x
260
262
setP5Sound ( false ) ;
261
263
} else {
262
264
// Replace the existing p5.sound with the one compatible with
263
265
// the new version
264
266
setP5SoundURL (
265
- version . startsWith ( '2.' )
267
+ majorVersion ( version ) === '2'
266
268
? p5SoundURL
267
269
: p5SoundURLOldTemplate . replace ( '$VERSION' , newVersion )
268
270
) ;
@@ -316,7 +318,7 @@ export function P5VersionProvider(props) {
316
318
317
319
return {
318
320
version,
319
- isVersion2 : version . startsWith ( '2.' ) ,
321
+ isVersion2 : majorVersion ( version ) === '2' ,
320
322
minified,
321
323
replaceVersion,
322
324
p5Sound : ! ! p5SoundNode ,
0 commit comments