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

moose-decorators

v1.0.3

Published

Moose Decorators is a project that provides decorators or annotations for JavaScript language. It contains many decorators are used to validate dto (data transfer object) from backend, improve your application such as ioc (invention of control) or caching

Downloads

213

Readme

MOOSE DECORATORS: A specific way to improve your application

Copyright 2024 Moose Software Inc. All rights reserved.

Moose Decorators is a project that provides decorators or annotations for JavaScript language. It contains many decorators are used to validate dto (data transfer object) from backend, improve your application such as ioc (invention of control) or caching...

Installing

For the latest stable version:

npm install moose-decorators

Usage

Cache:

Cache is used to cache returned values from methods such as getter or native methods, furthermore, it also is used to cache observable value of rxjs to improve your application because we don't need to re-call api methods that it always returns the constant value.

Without timeout:

import { Cache } from 'moose-decorators';

class Test {
  @Cache()
  get heroes(): string {
    const num = Math.random();
    return `id: ${num}, name: superman`;
  }
}

const test: Test = new Test();
const heroes1: string = test.heroes;
const heroes2: string = test.heroes;

expect(heroes1).toBe(heroes2);

With timeout:

import { Cache } from 'moose-decorators';

class Test {
  @Cache({
    timeout: 1000
  })
  get heroes(): string {
    const num = Math.random();
    return `id: ${num}, name: superman`;
  }
}

const test: Test = new Test();
const heroes1: string = test.heroes;
setTimeout((): void => {
  // Should be called when the timeout expires
  const heroes2: string = test.heroes;
  expect(heroes1).not.toBe(heroes2);
}, 2000);

Because JavaScript is a no-strict programming language, so you have to use a unique method name for every cached method, otherwise please use the id of the cache instead

import { Cache } from 'moose-decorators';

class Test1 {
  @Cache({
    id: 'test1#heroes'
  })
  get heroes(): string {
    const num = Math.random();
    return `id: ${num}, name: superman`;
  }
}

const test1: Test1 = new Test1();
const test1_heroes1: string = test1.heroes;
const test1_heroes2: string = test1.heroes;

expect(test1_heroes1).toBe(test1_heroes2);

class Test2 {
  @Cache({
    id: 'test2#heroes'
  })
  get heroes(): string {
    const num = Math.random();
    return `id: ${num}, name: superman`;
  }
}

const test2: Test2 = new Test2();
const test2_heroes1: string = test2.heroes;
const test2_heroes2: string = test2.heroes;

expect(test2_heroes1).toBe(test2_heroes2);

GLOBAL CONFIGURATION: add the moose.conf.js file and modify the content

module.exports = {
  cache: {
    timeout: 1000 // The default timeout in milliseconds of the cache
  }
};