mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
don't use switch where single if/else works
This commit is contained in:
parent
e0b9a3fa50
commit
ae68264db4
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user