npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

oxidizer

v3.3.4

Published

A lightweight reactive web development library based on web components. No compiler required.

Downloads

127

Readme

Oxidizer v3

An incredibly lightweight and easy to use Web Development library that is reactive and based upon Web Components.

Installation

npm install oxidizer

Usage

Creating HTML Elements

Every HTML Element has a correspond factory function that can be used to create them. These functions return an HTMLElement instance

import {DIV, H1, H3} from "oxidizer"

const simpleHeader = DIV(
    {id: 'simple-header', className: 'col center'}, // Attributes
    H1('Heading 1'), // Children
    H3('Sub Heading')
);

document.body.append(simpleHeader);

console.log(simpleHeader instanceof HTMLDivElement) // true

Elements can be created without attributes, or without children, or without both.

const div = DIV();
const div = DIV({id: 'my-div'})
const div = DIV(
    P('Paragraph 1'),
    P('Paragraph 2')
)

Props & Reactivity

These element factory functions can also take props as an input, which can be used to dynamically update their attributes and contents.

Creating Props

props can be created using the createProps method.

// SIMPLE COUNTER APP EXAMPLE

import {createProps, BUTTON, DIV, H1} from "oxidizer";

const props = createProps({count: 0});

const counter = DIV(props, p => [
    {id: 'simple-counter'},
    H1(`Count: ${p.count}`),
    BUTTON(
        {onclick: () => p.count += 1},
        'Increment Count'
    )
]);

document.body.append(counter);
  • props can be altered by simply setting the value on it's property
  • altering props triggers a rerender via the function provided in the element factory
  • props will only rerender the elements in which they have been passed.
// ANOTHER EXAMPLE

import {createProps, DIV, INPUT, P} from "oxidizer";

const props = createProps({
    firstName: "John",
    lastName: "Doe"
});

const nameInput = DIV(props, p => [
    {className: 'name-card'},
    DIV({style: {display: 'flex'}},
        P(p.firstName),
        P(p.lastName)
    ),
    DIV({style: 'display:flex'}, 
        INPUT({
            placeholder: 'First Name', 
            value: p.firstName,
            onchange(event){
                p.firstName = (event.target as HTMLInputElement).value;
            },
        }),
        INPUT({
            placeholder: 'Last Name', 
            value: p.lastName,
            onchange(event){
                p.lastName = (event.target as HTMLInputElement).value;
            },
        }),
    )
])

document.body.append(nameInput);

props can be easily mixed together

import { createProps, DIV, BUTTON, P } from "oxidizer";

const styleProps = createProps({color:'red'});

function WeirdElement () {
    const props = createProps({ count: 1 });
    return (
        DIV(props, p => [
            { id: 'test-element'}, 
            P(styleProps, sp => [
                {
                    style: `color: ${sp.color};`, 
                    onclick: () => {
                        sp.color = 'blue';
                    }
                },
                `Color: ${sp.color}`,
                `Count: ${p.count}`
            ]),
            BUTTON({ onclick: () => p.count += 1 }, [
                "Increment"
            ])
        ])
    )
}

document.body.append(
    WeirdElement()
)

Creating Effects

Effects are functions that will we triggered when a specified props property has been altered.

  • effect callbacks will be ran immediately upon creation
  • the return value of the callback will be applied to the props
import { createEffect, createProps, BUTTON, DIV, H1, H6, H2 } from "oxidizer";

type AppProps = {
    theme: 'light' | 'dark',
    user: undefined | {username: string}
}

const props = createProps<AppProps>({
    theme: 'dark',
    user: undefined
}, [
    // make sure light theme is appropriate
    createEffect('theme', (p) => {
        const date = new Date();
        const isNight = date.getHours() < 6 || date.getHours() > 18;
        if (p.theme === 'light' && isNight){
            return {theme: 'dark'}
        }
    }),
    // keep the user perpetually signed in
    createEffect(['user', /* more deps here if you want*/], (p) => {
        if (!p.user) {
            setTimeout(() => {
                p.user = { username: "snakgoat" }
            }, 3000)
        }
    })
]);

export default function HomePage () {
    return (
        DIV({ id: 'app' },
            DIV(props, p => [
                { id: 'home-page' },
                !p.user ? (
                    H2('Loading Information...')
                ) : (
                    H1(`Welcome ${p.user.username}`)
                ),
                BUTTON(
                    {onclick: () => p.theme = 'light'}, 
                    "Change Theme"
                ),
                BUTTON(
                    {onclick: () => p.user = undefined}, 
                    "Sign Out"
                )
            ]),
            H6('Come Again!')
        )
    )
}

Web Components

Web Components can be simply integrated into your app via the createComponent method.

  • createComponent returns a factory function that works identically to the intrinsic HTMLElement factory functions.
  • (optional) You can use the Component interface to help with WebComponent typing.
import { createComponent, Component, H1, P } from "oxidizer";

const TestApp = createComponent(
    'test-app',
    class extends HTMLElement implements Component {
        connectedCallback(): void {
            this.style.color = "red";
            this.style.background = "blue";
        }
    }
);

document.body.append(
    TestApp(
        {id: "root"}, 
        H1('Hello!'),
        P('How do you like my app?')
    )
)

export default TestApp;

Helpful Libraries

create-oxidizer-app

A useful package for bootstrapping oxidizer apps

oxidizer-router

A router component & state management library