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

van-cone

v1.0.1

Published

a lightweight package providing basic SPA such as routing, history and navigation functionality for VanJS applications

Downloads

51

Readme

Van Cone

Author: b-rad-c

An SPA framework add on for VanJS

🔥 Van Cone plus VanJS can create a fully featured SPA app that minifies and gzips to ~4.0 kB! 🔥

This lightweight (~215 lines) VanJS addon adds the following features:

  • Navigation powered by custom router with async loading
    • url and query param parsing
    • integrates with browser history
    • state object that integrates with browser history
    • determine current active route
    • define different backend endpoints for fetching data if different than route's front end url
  • link component for generating links based off of named routes
    • easily add url and query params as objects
    • dynamic css styling for active route
    • pass additional context data such as a prefetched data or other configuration to route component
  • TypeScript support

Links

Overview

Van Cone is a minimal framework that provides routing, history and a link component that provides dynamic styling for when it is the active link.

There is only one exported function which is used to create an application object. You provide it with the DOM element that will contain the app, a list of routes, and an optional default state for window.history.state and it returns an object with several SPA helper methods.

Install:

npm install van-cone

A basic hello world app requires javascript and HTML:

Example JS:

import createCone from 'van-cone';
import van from 'vanjs-core';
const { div, p, span, hr } = van.tags;

// define page components
const homePage = () => div('Home Page')
const userPage = (params) => div('User Page', p('userId: ' + params.userId))

// define routes
const routes = [
  { path: '/',              name: 'home', callable: async () => homePage },
  { path: '/user/:userId',  name: 'user', callable: async () => userPage }
];

// create the spa object
const routerElement = div({ id: 'layout' })
const { link } = createCone(routerElement, routes)

// main app layout
const App = () =>
  div(
    link({ name: 'home' }, 'Home'),
    span(' | '),
    link({name: 'user', params: {userId: 123}}, 'User'),
    hr(),
    routerElement
  );

document.body.replaceChildren(App());

Example HTML:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="description" content="Dialog Modal component with VanJS" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>VanJS Hello World</title>
  </head>
  <body>
    <script src="./src/index.js" type="module"></script>
  </body>
</html>

Changelog

1.0.1

  • fix bug with active route navigation - see: https://github.com/vanjs-org/van/issues/350
  • minimum supported version of VanJS raised to 1.3.0

1.0.0

  • fix issue #4 - argument for navigate and pushHistory functions
  • Van Cone is out of beta and is API stable

0.0.8

  • fix type definitions for navigate and pushHistory functions

0.0.7

  • minor update in type definition file

0.0.6

  • change isCurrentPage to return a boolean instead of a van derive object.

0.0.5

  • add route function, remove object style route definitions from constructor functions
  • add typescript definitions

0.0.4

  • change navigate and pushHistory to use route names instead of url strings, and accept optional nav state, they now return the url string.
  • rename navLink to link
  • update createVanCone return object
    • rename router.navUrl to navUrl
    • rename router.backendUrl to backendUrl
    • remove router
    • remvoe handleNav
  • interal refactoring to reduce size

0.0.3

  • rename router.formatUrl to router.navUrl
  • add router.backendUrl, update routes to support backend urls
  • add pushHistory
  • add context to programmatic navigation functions that is passed to route element

Support, issues, and suggestions

Open an issue or discussion either in the github repo

Contributing

Got some skills? Want to contribute? Send a pull request!

Development

start here:

git clone https://github.com/medium-tech/van-cone

In the ./examples folder you will find init.sh which will install dependencies for each example. If you run the script with the link option it will use your npm's link for van-cone so that you can test the examples in real time as you change the code.

init.sh --link

See here for docs on setting up an npm link.

Each example has a dev command npm run dev for launching the development server, and npm run test for testing. You can run ./examples/test.sh or npm run test from the root pacakge to run tests in all examples.

If you want to delete node_modules for each example run ./examples/reset.sh.

Roadmap

Some things I'm interested in.

  • type conversion for query parameters, currently query params and passed to the component as strings.

The Name

Van Cone is an addon for VanJS which is short for Vanilla JavaScript, and makes a callout to vanilla ice cream in its logo. Van Cone provides the cone that is needed to support the ice cream. VanJS provides reactivity and UI components, Van Cone provides routing, history and navigation components, together they're everything you need for a lightweight SPA experience!

Contributors

Credit

Router based on minimal router (no longer maintained).