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

mod-onion

v0.0.5

Published

middleware structure

Downloads

2

Readme

mod-onion

基于洋葱皮模型,创建数据管道处理结构模型。

功能概述:####

1.创建洋葱皮模型。 2.支持Promise异步等待,错误捕获。

install

npm安装命令

npm install --save mod-onion

Usage

引入包

import onion from "mod-onion"

USEAGE 使用方法 范例代码

import ModOnion from "mod-onion"

let onion=new ModOnion([
  async (data,next)=>{
    console.log("---------------------------")
    console.log(data,"1")
    data.name+=1
    data.age+=1
    await next()
    data.age-=1
    console.log(data,"1")
    console.log("---------------------------")
  },
  (data,next)=>{
    return new Promise((resolve,reject)=>{
      setTimeout(async ()=>{
        console.log(data,"2")
        data.name+=1
        data.age+=1
        await next()
        data.age-=1
        console.log(data,"2")
        resolve(data)
      },2000)   
    })  
  },
  (data,next)=>{
    return new Promise((resolve,reject)=>{
      setTimeout(async ()=>{
        console.log(data,"3")
        data.name+=1
        data.age+=1
        await next()
        ctx.age-=1
        console.log(ctx,"3")
        resolve(ctx)
      },2000)   
    })  
  }
]).then(
  value=>{
    console.log("END:value",value)
  }
)
.catch(err=>{
  console.log("END:error", err.message)
});

/* console.log
---------------------------
{name: 1001, age: 1} "1"
{name: 1002, age: 2} "2"
{name: 1003, age: 3} "3"
{name: 1004, age: 3} "3"
{name: 1004, age: 2} "2"
{name: 1004, age: 1} "1"
---------------------------
END:value {name: 1004, age: 1}
*/

API 类方法

new ModOnion(pipes)

pipes:Array 处理管道函数数组

import ModOnion from "mod-onion"

let onion=new ModOnion([
  async (data,next)=>{
    console.log("---------------------------")
    console.log(data,"1")
    data.name+=1
    data.age+=1
    await next()
    data.age-=1
    console.log(data,"1")
    console.log("---------------------------")
  },
  (data,next)=>{
    return new Promise((resolve,reject)=>{
      setTimeout(async ()=>{
        console.log(data,"2")
        data.name+=1
        data.age+=1
        await next()
        data.age-=1
        console.log(data,"2")
        resolve(data)
      },2000)   
    })  
  },
  (data,next)=>{
    return new Promise((resolve,reject)=>{
      setTimeout(async ()=>{
        console.log(data,"3")
        data.name+=1
        data.age+=1
        await next()
        data.age-=1
        console.log(data,"3")
        resolve(data)
      },2000)   
    })  
  }
]).then(
  value=>{
    console.log("END:value",value)
  }
)
.catch(err=>{
  console.log("END:error", err.message)
});

/* console.log
---------------------------
{name: 1001, age: 1} "1"
{name: 1002, age: 2} "2"
{name: 1003, age: 3} "3"
{name: 1004, age: 3} "3"
{name: 1004, age: 2} "2"
{name: 1004, age: 1} "1"
---------------------------
END:value {name: 1004, age: 1}
*/

.use(func)

func:Function 添加处理管道函数,由外至内添加。

onion.use((data,next)=>{
  return new Promise((resolve,reject)=>{
    setTimeout(()=>{
      console.log(data,"4")
      data.name+=1
      next()
      data.name-=1
      console.log(data,"4")
      resolve(data)
    },1000)   
  })  
})

注意:函数必须提供两个参数 data,正在管道中处理的数据. next,下一个内层的处理方式

管道函数可返回Promise对象. PS:请记返回Promise对象时,需通过resolve(data)方法向外层返回数据结果。

.pipingData(data,tempPipes)

data:Object 需管道加工的数据 tempPipes:Array 处理管道函数数组,可启用临时的加工管道