mirror of
https://github.com/talwrii/plugin-repl.git
synced 2026-07-22 11:40:27 +00:00
24 lines
673 B
TypeScript
24 lines
673 B
TypeScript
import * as util from 'util'
|
|
|
|
export const formatObj = (x: any) => {
|
|
if (x === undefined) {
|
|
return "undefined"
|
|
}
|
|
else if (x === null) {
|
|
return "null"
|
|
} else if (typeof x === "string") {
|
|
return x.toString()
|
|
} else if (typeof x === "boolean") {
|
|
return x.toString()
|
|
} else if (typeof x === "number") {
|
|
return x.toString()
|
|
} else if (x.constructor === undefined) {
|
|
return util.inspect(x)
|
|
} else if (x.constructor === Array) {
|
|
return x.toString()
|
|
} else if (x.constructor === Object) {
|
|
return util.inspect(x)
|
|
} else {
|
|
return `[${x.constructor.name} object]`
|
|
}
|
|
}
|