don't use switch where single if/else works

This commit is contained in:
Bruno Windels 2021-09-30 08:42:00 +02:00
parent e0b9a3fa50
commit ae68264db4

View File

@ -22,13 +22,8 @@ export function parse(value: string): any {
return decodeValue(JSON.parse(value));
}
function encodeValue(value: any): any {
switch (typeof value) {
case "object": {
if (value === null || Array.isArray(value)) {
return value;
}
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
// TypedArray
if (value.byteLength) {
return {_type: value.constructor.name, value: Array.from(value)};
@ -40,18 +35,13 @@ function encodeValue(value: any): any {
}
}
return newObj;
}
default:
} else {
return value;
}
}
function decodeValue(value: any): any {
switch (typeof value) {
case "object": {
if (value === null || Array.isArray(value)) {
return value;
}
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
if (typeof value._type === "string") {
switch (value._type) {
case "Int8Array": return Int8Array.from(value.value);
@ -76,8 +66,7 @@ function decodeValue(value: any): any {
}
}
return newObj;
}
default:
} else {
return value;
}
}