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

aileen-annotation

v0.2.5

Published

NodeJS Annotation Engine From Aileen Framework

Downloads

13

Readme

aileen-anntation

项目介绍

该项目为 NodeJS 注解框架,用于简化注解装饰器的开发, 提供简单的注解申明,装饰器导出,以及注解目标的相关信息查看等接口。提供标准化的注解装饰器申明方式。

快速开始

安装

npm i aileen-annotation -S

基础用法

import { Annotation } from "aileen-annotation";

// 创建注解
const anno = new Annotation<{
  id : string;
  name : string;
}>()

@anno.decorator({
  id: "id",
  name: "name",
})
class Demo {
  @anno.decorator({
    id: "test",
    name: "test",
  })
  test(
    @anno.decorator({
      id: "args",
      name: "args",
    })
    args: any
  ) {
    console.log(args);
  }
}

// 判断是否有注解
const exist = anno.hasRef(Demo);
// true


// 获取类注解信息
const refClass = anno.getRef(Demo);
// {
//    "id":"id",
//    "name":"name"
// }

// 通过实例获取
const refObjectClass = anno.getRef(new Demo());
// {
//    "id":"id",
//    "name":"name"
// }

// 获取方法注解信息
const refProperty = anno.getRefs(Demo, "test");
// {
//    "id":"test",
//    "name":"test"
// }

// 获取参数注解信息
const refArg= anno.getRefCompose(Demo, "test", 0);
// {
//    "id":"args",
//    "name":"args"
// }

多重注解

import { Annotation } from "aileen-annotation";

// 创建注解
const anno = new Annotation<{
  id? : string;
  name? : string;
}>()

/**
 * 演示类
 */
@anno.decorator({
  id: "id"
})
@anno.decorator({
  name: "name"
})
class Demo {}

// 获取默认注解(第一个)
const ref = anno.getRef(Demo);
// {
//    "id":"id"
// }

// 获取所有注解
const refs = anno.getRef(Demo);
// [
//   {
//      "id":"id"
//   },
//   {
//      "name":"name"
//   }
// ]

// 合并多注解
const refCompose = anno.getRefCompose(Demo);
// {
//    "id":"id",
//    "name":"name"
// }

反射属性/方法

import { Annotation } from "../src/annotation";

/**
 * 测试用注解
 */
const anno = new Annotation<{
  id?: string;
  name?: string;
}>();

/**
 * 演示类
 */
@anno.decorator({
  id: "id",
  name: "name",
})
class Demo {
  @anno.decorator({})
  test1(): string {
    return "hello";
  }

  @anno.decorator({})
  test2(id: number, name: string) {
    console.log(id, name);
  }

  @anno.decorator({})
  test3: string;
}

const res1 = anno.getRefPropertys(Demo);
// [{ key: "test3", type: String }]

const res2 = anno.getRefMethods(Demo);
// [
//   {
//     key: "test2",
//     return: undefined,
//     parameters: [Number, String],
//   },
//   { 
//     key: "test1", 
//     return: String, 
//     parameters: [] 
//   },
// ]

类继承关系

import { Annotation } from "aileen-annotation";

// 创建注解
const anno = new Annotation<{
  id? : string;
  name? : string;
}>()

@anno.decorator({
  id: "id",
  name: "name",
})
class Demo1 {
  @anno.decorator({})
  test1(): string {
    return "hello";
  }

  @anno.decorator({})
  test2(id: number, name: string) {
    console.log(id, name);
  }

  @anno.decorator({})
  test3: string;
}

@anno.decorator({
  id: "id1",
  name: "name1",
})
class Demo2 extends Demo1 {}

class Demo3 extends Demo1 {}

const res1 = anno.getRefs(Demo1);
assert.deepEqual(res1, [
  {
    id: "id",
    name: "name",
  },
]);

const res2 = anno.getRefs(new Demo1());
assert.deepEqual(res2, [
  {
    id: "id",
    name: "name",
  },
]);

const res3 = anno.getRefs(Demo2);
assert.deepEqual(res3, [
  { id: "id1", name: "name1" },
  { id: "id", name: "name" },
]);

const res4 = anno.getRefs(Demo3);
assert.deepEqual(res4, [
  {
    id: "id",
    name: "name",
  },
]);

包装其他注解

import { Annotation } from "../src/annotation";

/**
 * 测试用注解
 */
const anno1 = new Annotation<{
  id?: string;
}>();

/**
 * 测试用注解
 */
const anno2 = new Annotation<{
  id?: string;
  name?: string;
}>();

/**
 * 包装其他注解
 */
anno2.warp((option) => anno1.decorator({ id: option.id }));

/**
 * 演示类
 */
@anno2.decorator({
  id: "id",
  name: "name",
})
class Demo {}


const res1 = anno1.getRef(Demo);
assert.deepEqual(res1, { id: "id" });

const res2 = anno2.getRefs(Demo);
assert.deepEqual(res2, [{ id: "id", name: "name" }]);