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

saturjs

v1.0.5

Published

A lightweight web library that combines the best of server-side rendering and client-side state management.

Downloads

357

Readme

npm version license issues

🚀 Overview

SaturJs is a lightweight, server-side rendering (SSR) library designed for building dynamic, fast-loading web applications with ease. It empowers developers to manage application state, handle components, and optimize rendering while maintaining full control over their architecture.

✨ Features

  • 🖥️ Server-Side Rendering (SSR): Pre-render HTML on the server for improved performance and SEO.
  • 🔄 Reactive State Management: Utilize a simple proxy-based state system to track and react to data changes.
  • 🧩 Component-based Architecture: Organize your UI with reusable, modular components.
  • ⚡ Efficient DOM Updates: Built-in DOM diffing algorithm for optimized rendering.

📦 Quick Start

# Clone the starter template
git clone https://github.com/madhanmaaz/saturjs-quick-start
cd saturjs-quick-start

# Install dependencies
npm install

# Start development server
npm run dev

🚀 Here’s a simple example to get you started:

// server.js
const { setup, Router, renderPage } = require("saturjs")
const router = Router()

router.get("/", renderPage("index"))

module.exports = setup({
    appRouter: router
})

Creating a Page View: src/index.html

<script server>
    // server code
    const title = "page title"

    async function defServer(req, res, next) {

        if(req.query.id == "2") {
            res.send("user not found.")
        }

        return {
            id: req.query.id
        }
    }
</script>

<!DOCTYPE html>
<html lang="en">
<head>
    <title>{{ title }}</title>
</head>
<body>
    <h1>Welcome to SaturJs</h1>
    <p>User ID: {{ id }}</p>

    <!-- import component & render component -->
    <import src="./Counter.html" />
    {{ $$.Counter() }}
</body>
</html>

Creating a Component

  • You can create a component using the following structure: src/Counter.html the component must starts with caps.
<template>
    <button onclick="handler">Count {{ count }}</button>
</template>

<script>
    const state = defProxy({
        count: 0
    })

    defEvents({
        handler() {
            state.count++
        }
    })
</script>

🧩 Template Syntax

<!-- Basic Expressions -->
{{ 1 + 1 }}             <!-- Outputs: 2 -->
{{ username }}          <!-- Variable interpolation -->
{{- html }}             <!-- Unescaped HTML -->
{{# comments }}         <!-- Not visible in output -->

<!-- Conditionals -->
{{ if(condition) }}
    <p>True branch</p>
{{ else if(otherCondition) }}
    <p>Else if branch</p>
{{ else }}
    <p>Else branch</p>
{{/}}

<!-- Loops array -->
{{ for(value, index in array) }}
    <p>{{ index }}: {{ value }}</p>
{{/}}

<!-- Loops object -->
{{ for(value, key in object) }}
<p>{{ key }} - {{ value }}</p>
{{/}}

<!-- Component Usage -->
{{ $$.Counter({ count: 0 }) }}
{{ $$["Counter"]({ count: 0 }) }}

📘 Component Structure

<template>
    <!-- Root element for the component; must contain only one root element -->
    <div>
        <!-- Component-specific event -->
        <button onclick="handler">Count {{ count }}</button>

        <!-- Access events from another component -->
        <button onclick="Settings.open">Open Settings</button>

        <!-- Pass arguments to a method -->
        <button onclick="deleteNotes(id, 1, 2)">Delete Notes</button>
    </div>
</template>

<script>
    // Import libraries; these will automatically be bundled
    const uuid = require("uuid");
    const axios = require("axios");

    // Define props that come from a parent component
    const props = defProps({
        title: String
    });

    // `defProxy` manages the state for this component.
    // It stores all data relevant to this component.
    const state = defProxy({
        count: 0,
        data: [],
        users: []
    });

    // `defEvents` defines component-specific events.
    // Events can be accessed from other components using `thisComponent.eventName`.
    defEvents({
        handler() {
            state.count++;
        },
        openPanel() {
            // Use `useSignal` to communicate with other components
            useSignal("Panel").open = true;
        }
    });

    // `defMethods` defines functions accessible within the template.
    defMethods({
        alter(value) {
            return `${value}.`;
        }
    });

    // `defWatch` monitors state changes; triggers when `count` changes
    defWatch({
        count(newValue, oldValue) {
            console.log("Count changed from", oldValue, "to", newValue);
        }
    });

    // Alert outside of `defLoad` throw an error
    // alert("loaded"); // incorrect

    // `defLoad` runs when the component is ready in the client
    defLoad(() => {
        alert("Component loaded"); // correct usage
    });

    // `defError` handles errors within the component
    defError((error) => {
        console.log("Error encountered:", error);
    });
</script>