mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 13:04:30 -08:00
refactor
This commit is contained in:
@@ -59,20 +59,22 @@ 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 (isPromise(v)) {
|
} else if(type == 'string') {
|
||||||
if(v.status == null) {
|
return JSON.stringify(v)
|
||||||
return `Promise<pending>`
|
|
||||||
} else {
|
|
||||||
if(v.status.ok) {
|
|
||||||
return `Promise<fulfilled: ${stringify_for_header(v.status.value)}>`
|
|
||||||
} else {
|
|
||||||
return `Promise<rejected: ${stringify_for_header(v.status.error)}>`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if(isError(v)) {
|
|
||||||
return v.toString()
|
|
||||||
} else if(type == 'object') {
|
} else if(type == 'object') {
|
||||||
if(Array.isArray(v)) {
|
if (isPromise(v)) {
|
||||||
|
if(v.status == null) {
|
||||||
|
return `Promise<pending>`
|
||||||
|
} else {
|
||||||
|
if(v.status.ok) {
|
||||||
|
return `Promise<fulfilled: ${stringify_for_header(v.status.value)}>`
|
||||||
|
} else {
|
||||||
|
return `Promise<rejected: ${stringify_for_header(v.status.error)}>`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if(isError(v)) {
|
||||||
|
return v.toString()
|
||||||
|
} else if(Array.isArray(v)) {
|
||||||
if(v.length == 0) {
|
if(v.length == 0) {
|
||||||
return '[]'
|
return '[]'
|
||||||
} else {
|
} else {
|
||||||
@@ -87,19 +89,24 @@ export const stringify_for_header = v => {
|
|||||||
return '{…}'
|
return '{…}'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if(type == 'string') {
|
|
||||||
return JSON.stringify(v)
|
|
||||||
} else {
|
} else {
|
||||||
return v.toString()
|
return v.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const header = object => {
|
export const header = object => {
|
||||||
if(typeof(object) == 'undefined') {
|
const type = typeof(object)
|
||||||
return 'undefined'
|
|
||||||
} else if(object == null) {
|
if(object === null) {
|
||||||
return 'null'
|
return 'null'
|
||||||
} else if(typeof(object) == 'object') {
|
} else if(object === undefined) {
|
||||||
|
return 'undefined'
|
||||||
|
} else if(type == 'function') {
|
||||||
|
// TODO clickable link, 'fn', cursive
|
||||||
|
return 'fn ' + object.name
|
||||||
|
} else if(type == 'string') {
|
||||||
|
return JSON.stringify(object)
|
||||||
|
} else if(type == 'object') {
|
||||||
if(isPromise(object)) {
|
if(isPromise(object)) {
|
||||||
if(object.status == null) {
|
if(object.status == null) {
|
||||||
return `Promise<pending>`
|
return `Promise<pending>`
|
||||||
@@ -133,11 +140,6 @@ export const header = object => {
|
|||||||
.join(', ')
|
.join(', ')
|
||||||
return `${prefix} {${inner}}`
|
return `${prefix} {${inner}}`
|
||||||
}
|
}
|
||||||
} else if(typeof(object) == 'function') {
|
|
||||||
// TODO clickable link, 'fn', cursive
|
|
||||||
return 'fn ' + object.name
|
|
||||||
} else if(typeof(object) == 'string') {
|
|
||||||
return JSON.stringify(object)
|
|
||||||
} else {
|
} else {
|
||||||
return object.toString()
|
return object.toString()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user