diff --git a/src/data/local_storage.js b/src/data/local_storage.js index a34f3172fa..29395978e1 100644 --- a/src/data/local_storage.js +++ b/src/data/local_storage.js @@ -120,20 +120,23 @@ import p5 from '../core/main'; * * */ -p5.prototype.storeItem = function(key, value) { +p5.prototype.storeItem = function (key, value) { if (typeof key !== 'string') { - console.log( + p5._friendlyError( `The argument that you passed to storeItem() - ${key} is not a string.` ); + return; } if (key.endsWith('p5TypeID')) { - console.log( + p5._friendlyError( `The argument that you passed to storeItem() - ${key} must not end with 'p5TypeID'.` ); + return; } if (typeof value === 'undefined') { - console.log('You cannot store undefined variables using storeItem().'); + p5._friendlyError('You cannot store undefined variables using storeItem().'); + return; } let type = typeof value; switch (type) { @@ -276,13 +279,14 @@ p5.prototype.storeItem = function(key, value) { * * */ -p5.prototype.getItem = function(key) { +p5.prototype.getItem = function (key) { let value = localStorage.getItem(key); const type = localStorage.getItem(`${key}p5TypeID`); if (typeof type === 'undefined') { - console.log( + p5._friendlyError( `Unable to determine type of item stored under ${key}in local storage. Did you save the item with something other than setItem()?` ); + return; } else if (value !== null) { switch (type) { case 'number': @@ -442,11 +446,12 @@ p5.prototype.clearStorage = function () { * * */ -p5.prototype.removeItem = function(key) { +p5.prototype.removeItem = function (key) { if (typeof key !== 'string') { - console.log( + p5._friendlyError( `The argument that you passed to removeItem() - ${key} is not a string.` ); + return; } localStorage.removeItem(key); localStorage.removeItem(`${key}p5TypeID`);