Documentation

API Reference

RenderJS extends native constructors' .prototype directly (src/prototype/*.ts); nothing is a standalone import. Loading the bundle is enough to make every method below available globally.

String

Source: src/prototype/String.ts

Method / Property Description
"selector".RJS(body) Starts an RJS instance on the matched element; see Core Concepts
"tag.class#id"._(attrs, children) Builds a real DOM element from a tag-selector string (SVG namespace detection, input/textarea type/placeholder parsing, lazyload attribute wiring)
"selector".$ Single matching element (getElementById for #id, otherwise querySelector)
"selector".$all Array of all matching elements ([...querySelectorAll(...)])
"icon-a icon-b"._fa Getter that builds "i.icon-a.icon-b"._() — a Font Awesome <i> element from space-separated class names
"str".$json Safe JSON.parse(this); returns undefined (and logs) on parse failure
"str".$$json true when $json did not fail
"str".$html HTML-escapes , <, >, ", '
"str".copy() Async; writes the string to the clipboard via navigator.clipboard.writeText
"str".$regexp(flags?, force?) Builds a RegExp from the string; force: true escapes regex metacharacters first
"str".$base64(mimeType) Decodes a base64-encoded string into a Blob
"str".$$(filter?) RegExp test, exact-string match, or (no argument) non-empty-after-trim check
"url".$url new URL(this), falling back to new URL(location.origin + this) for relative paths
"url".$queryAll Query string parsed into a plain object (via $url.$queryAll)
"url".$img / $$200(isImg) / $req(body, once) / $query / _history(title) / _query(obj) / __history(title) / __query(obj) / query_(keys) / query__() Forwarded to the equivalent URL method/getter below, applied to this.$url

Element

Source: src/prototype/Element.ts

Method / Property Description
el.length this.children.length
el.$i Index of the element among its parent's children
el.$attributes All attributes as a plain { name: value } object
el._(value) / el.__(value) Append / replace children — strings and numbers become a text node; plain objects are pretty-printed as <br>-joined JSON
el._style(map) / el._data(map) / el._attr(map) Chainable: set multiple style / dataset / attribute key-values from an object
el._class(list) Chainable: add one or more classes (string, comma/space/dot-separated, or array)
el.class_(list) / el.style_(list) / el.data_(list) / el.attr_(list) Chainable: remove classes / clear styles / delete dataset keys / remove attributes
el.$style(key) / el.$data(key) / el.$attr(key) Read a single style property / dataset entry / attribute value
el.class__() Chainable: clears className entirely
el.__class(list) Chainable: replaces the whole class list
el.$$class(list) true only if every class in list is present
el.$$class_(bool, list) Chainable: adds list when bool is falsy, removes it when truthy (or auto-detects current state if bool is omitted)
el.$$data(key, value?) / el.$$attr(key, value?) true if the dataset/attribute value equals value, or is non-empty when value is omitted
el._children(...args) Chainable: appends each argument via _child
el._child(value, before) Chainable: append/insert a child (or array of children) by index or reference Element
el.__child(value) Chainable: replaces children (replaceChildren)
el.$child(value) Query a descendant by a mixed array of selector strings and numeric indices
el.$parent(count) / el.$pre(count) / el.$next(count) Walk count steps up parentElement / previousElementSibling / nextElementSibling
el.$sel(selector) / el.$selAll(selector) querySelector / querySelectorAll guarded against an empty selector
el._click(fn) (and every DOM event name, e.g. _input, _keydown, _touchstart, _drop, ...) Chainable on<event> = fn assignment

Array

Source: src/prototype/Array.ts

Method / Property Description
arr.$sum Sum of a numeric array via reduce
arr.$shuffle In-place Fisher–Yates shuffle; returns this
arr.$map A Map of value → index for every entry
arr._(value, index?) Negative-index-aware insert (splice); appends when index is omitted
arr.$(index) Negative-index-aware read
arr.$i(target) indexOf(target), returning undefined instead of -1
arr.$_(index) Negative-index-aware removal (splice)
arr.$$(target?) true if non-empty (no argument) or if target is present
arr.$req(body) Joins the array as /-separated URL path segments, then calls $req on the resulting path

Object

Source: src/prototype/Object.ts (extends Object.prototype, so these apply to plain objects)

Method / Property Description
obj.length Object.keys(this).length
obj.$keys / obj.$values Object.keys(this) / Object.values(this)
obj.$map Own enumerable entries as a Map
obj.forEach(cb) Array-like iteration: cb(key, value) over own enumerable properties
obj._(key, value, replace = true) Conditional setter — only overwrites an existing key when replace is true
obj.$$(key?) hasOwnProperty(key) if key given, else this.length > 0

URL

Source: src/prototype/URL.ts

Method / Property Description
url.$queryAll Query string parsed into a plain object
url.$image Promise resolving a preloaded Image for the URL
url.$$200(isImg = false) Fetches the URL; if the response is an image, converts it to an object-URL blob ({ src, img }) unless it's SVG and isImg is falsy
url.$req(body, once = false) Fetch wrapper: JSON or FormData body (via body.json/body.files/body.tag), custom header/credentials, request de-duplication through a shared Map keyed by URL, automatic JSON/text response parsing, rejects with response text on 4xx/5xx
url.$$query(key) searchParams.get(key)
url._history(title?) pushState to this URL, records it in the in-memory history stack, optionally sets document.title
url._query(obj) Returns a new URL with obj's keys merged into the existing query string
url.__history(title?) replaceState to this URL (also updates the history stack)
url.__query(obj) Returns a new URL with the query string replaced entirely by obj
url.query_(keys) Returns a new URL with the given key (or array of keys) removed from the query string
url.query__() Returns a new URL with the query string cleared

window

Source: src/prototype/window.ts

Method Description
_Listener(target?) With no argument, enables both the lazyload and SVG observers. With an argument, target.svg gates the lazyload observer and target.lazyload gates the SVG observer (see Listener System for the observer internals)
$file(file) Wraps a File/Blob in a FileReader.readAsDataURL, resolving with the load event
$cookie(key) Reads and URI-decodes a cookie; JSON-parses the value automatically if it looks like JSON
_cookie(key, body, expire = 3600) Writes a cookie (expire in seconds); objects are JSON.stringify'd first
$(selector) Module-level shortcut for "selector".$
$all(selector) Module-level shortcut for "selector".$all
_child(value, before) / __child(value) Append to / replace the children of document.body

Date

Source: src/prototype/Date.ts

Method / Property Description
date.$y / $yy / $yyyy Year (raw, 2-digit, 4-digit)
date.$M / $MM Month, 1-indexed (raw, zero-padded)
date.$D / $DD Day of month (raw, zero-padded)
date.$d / $dd / $ddd / $dddd Day of week: index, then localized name at increasing length (English abbreviations or 星期X in zh locales, detected via navigator.language)
date.$H / $HH 24-hour hour (raw, zero-padded)
date.$h / $hh 12-hour hour (raw, zero-padded)
date.$a / $A am/pm (lower/upper case)
date.$m / $mm Minutes (raw, zero-padded)
date.$s / $ss Seconds (raw, zero-padded)
date.$S / $SS / $SSS Milliseconds, sliced to 1/2/3 digits
date.$timestamp Unix timestamp in seconds
date.$gone Humanized relative time ("3 days" / "3天", "Coming in..." / "還有...", "recent" / "剛剛" for < 1 minute), localized by navigator.language
date.$format(format = "yyyy/MM/DD (ddd) HH:mm:ss") Token-based formatter; supports Y/M/D/H/h/m/s/S/A/a/d tokens at the repeat-counts shown above
date.$date(body?) Given { start } / { end } / { pre: { start } } / { pre: { end } }, returns the first/last day of the current or previous month; otherwise new Date()

Number

Source: src/prototype/Number.ts

Method / Property Description
n.$uniKey Random string of length n, drawn from a 52-character alphabet, deduplicated against previously generated keys for the process lifetime
n.$ASCII String.fromCharCode(n)
n.$date Treats n as a Unix timestamp (seconds) and returns the corresponding Date
n.$y / $M / $D / $d / $H / $h / $a / $A / $m / $s / $S (and their padded/repeated variants) / $gone Forwarded to n.$date's equivalent Date getter
n.$format(format) Forwarded to n.$date.$format(format)

Map

Source: src/prototype/Map.ts

Method / Property Description
map.length this.size
map.$keys / map.$values Iterators over keys / values
map.$json Object.fromEntries(this)
map._(key, value?) Chainable set(key, value)
map.$(key?) get(key)
map.$_(key?) Chainable delete(key)
map.$$(key?) has(key) if given, else this.size > 0

Image

Source: src/prototype/Image.ts

Method / Property Description
img.copy(mime = "image/jpeg") Async; copies the image to the clipboard via ClipboardItem
img.download(mime = "image/jpeg", filename?) Triggers a browser download using an object-URL <a download> link
img.$base64(mime, size?) Re-encodes via an offscreen <canvas>; size (if smaller than the longest side) proportionally downscales the image first
img.$blob(mime, size?) $base64 decoded back into a Blob

HTMLElement

Source: src/prototype/HTMLElement.ts

Method / Property Description
el._display(value) Chainable style.display = value
el.width(v) / height(v) / paddingTop(v) / paddingLeft(v) / paddingBottom(v) / paddingRight(v) / marginTop(v) / marginLeft(v) / marginBottom(v) / marginRight(v) Chainable numeric style setters; a bare number/numeric-string gets px appended automatically
el.padding(top, right?, bottom?, left?) / el.margin(...) CSS-shorthand-style chainable setter (1–4 args, same fallback rules as the padding/margin CSS property)
el.scrollToX(value, animation?) / el.scrollToY(value, animation?) Scrolls to an absolute offset (clamped to content bounds), optionally with behavior: "smooth"
el.scrollToT(animation?) / el.scrollToB(animation?) Scroll to the top / bottom edge
el.scrollToL(animation?) / el.scrollToR(animation?) Scroll to the left / right edge

File

Source: src/prototype/File.ts

Method Description
file.$image(isVideo = false) Returns a Promise<HTMLImageElement>. For images, decodes via FileReader.readAsDataURL. For video files (isVideo: true), loads the file into an offscreen <video>, seeks to the first decoded frame, and captures it onto a <canvas> to produce a JPEG thumbnail

HTMLVideoElement

Source: src/prototype/HTMLVideoElement.ts

Method Description
video._config({ preload, loop, muted, controls, playsinline, download, remote }) Chainable one-call setup: always disables the native download/remote-playback UI via controlsList, then applies each provided flag (download: false/remote: false re-add the corresponding controlsList token)

HTMLFormElement

Source: src/prototype/HTMLFormElement.ts

Method / Property Description
form.$map Form fields as a Map (via an internal FormData wrapper)
form.$json Form fields as a plain object

HTMLLinkElement

Source: src/prototype/HTMLLinkElement.ts

Method Description
a._go(href?) Chainable: sets href (if given) and navigates in the current tab (target = "_self")
a._open(href?) Chainable: sets href (if given) and navigates in a new tab (target = "_blank")

FormData

Source: src/prototype/FormData.ts

Method / Property Description
formData.$map Entries as a Map
formData.$json Entries as a plain object

DocumentFragment

Source: src/prototype/DocumentFragment.ts

Method / Property Description
fragment.innerHTML Serializes the fragment's contents via a detached <div>
fragment.length this.children.length
fragment._children(...args) Appends each argument as a child
fragment._child(value) Appends a value (or array of values); strings/numbers become text nodes
中文