Reference sections
Reference › The kitten global
The global kitten object has the following members:
Rendering
kitten.html: Kitten HTML tagged template string with support for Kitten components and JavaScript string interpolation.kitten.css: CSS tagged template.kitten.js: JS tagged template.kitten.markdown: Markdown wrapper.kitten.md: Reference to the MarkdownIt instance used internally by Kitten.kitten.safelyAddUntrustedHtml: Use this method to add untrusted markup to your page safely.kitten.markAsTrusted: Returns a value thatkitten.htmlinserts exactly as written. Only pass it a string you wrote or trust (see Interpolated values).kitten.sanitise: A wrapper around sanitize-html that removes every HTML tag not on the allow list. With the default allowed tags, the result is safe to add as HTML content with thekitten.markAsTrusted()method. It isn’t safe to include directly in a JavaScript attribute such asonclick(or Alpine.js’sx-data,x-init, etc.) as a quotation mark in the value can end the string and open you up to an injection attack. Instead, put it in adata-*attribute and read the value of that data property in your handler (see Interpolated values).kitten.slugify: Slugify a string.kitten.yaml: YAML parser and serialiser.
Pages and components
kitten.Page: KittenPage class.kitten.Component: KittenComponent class.kitten.page: Special page slot names (constants) that can be used as targets of<content for='…'>tags.kitten.pages: Record of all active KittenPage instances, keyed by page ID (UUID).kitten.components: Kitten’s built-in components.kitten.icons: Kitten’s built-in icon set.
Data
kitten.db: The default JSDB database for your app.kitten._db: Kitten’s internal database. Itssettingsproperty contains the redirect tables.kitten.uploads: Uploads sent via<input type='file'>in your pages to aPOSTroute that requires sign-in, which Kitten saves inkitten.paths.APP_UPLOADS_DIRECTORY.kitten.uploadLimits: Limits on the size of a file and the number of files and fields in every request with a body, and on the size of a field, a field name, and a body.kitten.Upload: Represents an uploaded file.kitten.paths: File system paths of important Kitten resources.
The server and the app
kitten.app: The Kitten app.kitten.domain: The domain or Web Number (IP Address) Kitten is running at.kitten.port: The port number Kitten’s running at.kitten.projectIdentifier: The unique identifier for this Kitten site/app, calculated using the base path of the source code as well as the domain and port the server is running on.kitten.package: Represents the currently-installed Kitten package.kitten.appRepository: Represents the git repository of the app that Kitten is currently serving.kitten.automaticUpdates: Schedules and runs automatic updates of both Kitten itself and the app that Kitten is running.kitten.version: Kitten’s version number and related utilities.kitten.deploy: For internal use by Kitten’s web app.kitten.events: Global Kitten event emitter.kitten.requests: A truncated log of the last 25 request URLs for debugging purposes.
Libraries
kitten.libraries: Constants for well-known/supported client-side libraries meant to be referenced in page routes.kitten.WebSocket: Reference toWebSocketclass from ws.
Cryptography
kitten.crypto: Kitten Cryptography API.
Utilities
kitten.utils: Kitten utility functions and properties, includingkitten.utils.secretsMatch.kitten.log: Kitten’s logger.
Introspection
kitten.$tables: The names of the tables in your custom JSDB database (kitten.db).kitten.$showEventsOnTable: Easily listen for events on JSDB tables from the Kitten Interactive Shell (REPL).
Kitten provides special properties and methods that make it easier to use the Kitten Shell (REPL) to interact with and debug your app.
You have the following introspection endpoints on the global kitten object:
$tables: returns a list of the tables available in thekitten.dbdatabase. You can pass any of these values to thekitten.$showEventsOnTable()method (see below).$showEventsOnTable(<nameOfTable:string): Events that occur on the table are logged to the console. This is for debugging use in the Kitten Interactive Shell (REPL) only and does not perform listener cleanup. If you use it in production, it will lead to memory leaks (so don’t) :)
In development, when a new page connects, you will see code in the console that you can copy and paste to get a reference to that page in the REPL.
Once you have a reference to the page or any other KittenComponent instance, you can use the following properties and methods:
$info(): This method will give you an overview of the component, displaying its component hierarchy and its methods. This is the equivalent of calling the$tree()method and accessing the$methodsproperty.$tree(): Displays the component hierarchy starting from the referenced component.$methods: List of this component’s methods.$properties: List of this component’s properties.$children: Displays the names of this component’s direct child components.$componentWithId(): Returns a reference to a component using its short ID (as displayed by the$info()and$tree()methods). (The short ID is the first fragment of a Kitten Component’s UUID and looks a bit like a short git hash.)
If you use WezTerm and you want to quickly copy the page = … line to get a reference to the page using Quick Select Mode, add this to the object you return from your ~/.config/wezterm/wezterm.lua:
quick_select_patterns = {
"^page = .*?$"
},