Skip to main content
Home
This release is 4 versions behind 0.1.15 — the latest version of @classic/js. Jump to latest

@classic/js@0.1.11
Built and signed on GitHub Actions

Works with
This package works with DenoIt is unknown whether this package works with Cloudflare Workers, Node.js, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
JSR Score94%
Published10 months ago (0.1.11)

Ad hoc (client) JavaScript from typed (server) code

@classic/js - Page specific JS from any backend

JSR

Custom elements/web components scope reusable logic and style. On the other hand, @classic/js offers a way to send dynamic arbitrary code in web pages to fully control native and custom elements.

const foo = "42";
const jsParsedFoo = js<number>`parseInt(${foo})`; // Smart interpolation will result in `parseInt("42")`
await js.eval(jsParsedFoo) === 42;

References are tracked and transcribed into generated JS, so it is minified by design:

const lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
const loremReference = js<string>`${lorem}`;
await js.eval(js`${lorem} === ${loremReference}`) === true;
// ^ `lorem` is referenced twice: generated JS will declare it as a variable
Built and signed on
GitHub Actions

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@classic/js

Import symbol

import * as js from "@classic/js";
or

Import directly with a jsr specifier

import * as js from "jsr:@classic/js";

Add Package

pnpm i jsr:@classic/js
or (using pnpm 10.8 or older)
pnpm dlx jsr add @classic/js

Import symbol

import * as js from "@classic/js";

Add Package

yarn add jsr:@classic/js
or (using Yarn 4.8 or older)
yarn dlx jsr add @classic/js

Import symbol

import * as js from "@classic/js";

Add Package

vlt install jsr:@classic/js

Import symbol

import * as js from "@classic/js";

Add Package

npx jsr add @classic/js

Import symbol

import * as js from "@classic/js";

Add Package

bunx jsr add @classic/js

Import symbol

import * as js from "@classic/js";