String Extensions
Methods and getters RenderJS adds to String.prototype: DOM construction from tag-selector strings, element queries, JSON and HTML helpers, and URL shortcuts.
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 |