Printer
MMO.core · 1 symbol · generated 5 Oct 2026
Printer
Printer.js:17Printer: render any value to text.
- Namespace
MMO.core
Index
| constructor() | ||
| Shared(id) static | Get 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
constructor()
Printer.js:18Shared(id)
staticPrinter.js:27Get a shared printer, creating it (with the default renderers) on first use.
| id = '*' | string | keep several independent printers side by side |
| returns | MMO.core.Printer |
setRenderer(format, fn, opts)
Printer.js:43Register how a format is rendered, replacing any previous renderer of that name.
| format | string | a format name, a json type, or a typeof result |
| fn | Function | function(value, opts): string|Element|Array|null|false return null or false to decline the value and let the next renderer try |
| opts = [] | Object | options merged into every call's opts |
getRenderer(format)
Printer.js:51| format | string | |
| returns | ?Function | null when nothing is registered |
callRenderer(type, value, opts)
Printer.js:62Run one renderer, without the format/type resolution MMO.core.Printer#render does.
| type | string | the renderer's name |
| value | * | |
| opts | Object | |
| returns | string | Element | Array | false | false when the renderer is missing or declined |
getOptions(format)
Printer.js:76| format | string | |
| returns | ?Object | null when nothing is registered under that name |
setOptions(format, opts)
Printer.js:86Replace a registered renderer's options.
| format | string | |
| opts | Object | |
| throws | MMO.Error | when nothing is registered under that name |
render(value, opts)
Printer.js:98Render a value, trying the renderers in order until one accepts it: opts.format, then each of opts.type, then typeof value.
| value | * | |
| opts = [] | Object | format, type, html and whatever the renderer reads |
| returns | string | Element | Array | the value stringified when no renderer matched |
setDefaultRenderers()
Printer.js:134renderHeader(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); }