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

bw-rikaoyi

v1.0.1

Published

> Router middleware for [Koa](https://github.com/koajs/koa). Maintained by [Forward Email][forward-email] and [Lad][].

Downloads

2

Readme

@koa/router

Router middleware for Koa. Maintained by Forward Email and Lad.

build status code style styled with prettier made with lass license

Table of Contents

Features

  • Express-style routing (app.get, app.put, app.post, etc.)
  • Named URL parameters
  • Named routes with URL generation
  • Match routes with specific host
  • Responds to OPTIONS requests with allowed methods
  • Support for 405 Method Not Allowed and 501 Not Implemented
  • Multiple route middleware
  • Multiple and nestable routers
  • async/await support

Migrating to 7 / Koa 2

  • The API has changed to match the new promise-based middleware signature of koa 2. See the koa 2.x readme for more information.
  • Middleware is now always run in the order declared by .use() (or .get(), etc.), which matches Express 4 API.

Install

npm:

const http = require('http');
const fs = require('fs');
const url = require('url');
const path = require('path');
const qs = require('querystring');

const app = http.createServer((req, res) => {
    res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader('Content-Type', 'text/html;charset=utf8');
    let urlparse = url.parse(req.url)
    let shoppath = path.join(__dirname, 'shop.json')

    if (urlparse.pathname == '/showdata') {
        let shopdata = fs.readFileSync(shoppath, 'utf-8')
        return res.end(shopdata)
    }

    if (urlparse.pathname == '/showquery') {
        let params = qs.parse(urlparse.query);
        let shopdata = JSON.parse(fs.readFileSync(shoppath, 'utf-8'));
        let data = shopdata.filter((item) => {
            return item.name.search(params.name) != -1;
        })
        return res.end(JSON.stringify(data))
    }
    if (urlparse.pathname == '/showdel') {
        let params = qs.parse(urlparse.query);
        let shopdata = JSON.parse(fs.readFileSync(shoppath, 'utf-8'));
        if (shopdata.findIndex((item) => item.id == params.id) != -1) {
            shopdata.splice(shopdata.findIndex((item) => item.id == params.id), 1)
        } else {
            return res.end('403')
        }
        fs.writeFileSync(shoppath, JSON.stringify(shopdata, 'utf-8'));
        return res.end('200');
    }
    if (urlparse.pathname == '/showadd') {
        let params = qs.parse(urlparse.query);
        let shopdata = JSON.parse(fs.readFileSync(shoppath, 'utf-8'));
        shopdata.push(params);
        fs.writeFileSync(shoppath, JSON.stringify(shopdata, 'utf-8'));
        return res.end('200');
    }

    if (urlparse.pathname == '/showput') {
        let params = qs.parse(urlparse.query);
        let shopdata = JSON.parse(fs.readFileSync(shoppath, 'utf-8'));
        for (let i = 0; i < shopdata.length; i++) {
            if (params.id == shopdata[i].id) {
                if (shopdata[i].status == 0) {
                    shopdata[i].status = 1;
                } else {
                    shopdata[i].status = 0
                }
            }
        }
        fs.writeFileSync(shoppath, JSON.stringify(shopdata, 'utf-8'));
        return res.end('200');
    }

})

app.listen(3000)

Typescript Support

 <input type="text" name="" id="search"> <button id="btn">搜索</button>
    <div id="menu"></div>

    
  let ajax = new XMLHttpRequest();
    function render() {
        ajax.open('get', 'http://localhost:3000/showdata');
        ajax.send();
        ajax.onload = () => {
            let data = JSON.parse(ajax.responseText);
            menu.innerHTML = data.map((item) => {
                return `
                <p>${item.id}</p>
                <p>${item.name}</p>
                <p>${item.price}</p>
                <p>${item.status == 1 ? '上架中' : '未下架'}</p>
                <button onclick='Del(${item.id})'>删除</button>
            `
            }).join('')
        }
    }
    render();


    btn.onclick = () => {
        ajax.open('get', `http://localhost:3000/showquery?name=${search.value}`);
        ajax.send();
        ajax.onload = () => {
            let data = JSON.parse(ajax.responseText);
            menu.innerHTML = data.map((item) => {
                return `
                <p>${item.id}</p>
                <p>${item.name}</p>
                <p>${item.price}</p>
                <p>${item.status == 1 ? '上架中' : '未下架'}</p>
            `
            }).join('')
        }

    }

    const Del = (id) => {
        ajax.open('get', `http://localhost:3000/showdel?id=${id}`);
        ajax.send();
        render();
    }

API Reference

See API Reference for more documentation.

Contributors

| Name | | ---------------- | | Alex Mingoia | | @koajs |

License

MIT © Alex Mingoia