forked from LaconicNetwork/cosmos-explorer
40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import ObjectElement from './ObjectElement.vue';
|
|
import TextElement from './TextElement.vue';
|
|
import ArrayElement from './ArrayElement.vue';
|
|
import UInt8Array from './UInt8Array.vue';
|
|
import NumberElement from './NumberElement.vue';
|
|
import TxsElement from './TxsElement.vue';
|
|
import ObjectHorizontalElement from './ObjectHorizontalElement.vue';
|
|
import Long from 'long';
|
|
|
|
export function select(v: any, direct?: string) {
|
|
// if(k === 'txs' && v) {
|
|
// return TxsElement
|
|
// } else {
|
|
const type = typeof v;
|
|
switch (type) {
|
|
case 'object':
|
|
return selectObject(v, direct);
|
|
case 'number':
|
|
return NumberElement;
|
|
default:
|
|
return TextElement;
|
|
}
|
|
// }
|
|
}
|
|
|
|
function selectObject(v: Object, direct?: string) {
|
|
switch (true) {
|
|
case v instanceof Long:
|
|
return NumberElement;
|
|
case v instanceof Uint8Array:
|
|
return UInt8Array;
|
|
case Array.isArray(v):
|
|
return ArrayElement;
|
|
case direct === 'horizontal':
|
|
return ObjectHorizontalElement;
|
|
default:
|
|
return ObjectElement;
|
|
}
|
|
}
|