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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@mk-singh/web-utils

v1.0.0

Published

A collection of TypeScript utilities for Deno including route factory with navigation support

Readme

@mk-singh/web-utils

Why This Library?

When building React applications, you often need to:

  • Manage complex nested routes
  • Handle multi-step forms with navigation
  • Avoid hardcoding paths throughout your app
  • Maintain consistent navigation patterns
  • Build breadcrumbs and back buttons

This library solves these problems by providing a declarative way to define your route structure once and generate all the paths automatically.

Compatibility

  • React.js (Perfect for SPA routing)
  • Vue.js (Works with Vue Router)
  • Next.js (App Router & Pages Router)
  • Vanilla JavaScript (Framework agnostic)
  • TypeScript (Full type support)
  • Any JavaScript bundler (Webpack, Vite, Rollup, etc.)# @mk-singh/web-utils

A collection of JavaScript utility functions designed for modern web development, with special focus on React.js applications. Modular and tree-shakeable for optimal bundle sizes.

Installation

import { createRoutes } from "@mk-singh/web-utils";

Modular Imports

Import only what you need to keep your bundle size small:

// Import specific utilities
import { createRoutes } from "@mk-singh/web-utils/factories/route-factory";

Features

Route Factory

Create nested route structures with automatic path resolution and navigation helpers.

createRoutes(basePath, routeConfig)

Transforms a route configuration object into a fully resolved route structure with absolute paths.

Parameters:

  • basePath (string): The base path to prepend to all routes
  • routeConfig (object): Route configuration with relative paths and navigation data

Returns: Object with resolved absolute paths and preserved navigation data

React.js Example

import React from 'react';
import { BrowserRouter, Routes, Route, Link } from 'react-router-dom';
import { createRoutes } from "@mk-singh/web-utils/factories/route-factory";

// Define your route configuration
const routeConfig = {
    dashboard: { path: "dashboard" },
    user: {
        path: "user",
        profile: {
            path: "profile",
            step: 1,
            prevPath: "../dashboard",
        },
        settings: {
            path: "settings", 
            step: 2,
            prevPath: "./profile",
        },
    },
    admin: {
        path: "admin",
        step: 3,
        prevPath: "./user/settings",
    },
};

// Generate routes with base path
const routes = createRoutes("/app", routeConfig);

function App() {
    return (
        <BrowserRouter>
            <nav>
                <Link to={routes.dashboard.path}>Dashboard</Link>
                <Link to={routes.user.profile.path}>Profile</Link>
                <Link to={routes.user.settings.path}>Settings</Link>
                <Link to={routes.admin.path}>Admin</Link>
            </nav>
            
            <Routes>
                <Route path={routes.dashboard.path} element={<Dashboard />} />
                <Route path={routes.user.profile.path} element={<Profile />} />
                <Route path={routes.user.settings.path} element={<Settings />} />
                <Route path={routes.admin.path} element={<Admin />} />
            </Routes>
        </BrowserRouter>
    );
}

// Use in components for navigation
function Settings() {
    const handleBack = () => {
        navigate(routes.user.settings.prevPath); // Goes to /app/user/profile
    };
    
    return (
        <div>
            <button onClick={handleBack}>← Back</button>
            <h1>Settings (Step {routes.user.settings.step})</h1>
        </div>
    );
}

Basic Example

import { createRoutes } from "@mk-singh/web-utils/factories/route-factory";

const routeConfig = {
    start: { path: "start" },
    onboarding: {
        path: "onboarding",
        basicDetails: {
            path: "basic-details",
            step: 1,
            prevPath: "../start",
        },
        businessDetails: {
            path: "business-details",
            step: 2,
            prevPath: "./basicDetails",
        },
    },
    review: {
        path: "review",
        step: 3,
        prevPath: "./onboarding/businessDetails",
    },
};

const routes = createRoutes("/client", routeConfig);

console.log(routes);
// Output:
// {
//     start: { path: "/client/start" },
//     onboarding: {
//         path: "/client/onboarding",
//         basicDetails: {
//             path: "/client/onboarding/basic-details",
//             step: 1,
//             prevPath: "/client/start",
//         },
//         businessDetails: {
//             path: "/client/onboarding/business-details",
//             step: 2,
//             prevPath: "/client/onboarding/basic-details",
//         },
//     },
//     review: {
//         path: "/client/review",
//         step: 3,
//         prevPath: "/client/onboarding/business-details",
//     },
// }

Path Resolution Rules

The createRoutes function intelligently resolves different types of paths in prevPath:

  • Relative paths with ../: Navigate up one level

    • ../start from /client/onboarding/basic-details/client/start
  • Current directory paths with ./: Reference sibling routes

    • ./basicDetails from /client/onboarding/business-details/client/onboarding/basic-details
  • Nested paths: Navigate to nested routes

    • ./onboarding/businessDetails from /client/review/client/onboarding/business-details

Use Cases

Perfect for:

  • React.js Single Page Applications with complex routing
  • Multi-step forms and wizards in React components
  • Navigation breadcrumbs with automatic path resolution
  • Dynamic route generation for React Router
  • Type-safe route management in TypeScript React apps
  • Centralized route configuration to avoid hardcoded paths
  • Back/Next navigation in form workflows

API Reference

Route Factory

createRoutes(basePath: string, routeConfig: RouteConfig): ResolvedRoutes

Development

# Run tests
npm test

# Format code
npm run format

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.