New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

jay-comp

Package Overview
Dependencies
Maintainers
0
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jay-comp

Jay is a lean and lightweight framework that puts the control and creativity of traditional web development with modular and scalable component architecture.

latest
Source
npmnpm
Version
2.1.5
Version published
Weekly downloads
1
Maintainers
0
Weekly downloads
 
Created
Source

Jay Components

npm version

A lightweight, modular web-component library built in TypeScript. Jay manages rendering, styling, HTTP requests, and component lifecycle so you can focus on HTML, CSS, and behavior.


Table of Contents


Installation

Via npm

npm install --save-dev jay-comp webpack webpack-cli

Via Git

git clone https://github.com/Taghunter98/jay-comps.git
cd jay-comps
npm install
npx tsc

Bundling with Webpack

Ensure your package.json includes:

{
  "type": "module",
}

index.js

import { Comp } from "jay-comp";
import "./helloworld.js";  // Your custom components

webpack.config.cjs

const path = require("path");

module.exports = {
  entry: "./index.js",
  mode: "development",
  output: {
    filename: "bundle.js",
    path: path.resolve(__dirname, "dist")
  }
};

After building:

npx webpack

Include in your HTML:

<script type="module" src="./dist/bundle.js"></script>

A Minimal Example

helloworld.js

import { Comp } from "jay-comp";

class HelloWorld extends Comp {
    greeting_;
    
    beforeRender() {
        this.greeting_ = "Hello Jay!";
    }
    
    createHTML() {
        return `<h1 class="heading">${this.greeting_}</h1>`;
    }
    
    createCSS() {
        return {
            class: "heading",
            colour: "#142985",
            padding: [20, 40],
            fontSizePt: 48,
            media: {
                maxWidthBp: 600,
                fontSizePt: 24,
                padding: [8, 16]
            }
        };
    }

    afterRender() {
        this.query("h1")
            .addEventListener("click", () => alert("This is my first Jay Component!"));
    }

    static { Comp.register(this); }
}

index.js

import { Comp } from "jay-comp";
import "./helloworld.js";

index.html

<!DOCTYPE html>
<html>
  <body>
    <comp-hello-world></comp-hello-world>
    <script type="module" src="./dist/bundle.js"></script>
  </body>
</html>

Open index.html to see your component in action.


Core API

The Comp Class

Comp is Jay’s base class. It handles:

  • Shadow DOM setup
  • Template injection via render()
  • Scoped CSS through createCSS()
  • Lifecycle hooks (createHTML(), createCSS(), hook())
  • HTTP requests (request(), submitForm())

Lifecycle Flow

  • Constructor

    • Attaches an open shadow root
    • Calls render()
  • render()

    • Injects output of createHTML() and createCSS() into shadow root
    • Calls hook()
  • hook()

    • User-defined for wiring up logic (events, data fetch, etc.)

Overrideable Methods

createHTML(): string

Define your component’s inner markup:

createHTML() {
  return `<div class="container">${this.content_}</div>`;
}

createCSS(): string

Define scoped styles via the CSS compiler:

createCSS() {
  return this.css({
    class:         "container",
    display:       "flex",
    padding:       [10, 15],
    media: {
      maxWidthBp: 600,
      flexDirction: "column"
    }
  });
}

beforeRender(): void

Run before-render logic:

beforeRender() {
  if (!this.greeting_) this.greeting_ = "Hello World!"
}

afterRender(): void

Run post-render logic:

afterRender() {
  this.shadowRoot
    .querySelector(".container")
    .addEventListener("click", () => console.log("Clicked!"));
}

static register(componentClass): void

Registers the Comp as a custom element.
Class names convert to kebab-case and prefix comp-:

static { Comp.register(this); }
// MyButtonComp -> <comp-my-button-comp>

Helper Methods

update(html?: string, css?: string): void

Re-render markup and/or styles at runtime:

set title(text) {
  this.title_ = text;
  this.update();  // Re-runs createHTML/createCSS
}

getById(id: string): HTMLElement | null

Returns an element from the Shadow DOM by its ID. Automatically strips a leading # if present.

// Lookup without '#'
const btn = this.getById<HTMLButtonElement>('submitBtn');
btn?.addEventListener('click', () => console.log('Clicked'));

// Lookup with '#'
const input = this.getById<HTMLInputElement>('#usernameInput');
if (input) input.value = 'alice';

query(sel: string): Element | null

Selects the first element matching a given CSS selector.

// Select an active list item
const item = this.query<HTMLLIElement>('ul > li.active');

// Select an input by attribute
const email = this.query<HTMLInputElement>('input[name="email"]');

queryAll(sel: string): NodeListOf<Element>

Selects all elements matching a given CSS selector. Returns a live NodeList, even if no matches are found.

// Style all active items
const items = this.queryAll<HTMLLIElement>('ul > li.active');
items.forEach(li => li.style.color = 'red');

// Disable all buttons in the shadow DOM
const buttons = this.queryAll<HTMLButtonElement>('button');
buttons.forEach(btn => btn.disabled = true);

css(config: CSSConfig): string

Compiles a single config object into scoped CSS. Supports a wide range of suffix-based operators:

Rules

  • CamelCase -> kebab-case
  • UK spellings (colour, centre, behaviour)
  • Media queries must have a Bp keyword for defining breakpoints.

Examples

A basic box layout:

const config1 = {
  class:         "box",
  display:       "flex",
  flexDirection: "column",
  padding:       10,
  opacity:       0.8
};
console.log(this.css(config1));

Using arrays, percent, and media:

const config2 = {
  class:        "container",
  colour:       "white",
  border:       ["solid", 2, "black"],
  borderRadius: [4, 8],
  widthPercent: 75,
  media: {
    maxWidthBp: 600,
    padding:    [16, 32]
  }
};
console.log(this.css(config2));

Pseudo-class:

const config3 = {
  class:          "btn",
  backgroundVar:  "blue100",
  pseudoClass:    "hover"
};
console.log(this.css(config3));

CSSConfig Operator Reference

OperatorCSS OutputExample ConfigCompiled CSS Snippet
(default number)px appended (except 0)margin: 16margin: 16px;
Percent%widthPercent: 50width: 50%;
Varvar(--…)colorVar: "blue100"color: var(--blue100);
Urlurl(...)backgroundImageUrl: "hero.jpg"background-image: url(hero.jpg);
Calccalc(...)widthCalc: "100% - 32px"width: calc(100% - 32px);
Em / Remem / rempaddingEm: 1.5, marginRem: 2padding: 1.5em;, margin: 2rem;
Vw / Vh / Vmin / Vmaxviewport unitsheightVh: 80, gapVmax: 2height: 80vh;, gap: 2vmax;
Ch / Excharacter-based unitstextIndentCh: 2, fontSizeEx: 1text-indent: 2ch;, font-size: 1ex;
Pt / Pcprint-based unitsfontSizePt: 12font-size: 12pt;
In / Cm / Mm / Qabsolute/metric lengthswidthCm: 10, borderQ: 4width: 10cm;, border: 4q;
Frgrid fractiongridTemplateColumnsFr: [1,2]grid-template-columns: 1fr 2fr;
S / Mstime unitstransitionDurationS: 0.3, delayMs: 200transition-duration: 0.3s;, delay: 200ms;
Deg / Rad / Grad / Turnangle unitsrotateDeg: 45, skewRad: 0.5transform: rotate(45deg);, skew(0.5rad);
Dpi / Dpcm / Dppxresolution unitsresolutionDpi: 300resolution: 300dpi;
Hz / KHzfrequencyaudioRateHz: 60, signalKHz: 2.4audio-rate: 60Hz;, signal: 2.4kHz;
Raw strings / Keywordspassed through as-isdisplay: "flex"display: flex;
Array shorthandspace-separated valuespadding: [8,16]padding: 8px 16px;
pseudoClasspseudo-selector suffixpseudoClass: "hover".my-class:hover { … }
Breakpoint operator (Bp suffix)media query headermedia: { maxWidthBp: 600 }@media (max-width: 600px) { … }

HTTP Requests API

request<T>(url: string, method: "GET"|"POST", data?: object): Promise<ApiResponse<T>>

Perform JSON fetch with error handling.

// GET
const usersResp = await this.request<User[]>("/api/users", "GET");
if (usersResp.ok) {
    console.log("Got users:", usersResp.data);
} else {
   console.error("Fetch users failed:", usersResp.status, usersResp.error);
}

// POST
const loginResp = await this.request<{ token: string }>("/api/login", "POST",{ user: "alice", pass: "s3cret" });

if (loginResp.ok) {
   console.log("JWT =", loginResp.data.token);
} else {
   console.error("Login error:", loginResp.status, loginResp.error);
}

submitForm<T>(url: string, data: HTMLFormElement|FormData|object): Promise<ApiResponse<T>>

Send multipart/form-data for uploads.

// 1) HTMLFormElement
const form = document.querySelector("form#profile")!;
const res1 = await this.submitForm<{ success: boolean }>(
  "/api/profile", form
);

// 2) FormData
const fd = new FormData();
fd.append("avatar", fileInput.files[0]);
const res2 = await this.submitForm<{ url: string }>(
  "/api/upload", fd
);

// 3) Plain object
const data = { name: "Alice", age: 30, newsletter: true };
const res3 = await this.submitForm<{ status: "ok" }>(
  "/api/subscribe", data
);

Contributing & License

Jay is licensed under the Apache 2.0 License. Contributions are welcome!

  • Fork the repo
  • Create a feature branch
  • Commit your changes
  • Open a Pull Request

For issues or feedback, please open an issue or email the maintainer.

Keywords

framework

FAQs

Package last updated on 05 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts