Section33 pages
Output functions
Basic functions for output and formatting.
process(script, cursor?)Executes a #JS script string and returns its output. Only allowed when the workspace owner's account (or its group) is marked as trusted by…console.assert(condition, message)Throws an error with the given message when a condition is false.setContentDisposition(type, filename)Tells the browser to download and save the returned result to a file with the specified name.htmlToXlsx(filename?, html?)Converts an HTML table to an Excel file (XLSX).htmlToPdf(filename?, html?, usePrintCss?)Converts html to a PDF file using headless Chrome.base64(data)Converts data to base64 encoded string.setMime(mime)Allows user to set the mime type of a response.repairHtml(html)Parses and repairs an HTML string by adding missing end tags, closing quotes, and fixing malformed markup. Returns a valid, well-formed…scaleImage(bytes, width, height, options?)Scales an image byte array to a target size and returns the scaled image as bytes. Supports several scaling modes and lets you preserve or…getConsoleLog()Returns the lines written to the site's console with console.log, console.warn and console.error. The console log is kept in memory on the…write(text)Outputs specified text to page content, same as write in javascript. Note that for API functions the output will not be returned to the…setResultCode(code)Sets the HTTP result code for the response. This function is used to specify the HTTP status code that should be returned to the client.getHeader(name)Reads a header value from the request.setHeader(name, value)Sets a header value in the response.setCookie(name, value, options?)Sets a cookie on the response. Available in API scripts and the site router — pages are rendered once and shared, so they cannot set…getCookie(name)Reads a cookie sent with the request. Available in API scripts and the site router.request()Get information about the current request from the request object.format(value, format)Formats a number or date into a string by given format.Formatting numbersInformation about formatting numbers with the Docly format function.HTML.format(html)Returns specified HTML string formatted as "prettified" indented HTML.JSON.format(json)Outputs specified JSON string to "prettified" indented JSON. To indent while converting a value, JSON.stringify(value, null, 2) does it in…redirect(url)Stops the page and redirects the browser to the specified url. Works in .hash pages and API functions, and is not swallowed by try/finally…JSON.parse(json)Parses a JSON string into an object.JSON.stringify(value, replacer?, space?)Converts a JavaScript object or value to a JSON string. Numbers are written the JavaScript way (3, not 3.0), and object properties that are…console.log(values)Outputs specified text to the site's console log, same as in JavaScript. console.warn and console.error write the same way, but mark the…setCulture(culture)Sets culture to use when formatting dates and numbers.console.warn(values)Writes a warning to the site's console log — the same as console.log, but the line is marked as a warning (Type "warn"). Open the log with…textToHtml(text)Converts plain text to HTML: encodes characters like < and &, turns line breaks ( ) into <br> tags and makes URLs clickable. Several…console.error(values)Writes an error to the site's console log — the same as console.log, but the line is marked as an error (Type "error"). It does not throw…Chr(code, ...)Returns a string made of the characters for the given character codes. Call it as chr(...). Takes any number of codes; a value that is not…sleep(milliseconds)Pauses the script for the given number of milliseconds — for example between retries against an external API. The pause counts toward the…assetUrl(path)Returns a versioned URL for a static asset so the browser fetches a fresh copy after each publish (cache-busting). Typically used in…setExecutionTimeout(timeout)Sets the maximum server-side execution time for the current API function or service. The value is capped at 10 minutes (600000…