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 🙏

© 2026 – Pkg Stats / Ryan Hefner

decorator-dto

v2.0.2

Published

dto装饰器扩展

Readme

decorator-dto插件使用说明

  1. @Dto:用在class的上面,见下面demo
  2. @Format(fn):用在class的属性上面,参数为function,fn函数接收当前属性值并进行处理,执行format后将fn返回的值赋值到当前属性上.见下面demo
  3. @Link(k,fn):用在class的属性上面,参数分别为string和function,fn函数接收属性k(class未申明的属性)的值并进行处理,执行format后将fn返回的值赋值到当前属性上.见下面demo
  4. @OneToOne(k, fn) 用在class的属性上面,参数k(class申明的属性)为string,fn为可选的转换函数,执行format后将属性k值赋值到当前属性上.见下面demo
  5. @ManyToOne([K,...],fn) 用在class的属性上面,参数为[k,..],k必须为class申明的属性,fn为可选的转换函数,执行format后判断是否存在数组里的属性,若存在则将任一个值赋值到当前属性上.见下面demo
  6. @Property,用在class的属性上面,收集属性字段,当于其他装饰器同时存在时无意义,见下面demo
  7. @Inject(k, fn),用在class的属性上面, 第一个参数为当前类上的属性,可以为数组,在Format、Link、OneToOne、ManyToOne、Inject执行完后Condition执行前执行。
  8. @Condition(fn),用在class的属性上面,参数为function,fn的参数为当前最新对象,fn的返回值必须为boolean,若为true则当前属性显示,反之当前属性不显示,见下面demo
  9. warp: 当前class的静态方法用于批量格式化,见下面demo

注:

  • Link不能与OneToOne、ManyToOne、Format一起使用在同一属性上。
  • OneToOne与ManyToOne不能相互作用

@Dto
class Demo extends BaseDto  {

    @Format(val => val + 1)
    test = 1

    @Link('name', val => val + 1)
    test1 = 2;

    @OneToOne('test1')
    test2 = 2;

    @ManyToOne(['name2'])
    test3 = 2;

    @ManyToOne(['name3'], val => val + 1 )
    test4 = 2;

    @OneToOne('name4', val => val + 1)
    @Inject('test4', (v, m) => {
        return v + m
    })
    test5 = 2;

    @Condition(obj => true)
    test6 = 2;
}

// 调用
const demo = new Demo();

const tmp = Demo.warp([{ test: 3, name: 4, name1: 5, name2: 6, name3: 7, name4: 8 }])

console.log(tmp) 
//打印 [
    {
        test: 4,
        test1: 5,
        test2: 5,
        test3: 6,
        test4: 8,
        test5: 17,
        test6: 2
    }
]

demo.name = 2
demo.name1 = 33
demo.name2 = 44
demo.name3 = 55
demo.name4 = 66

const t = demo.format();

console.log(t.test) // 2
console.log(t.test1) // 3
console.log(t.test2) // 33
console.log(t.test3) // 44
console.log(t.test4) // 56 = 55 + 1
console.log(t.test5) // 67 = 66 + 1
console.log(t.test6) // 2

欢迎提出各种bug,有问题可以直接发送邮件到 [email protected]