mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 21:14:28 -08:00
fix value explorer
This commit is contained in:
@@ -6,14 +6,21 @@
|
|||||||
|
|
||||||
import {el, stringify, scrollIntoViewIfNeeded} from './domutils.js'
|
import {el, stringify, scrollIntoViewIfNeeded} from './domutils.js'
|
||||||
|
|
||||||
|
const has_custom_toString = object =>
|
||||||
|
object.toString != globalThis.run_window.Object.prototype.toString
|
||||||
|
&&
|
||||||
|
object.toString != Object.prototype.toString
|
||||||
|
|
||||||
|
const isError = object =>
|
||||||
|
object instanceof Error
|
||||||
|
||
|
||||||
|
object instanceof globalThis.run_window.Error
|
||||||
|
|
||||||
const displayed_entries = object => {
|
const displayed_entries = object => {
|
||||||
if(Array.isArray(object)) {
|
if(Array.isArray(object)) {
|
||||||
return object.map((v, i) => [i, v])
|
return object.map((v, i) => [i, v])
|
||||||
} else {
|
} else {
|
||||||
const result = Object.entries(object)
|
return Object.entries(object)
|
||||||
return (object instanceof Error)
|
|
||||||
? [['message', object.message], ...result]
|
|
||||||
: result
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,7 +39,7 @@ export const stringify_for_header = v => {
|
|||||||
} else if(type == 'function') {
|
} else if(type == 'function') {
|
||||||
// TODO clickable link, 'fn', cursive
|
// TODO clickable link, 'fn', cursive
|
||||||
return 'fn ' + v.name
|
return 'fn ' + v.name
|
||||||
} else if(v instanceof Error) {
|
} else if(isError(v)) {
|
||||||
return v.toString()
|
return v.toString()
|
||||||
} else if(type == 'object') {
|
} else if(type == 'object') {
|
||||||
if(Array.isArray(v)) {
|
if(Array.isArray(v)) {
|
||||||
@@ -41,6 +48,8 @@ export const stringify_for_header = v => {
|
|||||||
} else {
|
} else {
|
||||||
return '[…]'
|
return '[…]'
|
||||||
}
|
}
|
||||||
|
} else if(has_custom_toString(v)) {
|
||||||
|
return v.toString()
|
||||||
} else {
|
} else {
|
||||||
if(displayed_entries(v).length == 0) {
|
if(displayed_entries(v).length == 0) {
|
||||||
return '{}'
|
return '{}'
|
||||||
@@ -61,7 +70,7 @@ export const header = object => {
|
|||||||
} else if(object == null) {
|
} else if(object == null) {
|
||||||
return 'null'
|
return 'null'
|
||||||
} else if(typeof(object) == 'object') {
|
} else if(typeof(object) == 'object') {
|
||||||
if(object instanceof Error) {
|
if(isError(object)) {
|
||||||
return object.toString()
|
return object.toString()
|
||||||
} else if(Array.isArray(object)) {
|
} else if(Array.isArray(object)) {
|
||||||
return '['
|
return '['
|
||||||
@@ -69,7 +78,7 @@ export const header = object => {
|
|||||||
.map(stringify_for_header)
|
.map(stringify_for_header)
|
||||||
.join(', ')
|
.join(', ')
|
||||||
+ ']'
|
+ ']'
|
||||||
} else if(object.toString != Object.prototype.toString) {
|
} else if(has_custom_toString(object)) {
|
||||||
return object.toString()
|
return object.toString()
|
||||||
} else {
|
} else {
|
||||||
const inner = displayed_entries(object)
|
const inner = displayed_entries(object)
|
||||||
|
|||||||
Reference in New Issue
Block a user