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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@uniweb/core

v0.5.6

Published

Core classes for the Uniweb platform - Uniweb, Website, Page, Block

Downloads

6,337

Readme

@uniweb/core

Core classes for the Uniweb Component Web Platform.

Overview

This package provides the foundational classes that power Uniweb sites. It's a pure JavaScript library with no React dependencies, designed to be shared between the runtime and foundations.

Installation

npm install @uniweb/core

Usage

import { createUniweb, getUniweb } from '@uniweb/core'

// Create the singleton instance (typically done by @uniweb/runtime)
const uniweb = createUniweb(siteConfig)

// Access the singleton from anywhere
const uniweb = getUniweb()

// Work with the active website
const website = uniweb.activeWebsite
const page = website.getPage('/about')
const language = website.getLanguage()

API

Factory Functions

| Function | Description | |----------|-------------| | createUniweb(config) | Create and register the global Uniweb instance | | getUniweb() | Get the current Uniweb instance |

Classes

Uniweb

The main runtime instance, available as globalThis.uniweb.

uniweb.getComponent(name)     // Get component from foundation
uniweb.listComponents()       // List available components
uniweb.activeWebsite          // Current website instance
uniweb.setFoundation(module)  // Set the foundation module

Website

Manages pages, theme, and localization.

// Page navigation
website.getPage(route)        // Get page by route
website.setActivePage(route)  // Navigate to page
website.activePage            // Current active page
website.pages                 // All pages
website.pageRoutes            // Array of route strings

// Page Hierarchy API (for navbars, footers, sitemaps)
website.getPageHierarchy(options)  // Get pages for navigation
website.getHeaderPages()           // Convenience: pages for header nav
website.getFooterPages()           // Convenience: pages for footer nav
website.getAllPages()              // Get flat list of all pages

// Locale API
website.getLocales()          // Get all locales: [{code, label, isDefault}]
website.getActiveLocale()     // Get current locale code
website.getDefaultLocale()    // Get default locale code
website.hasMultipleLocales()  // Check if site has multiple locales
website.getLocaleUrl(code, route)  // Build URL for a locale
website.setActiveLocale(code) // Set active locale
website.getLocale(code)       // Get locale info by code

// Content localization (for multilingual values)
website.localize(value)       // Localize {en: "Hello", es: "Hola"} to active lang
website.makeHref(href)        // Transform href for routing

// Deprecated (use Locale API instead)
website.getLanguage()         // Use getActiveLocale()
website.getLanguages()        // Use getLocales()

Page Hierarchy API

The getPageHierarchy() method returns pages filtered and formatted for navigation:

// Get pages for header navigation
const headerPages = website.getPageHierarchy({ for: 'header' })
// Returns: [{ id, route, title, label, description, order, hasContent, children }]

// Get flat list of all pages (for sitemaps)
const allPages = website.getPageHierarchy({ nested: false, includeHidden: true })

// Custom filtering and sorting
const topLevel = website.getPageHierarchy({
  filter: (page) => page.order < 10,
  sort: (a, b) => a.title.localeCompare(b.title)
})

Options:

  • nested (default: true) - Return with nested children or flat list
  • for - Filter for 'header', 'footer', or undefined (all)
  • includeHidden (default: false) - Include hidden pages
  • filter - Custom filter function: (page) => boolean
  • sort - Custom sort function: (a, b) => number

Page

Represents a page with its sections.

// Basic properties
page.route                    // Page route path
page.title                    // Page title
page.description              // Page description
page.label                    // Short navigation label (or null)
page.order                    // Sort order
page.children                 // Child pages (for nested hierarchy)
page.website                  // Back-reference to parent Website

// Navigation visibility
page.hidden                   // Hidden from all navigation
page.hideInHeader             // Hidden from header nav only
page.hideInFooter             // Hidden from footer nav only
page.isHidden()               // Check if hidden from navigation
page.showInHeader()           // Should appear in header nav?
page.showInFooter()           // Should appear in footer nav?
page.getLabel()               // Get navigation label (falls back to title)

// Layout options (per-page overrides)
page.layout.header            // Show header on this page?
page.layout.footer            // Show footer on this page?
page.layout.leftPanel         // Show left panel?
page.layout.rightPanel        // Show right panel?
page.hasHeader()              // Convenience: page.layout.header
page.hasFooter()              // Convenience: page.layout.footer
page.hasLeftPanel()           // Convenience: page.layout.leftPanel
page.hasRightPanel()          // Convenience: page.layout.rightPanel

// Content
page.getPageBlocks()          // Get header + body + footer blocks
page.getBodyBlocks()          // Get just body blocks
page.getHeader()              // Get header block
page.getFooter()              // Get footer block
page.hasChildren()            // Has child pages?
page.getHeadMeta()            // Get SEO meta tags

Page Configuration (page.yml)

title: About Us
description: Learn about our company
label: About                  # Short nav label (optional)
order: 2

# Navigation visibility
hidden: true                  # Hide from all navigation
hideInHeader: true            # Hide from header nav only
hideInFooter: true            # Hide from footer nav only

# Layout overrides (default: all true)
layout:
  header: false               # Don't show header on this page
  footer: false               # Don't show footer on this page
  leftPanel: false            # Don't show left panel
  rightPanel: false           # Don't show right panel

# SEO (optional)
seo:
  noindex: false
  image: /about-og.png

Block

Represents a section/component on a page.

block.component               // Component name
block.getBlockContent()       // Get parsed content
block.getBlockProperties()    // Get configuration properties
block.childBlockRenderer      // Renderer for child blocks

Input

Handles form input fields with validation.

input.value                   // Current value
input.validate()              // Run validation
input.errors                  // Validation errors

Architecture

@uniweb/runtime (browser)
    │
    └── imports @uniweb/core
            │
            ├── createUniweb() - creates singleton
            ├── Uniweb - main instance
            ├── Website - page/locale management
            ├── Page - page representation
            ├── Block - section representation
            └── Input - form handling

@uniweb/kit (foundation components)
    │
    └── imports @uniweb/core
            │
            └── getUniweb() - access singleton

For Foundation Creators

Foundations typically don't import from @uniweb/core directly. Instead, use @uniweb/kit which provides React hooks and components that abstract the core:

// Prefer this (kit)
import { useWebsite } from '@uniweb/kit'
const { localize, website } = useWebsite()

// Instead of this (core)
import { getUniweb } from '@uniweb/core'
const website = getUniweb().activeWebsite

Mark @uniweb/core as external in your foundation's Vite config:

// vite.config.js
export default {
  build: {
    rollupOptions: {
      external: ['react', 'react-dom', 'react-router-dom', '@uniweb/core']
    }
  }
}

Related Packages

License

Apache 2.0