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