Index

Printer

MMO.core · 1 symbol · generated 30 Sep 2026

class

Printer

Printer.js:17

Printer: render any value to text.

class MMO.core.Printer
Namespace
MMO.core
Use Shared instance: Printer try every renderer corresponding to the given format (opts.format), or the given types (opts.type)
render something: MMO.core.Printer.Shared().render(value); add a new renderer: MMO.core.Printer.Shared().setRenderer('datetime', (value, opts) => ...);MMO.core.Printer.Shared().render(false, {format: status, type: [null]}) This will cause the printer to try the following renderder: 'status', 'null', 'boolean' (from typeof value). If any renderer exists and returns a string or an Element, the printer will stop trying other renderer.

Index

constructor()
Shared(id) staticGet a shared printer, creating it (with the default renderers) on first use.
setRenderer(format, fn, opts)Register how a format is rendered, replacing any previous renderer of that name.
getRenderer(format)
callRenderer(type, value, opts)Run one renderer, without the format/type resolution MMO.core.Printer#render does.
getOptions(format)
setOptions(format, opts)Replace a registered renderer's options.
render(value, opts)Render a value, trying the renderers in order until one accepts it: opts.format, then each of opts.type, then typeof value.
setDefaultRenderers()renderHeader(headerProperties, key) { if (headerProperties.contentRoot instanceof MMO.core.Map) { headerProperties = headerProperties.contentRoot.toObject(); } const currentHeader = headerPropertie…

Methods9

Shared(id)

staticPrinter.js:27

Get a shared printer, creating it (with the default renderers) on first use.

static Shared(id = '*')
id = '*'stringkeep several independent printers side by side
returnsMMO.core.Printer

setRenderer(format, fn, opts)

Printer.js:43

Register how a format is rendered, replacing any previous renderer of that name.

setRenderer(format, fn, opts = [])
formatstringa format name, a json type, or a typeof result
fnFunctionfunction(value, opts): string|Element|Array|null|false return null or false to decline the value and let the next renderer try
opts = []Objectoptions merged into every call's opts

getRenderer(format)

Printer.js:51
getRenderer(format)
formatstring
returns?Functionnull when nothing is registered

callRenderer(type, value, opts)

Printer.js:62

Run one renderer, without the format/type resolution MMO.core.Printer#render does.

callRenderer(type, value, opts)
typestringthe renderer's name
value*
optsObject
returnsstring | Element | Array | falsefalse when the renderer is missing or declined

getOptions(format)

Printer.js:76
getOptions(format)
formatstring
returns?Objectnull when nothing is registered under that name

setOptions(format, opts)

Printer.js:86

Replace a registered renderer's options.

setOptions(format, opts)
formatstring
optsObject
throwsMMO.Errorwhen nothing is registered under that name

render(value, opts)

Printer.js:98

Render a value, trying the renderers in order until one accepts it: opts.format, then each of opts.type, then typeof value.

render(value, opts = [])
value*
opts = []Objectformat, type, html and whatever the renderer reads
returnsstring | Element | Arraythe value stringified when no renderer matched

setDefaultRenderers()

Printer.js:134

renderHeader(headerProperties, key) { if (headerProperties.contentRoot instanceof MMO.core.Map) { headerProperties = headerProperties.contentRoot.toObject(); } const currentHeader = headerProperties[key]; if (!currentHeader.headerFormat) { return currentHeader.title; } return this.callRenderer(currentHeader.headerFormat, currentHeader); }

setDefaultRenderers()