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

@yeliex/arsenic

v1.1.2

Published

arsenic--a nodejs framework

Downloads

1

Readme

Arsenic

  • structure

    Arsenic Project
    ├── config
    |   ├── config.default.js
    |   ├── config.daily.js
    |   └── config.online.js
    ├── controller
    |   └── user
    |      └── index.js
    ├── service
    |   └── user
    |      └── index.js
    ├── router
    |   └── user.js
    ├── lib
    ├── test
    ├── index.js
    └── package.json
  • router

    Router 主要用来描述请求 URL 和具体承担执行动作的 Controller 的对应关系

    // router/user.js
    const router = require("@yeliex/arsenic").router();
      
    router.mount('/user', ctx => ctx.controller.user );
      // ctx.get('/users', ctx => ctx.controller.user.list);
      // ctx.post('/users', ctx => ctx.controller.user.create);
      // ctx.get('/users/:id', ctx => ctx.controller.user.item);
      // ctx.put('/users/:id', ctx => ctx.controller.user.update);
      // ctx.delete('/users/:id', ctx => ctx.controller.user.destroy);
    
    router.get('/users',ctx => ctx.controller.user.list);
      
    router.post('/users',ctx => ctx.controller.user.list);
      
    module.exports = router;
  • controller

    Controller 接受用户的参数,从数据库中查找内容返回给用户或者将用户的请求更新到数据库中

    框架推荐 Controller 层主要对用户的请求参数进行处理(校验、转换),然后调用对应的 service 方法处理业务,得到业务结果后封装并返回

    • 获取用户通过 HTTP 传递过来的请求参数
    • 校验、组装参数
    • 调用 Service 进行业务处理,必要时处理转换 Service 的返回结果,让它适应用户的需求
    • 通过 HTTP 将结果响应给用户
    // controller/user/index.js
    const Context = require('@yeliex/arsenic').Context;
      
    class UserController extends Context {
      list() {
        return this.Service.user.getUserList();
      }
      create(){
        return this.Service.user.getUser({phone: this._POST.phone}).then((user)=>{
          if(user){
            return Promise.reject('user exist');
          }
          return this.Service.user.addUser(this._POST);
        });
      }
      destroy(){
        return this.Service.user.getUser({phone: this._POST.phone}).then((user)=>{
          if(user){
            return Promise.reject('user exist');
          }
          return this.Service.user.deleteUser({id: this._POST.id});
        });
      }
    }
      
    module.exports = UserController;
  • service

    Service 是在复杂业务场景下用于做业务逻辑封装的一个抽象层

    • 保持 Controller 中的逻辑更加简洁
    • 保持业务逻辑的独立性,抽象出来的 Service 可以被多个 Controller 重复调用
    • 将逻辑和展现分离,更容易编写测试用例
    • 复杂数据的处理
    • 第三方服务的调用
    // service/user/index.js
    const Context = require('@yeliex/arsenic').Context;
      
    class UserService extends Context {
      getUserList(){
        return this.db.userDB.findAll();
      }
    }
    
    // OR
    const {userDB} = require('../../libs/db');
    
    exports.getUserList = () => {
      return userDB.findAll();
    }