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

koa-core

v1.0.8

Published

### Modules

Downloads

18

Readme

koa-core the util library for koa web application

Modules

Errors

there are some Object exports which all extends Error, they have the same property all type and the value are as the same as the object's name, e.g.

var err = new ApiRequestError('err message');
console.log(err.type);
console.log(err.message);
// ApiRequestError
// err message
  • ApiRequestError

  • DBError

  • PageError

    it has the status property which stands for httpStatus, the same as http status code, default 500

    var err = new PageError('err message', 404);
    console.log(err.staus);
    console.log(err.message);
    // 404
    // err message
  • CodeException

fileHelper

the util for handle files

  • has(uri)

    check the path exits?

    uri: the path (string)

    return true or false

  • write(uri, content)

    write something into the file

    uri: the file path (string)

    content: the file content (string)

  • read(uri, def)

    read file content

    uri: the file path (string)

    def: if readfile fail or file unexits (string)

    return string

  • remove(uri)

    remove file

    uri: the file path (string)

  • readJSON(uri, def)

    read the json file content and return a json object

    uri: the file path (string)

    def: the default return when the reading fail (object)

  • mkdirSync(dirname)

    mkdir

    dirname: dirname

http

the module for http request which extend request

https://github.com/request/request/blob/master/README.md

  • get(url, params, header)

    the request with get method

    url: request URL

    params: request params

    header: request header, default {}

    return promise

  • post(url, params, header)

    the request with get method

    url: request URL

    params: request params

    header: request header, default {}

    return promise

there are some method you can register to global

// 注册请求前事件
http.onBeforeSend = function (req) {}

// 格式化输出
http.responseFormat = function (res) { return res; }

// 判断请求是否成功
http.isSuccess = function(res) { return Number(res.code) === 1; }

// 注册请求完成事件, 无论成功与否
http.onComplete = function(response) {}

// 业务上的错误回调
http.errCallback = function(response, body) {}

http.defaultOptions = {
  time: true
};
//option 结构参考 https://github.com/request/request/blob/master/README.md

logger

use:

var logger = require('koa-core').logger;
logger.log('success','http')
  • log(msg, type)

    add logs content

    msg: logs content (string)

    type: log type which from your conf, default log(string)

there are some method you can register to global

logger.formatMsg = function(msg, type) { }

PageHelper

the helper for view engin

  • contructor(options)
    • options default was { jsonFileName: 'staticAsset.json' }
  • setCss(moduleName)

    get css url from the webpack asset.json file by moduleName

  • setScript(moduleName)

    get js url from the webpack asset.json file by moduleName

  • setImgSrc(srcPath)

    set the webpack build img path

    usage with img-assets-webpack-plugin

  • isToday(date)

    ...

  • formatDate (dateString, format)

    ...

  • fromNow (dataString)
    // 1 天前
    // 4 小时前
  • getweek (dateString)

    format the date to 周x