@@ -144,6 +144,8 @@ export const p5Versions = [
144144
145145export const currentP5Version = '1.11.5' ; // Don't update to 2.x until 2026
146146
147+ export const majorVersion = ( version ) => version . split ( '.' ) [ 0 ] ;
148+
147149export const p5SoundURLOldTemplate =
148150 'https://cdnjs.cloudflare.com/ajax/libs/p5.js/$VERSION/addons/p5.sound.min.js' ;
149151export const p5SoundURLOld = p5SoundURLOldTemplate . replace (
@@ -227,7 +229,7 @@ export function P5VersionProvider(props) {
227229 const newNode = document . createElement ( 'script' ) ;
228230 newNode . setAttribute (
229231 'src' ,
230- version . startsWith ( '2' )
232+ majorVersion ( version ) === '2'
231233 ? p5SoundURL
232234 : p5SoundURLOldTemplate . replace ( '$VERSION' , version )
233235 ) ;
@@ -255,14 +257,14 @@ export function P5VersionProvider(props) {
255257 ) ;
256258
257259 if ( p5SoundNode ) {
258- if ( version . startsWith ( '2.' ) !== newVersion . startsWith ( '2.' ) ) {
260+ if ( majorVersion ( version ) !== majorVersion ( newVersion ) ) {
259261 // Turn off p5.sound if the user switched from 1.x to 2.x
260262 setP5Sound ( false ) ;
261263 } else {
262264 // Replace the existing p5.sound with the one compatible with
263265 // the new version
264266 setP5SoundURL (
265- version . startsWith ( '2.' )
267+ majorVersion ( version ) === '2'
266268 ? p5SoundURL
267269 : p5SoundURLOldTemplate . replace ( '$VERSION' , newVersion )
268270 ) ;
@@ -316,7 +318,7 @@ export function P5VersionProvider(props) {
316318
317319 return {
318320 version,
319- isVersion2 : version . startsWith ( '2.' ) ,
321+ isVersion2 : majorVersion ( version ) === '2' ,
320322 minified,
321323 replaceVersion,
322324 p5Sound : ! ! p5SoundNode ,
0 commit comments