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

@vue-polar/middleware

v1.0.2

Published

A middleware implementation for VueJS based on the "vue-router"

Downloads

1

Readme

README

VUE-POLAR / Statemanager

#####V1.0.2 #####Typescript required

The "Vue-polar / middleware" is an extension of "vue-router". This package adds the addition to implement middleware classes in a neat typescript way.

How do I get set up?

#####Usage with yarn yarn add @vue-polar/middleware

#####Usage with npm npm i @vue-polar/middleware

#####Dependencies

  • "vue": "^2.6.11",
  • "vue-router": "^3.1.5" #####Dev Dependencies
  • "typescript": "~3.7.5", #####ESlint Configuration
  • "@typescript-eslint/no-explicit-any": "off", #####Usage When you first setup "@vue-polar/middleware" you need to add the following lines to the bottom of your "@/routes/index.ts" just above the export
//Inject the router
MiddlewareRouter.setRouter(router);

//Here you will be able to register the middleware.
//You'll instantiate your middleware class and define how important it is
//The importance goes from 0 as not very important to higher as very important
//
//So this middleware is not that important
//MiddlewareRouter.register(new ExampleAfterMiddleware(),0);
//
//But this one is very important
//MiddlewareRouter.register(new ExampleBeforeMiddleware(),10);

//Call router functions
MiddlewareRouter.enable();

There are 2 types of Middleware: After and Before. In this package we define the difference by adding a Generic Type to the interface

Here is how that looks like:

//Extends the MiddlewareContract with the AfterMiddleware GenericType
export class ExampleAfterMiddleware implements MiddlewareContract<AfterMiddleware>{

    //With middleware groups we can filter for which routes we need to run this middleware
    getMiddlewareGroups(): Array<string> {
        return ['someGroup'];
    }

    //because we are using the generic type after middleware
    //the class now expects you to create a call property with the exact implementation the vue router needs
    //in this case being:
    call: AfterMiddleware = (to, from) => {
        //asd
    }
}

//Below you will find an example for the Before version of a middleware

//Extends the MiddlewareContract with the BeforeMiddleware GenericType
export class ExampleBeforeMiddleware implements MiddlewareContract<BeforeMiddleware>{
    
    //With middleware groups we can filter for which routes we need to run this middleware
    getMiddlewareGroups(): Array<string> {
        return ['someGroup'];
    }


    //because we are using the generic type before middleware
    //the class now expects you to create a call property with the exact implementation the vue router needs
    //in this case being:
    call: BeforeMiddleware = (to, from, next) => {
        return true;
    }
}

Now last but not least you need to know how to create a route that responds to these middlewares:

//we're using the default route system from vue-router
//the only difference is that we add a meta property
//This property is called 'middlewareGroups' and expects an array of middlewareGroup names
//Yes, These are the same as the ones you define in the 'getMiddlewareGroups()' method
{
    path: "/account",
    name: "account",
    component: Account,
    meta:{
      middlewareGroups: [
          'auth'
      ]
    }
}

Contribution guidelines

We are currently still working on this package any suggestions and/or contribution is welcome

Writing tests

Writing tests should be done in JEST and written according TDD

Code review

We will review the code submitted before there is any permanent action taken. Please do not waste my time on anything that is outside of the scope of this package.

Who do I talk to?

stanley-leroy-gerrits