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

cat-middleware

v0.2.8

Published

koa middleware

Downloads

57

Readme

Cat-middleware NPM version Build Status

Middleware of koa server. See more information in code and here.

Middleware

koa-react-render

Render html with react and nunjucks. If you need to use radium. You will get radiumConfig as props to your component.

Install
  • nunjucks
  • react
  • react-dom
Arguments
  • component: This component is used to render to the template.
  • options(default: {})
    • root(default: './views'): This is the folder of the templates which is for nunjucks.
    • renderKey(default: 'content'): This is the variable in template which will be replace with component.
    • template(default: 'template.html'): This is the template of the html.
    • You can add other variables for your template.
Example
import reactRender from 'cat-middleware/lib/koa-react-render';

...
app.use(reactRender(
  <div>render react</div>
));
...

koa-i18n

Read json file and use it as string. It will read the cookies from client. You can set i18n in cookies to change the language.

Arguments
  • options(default: {})
    • root(default: './i18n'): This is the folder of the files.
    • i18n(default: 'en-us'): This is the default language for this middleware.
Example
import i18n from 'cat-middleware/lib/koa-i18n';

...
app.use(i18n());
...
// Then you can use `i18n` in your `ctx`.

koa-authentication

Use to check the authentication. You must have user in ctx.state and authentication in user. You can use koa-passport to do this.

koa-authentication.configure
  • Arguments
    • authentication_levels(default: {}): This is used to check the authentication. For example, it will be like {none: 0, user: 1, superuser: 999}.
    • env(default: true): If this is false, this middleware will not check the authentication. Remeber to use this with process.env.NODE_ENV.
koa-authentication.set
  • Arguments
    • authentication(default: 'none'): Use to set authentication in url.
    • redirect(default: '/'): Redirect to the url when user dose not pass the authentication.
Example
import authentication from 'cat-middleware/lib/koa-authentication';

...
app.use(authentication.configure({
  none: 0,
  user: 1
}, process.env.NODE_ENV === 'production'));

...
router.get(
  '/authentication/',
  authentication.set('user', '/authentication/fail/'), ctx => {
    // do something here
  }
);
...

koa-relay-data

Use to get the data from fetch with react-relay.

Install
  • babel-polyfill
  • fetch-everywhere
  • react-relay
Arguments
  • link
  • query
  • variables
Example
import relayData from 'cat-middleware/lib/koa-relay-data';

...
app.use(relayData(
  link, graphql`
    query relayData {
      data {
        key
      }
    }
  `
));
...
// Then you can get the data `graphql_data` in your `ctx`.

License

MIT © hsuting