-
chomp(s: string): string
Perl's
chomp($x)mutates$xin place, stripping exactly one trailing"\n"(Perl's default$/record separator — not"\r\n"). JS can't mutate a caller's local binding through a function call, so converted code must reassign the result itself:x = legacyCompat.chomp(x), mirroringchomp $x;'s own mutating spirit as closely as a pure function can. -
fileparse(): [string, string, string]path: string,suffixPattern?: unknown
File::Basename::fileparse($path, $suffix_pattern)— every real call site in the legacy plugin corpus passes the same "match a trailing dot plus any run of non-dot characters" suffix pattern (i.e. "the last extension"), so the second argument is accepted but ignored rather than genuinely interpreting an arbitrary suffix pattern. Returns[name-without-extension, directory-with-trailing-slash, extension-with-leading-dot], matching Perl's own return order. -
getLogger(): LegacyLoggername: string,category: string
get_logger($name, $category)— seeLegacyLogger's own docs for exactly what's covered. -
getVersion(): { version: string; homepage: string; }
LANraragi::Utils::Generic::get_version— legacy reads this straight out of its ownpackage.json(version/homepagefields) once and caches it; this returns the equivalent static values for this project instead of trying to read a Rust crate'sCargo.tomlfrom within the Deno sandbox. Update these two literals ifCargo.toml's[workspace.package]version/repositoryever changes. -
htmlUnescape(s: string): string
Mojo::Util::html_unescape— decodes HTML entities (named:&/</"/etc., and numeric:'/'). No native JS equivalent outside a real DOM (atextareaelement's.valuetrick, unavailable in this Deno sandbox — there's nodocument), so reimplemented directly against the HTML5 entity table's most common names rather than pulling in a full HTML entity library for what the legacy plugin corpus only ever uses on scraped titles/summaries (a handful of the same few entities in practice). -
parseHtml(): LegacyDomNodemarkup: string,xml?: boolean
Mojo::DOM->new(html)/Mojo::DOM->new->xml(1)->parse(xml)— parses markup and returns its root node.xmltoggles case-sensitive tag matching (real XML/custom elements like<Genre>in a ComicInfo.xml file) vs HTML's traditionally case-insensitive tag names; seeLegacyDomNode's own docs for what's covered. -
redis_decode(s: string): string
LANraragi::Utils::Redis::redis_decode— legacy re-decodes a value read back from Redis as UTF-8, since Perl's own Redis client hands back raw bytes. Deno's Redis client (and every string this dispatcher otherwise touches) is already a proper UTF-8 JS string by the time a plugin sees it, so this is a pure pass-through. -
refType(x: unknown): string
Perl's
ref($x)builtin — returns"HASH"/"ARRAY"for a hashref/arrayref, or""for anything else (a plain scalar,undef, etc.), matching Perl's own string-truthiness rule closely enough thatref($x)used as a bare boolean condition (return if ref $x;) works unmodified once translated. Only hashref/arrayref detection — real Perlref()also recognizesCODE/SCALAR/blessed-object-class-name, none of which the legacy plugin corpus's own use ofref()ever tests for. -
reverse<T>(list: readonly T[]): T[]
Perl's
reverse(@list)returns a new list; JS'sArray.prototype.reversemutates its receiver in place. Spreads into a fresh array first so converted code doesn't pick up a mutation side effect the original Perl never had. -
sleep(seconds: number): Promise<void>
Perl's
sleep($seconds)blocks synchronously; JS has no synchronous sleep, so this is asetTimeout-backedPromiseinstead — every call site mustawaitit (the converter's ownsleepmapping inrender.rsalways emits theawait, forcing the enclosing functionasyncthe same way an awaited->get()/->post()Mojo call already does). -
sprintf(): stringformat: string,...args: unknown[]
A minimal
sprintfcovering the format-spec subset actually used across the legacy plugin corpus (%s,%d,%fwith optional width/precision) — not a full reimplementation of Perl's considerably largersprintfgrammar. -
trim(s: string | null | undefined): string
LANraragi::Utils::String::trim— strips leading/trailing whitespace, returning""fornull/undefinedinstead of throwing (unlike JS's ownString.prototype.trim, which requires a real string receiver). -
userAgent(): LegacyUserAgent
Mojo::UserAgent->new— seeLegacyUserAgent's own docs for exactly what's covered. Every plugin using this must still declare its own real target host(s) indeclared_permissions(constitution Principle IV); this shim runs inside that same already-permission-scoped process, so it's bound by whatever--allow-netgrant the plugin itself was started with, same as a plugin callingfetch()directly would be.
A plugin-authored, structured error — throw this (instead of a plain throw new Error(...))
to report {error_code, data} through an exception rather than a return {error}. error_code
doubles as an i18n lookup key (see crates/lanrurugi-plugin/dispatcher/plugin-sdk.ts's
PluginError for the full field-meaning docs — this class's fields mirror that interface
exactly). The dispatcher's own catch (dispatcher.ts's handleRequest) uses real
instanceof against this exact class to extract error_code/data for the Rust host.
Usage
import * as mod from "plugins/legacy-globals.d.ts";