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

es7-aspect

v1.2.0

Published

A simple aspect-oriented programming library in ECMAScript 7

Downloads

14

Readme

ES7-Aspect

Build Status npm version

This library provides simple aspect oriented programming features in javascript using ES7 decorators.

It is a derivative of Board project.

Please note that this library is intended to do simple runtime checks and should be used as the last resort. It is not async-compatible, i.e. the activities in an Aspect class cannot contain any callbacks or promises, whereas the original function can be async.

Sample Usage

In gru-aspect.js:

import Aspect from 'es7-aspect';

export default class GruAspect extends Aspect {
  //Once again, no async calls in any of these functions

  @Aspect.before('stealsTheMoon')
  eatsABanana(bananas) {
    if (bananas) {
      console.log(`There're ${bananas.length} banana(s). Eat one.`);
      bananas.pop();
    }
  }

  @Aspect.intercept('stealsTheMoon')
  checkBananas(resolve, reject, bananas) {
    if (!bananas || bananas.length === 0) {
      console.log('No banana. Nah.');
      reject();
    }
    else {
      console.log(`${bananas.length} banana(s)!`);
      resolve();
    }
  }

  @Aspect.after('stealsTheMoon')
  givesBananas(bananas) {
    console.log(`${bananas.length} banana(s) left.`);
  }
}

In gru.js:

import Aspect from 'es7-aspect';
import GruAspect from './gru-aspect';

@Aspect.use(GruAspect)
export default class Gru {
  stealsTheMoon(bananas) {
    console.log('Just stole the moon!');
  }
}

In a console:

new Gru().stealsTheMoon();
// Prints 'No banana. Nah.'

new Gru().stealsTheMoon(['banana', 'banana']);
// Prints
// There're 2 banana(s). Eat one.
// Just stole the moon!
// 1 banana(s) left.

Advices

There are three advices: Before, After and Intercept.

Before

Perform certain activities before the original function executes. After all defined activities finishes, the original will run. The pre-activities have access to the actual arguments that will be eventually applied.

Intercept

The intercept advice runs before the original function, similar to the before advice, except that there can be one and only one intercept advice defined for a method, and it has the ability to prevent the original function from execution.

  • To continue running after completing the interception, call resolve().
  • Otherwise, to stop execution, call reject([val]). [val] is an optional argument that will be used as the return value of original function.

After

Perform certain activities after the original function executes. All activities run after the original function completes execution. The post-activities have access to the actual arguments that will be eventually applied.