Minor code review of set-local-storage-item scriptlet

This commit is contained in:
Raymond Hill 2023-06-23 08:23:08 -04:00
parent e50b391105
commit ea4afc0610
No known key found for this signature in database
GPG key ID: 25E1490B761470C2

View file

@ -2788,25 +2788,15 @@ function setLocalStorageItem(
if ( key === '' ) { return; }
if ( value === '' ) { return; }
const validValues = [
'undefined', 'null',
'false', 'true',
'yes', 'no',
'{}', '[]', "''",
];
let actualValue;
if ( value === 'undefined' ) {
actualValue = undefined;
} else if ( value === 'false' ) {
actualValue = false;
} else if ( value === 'true' ) {
actualValue = true;
} else if ( value === 'null' ) {
actualValue = null;
} else if ( value === '{}' ) {
actualValue = '{}';
} else if ( value === '[]' ) {
actualValue = '[]';
} else if ( value === "''" ) {
actualValue = '';
} else if ( value === 'yes' ) {
actualValue = 'yes';
} else if ( value === 'no' ) {
actualValue = 'no';
if ( validValues.includes(value) ) {
actualValue = value;
} else if ( /^\d+$/.test(value) ) {
actualValue = parseInt(value, 10);
if ( actualValue > 32767 ) { return; }