New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

twill

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

twill

a clean javascript aspect oriented microframework

  • 0.0.2
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

twill

A new approch to javascript aspect oriented programming. Twill is an attempt to create an AOP framework for javascript that feels like it was written for javascript. Twill will run fine in both node and in the browser.

install

npm install twill

example

var twill = require("twill"),
    foo = {
        stuff: function (a,b,c) { 
            console.log("stuff");
        },
        things: function () {
            console.log("things");
        },
        foo: function (bar, baz) {
            console.log(bar);
            console.log(baz);
        }
    };

var foo_aspect = twill.aspect(foo, function (weave) {
    weave.before.stuff(function (a, b, c) {
        console.log("calling stuff!");
    });

    weave.after.things(function (a, b, c) {
        console.log("called things!");
    });

    weave.around.foo(function (args, orig) {
        orig(args[0] || "default_bar", args[1] || "default_baz");
    });

    weave.create.sweet = function () {
        console.log("dude");
    };

    //can be done for before/after/around (around also passes orig)
    weave.all.after(function (method, args) {
        window.stats.track(method);
        console.log("stats +1 for " + method);
    });

    weave.create.dude = function () {
        console.log("sweet");
    };
});

foo.stuff("one", "two", "three");
// calling stuff
// stuff
// stats +1 for stuff

foo.things(1,2,3);
//things
//called things
//status +1 for things

foo.foo();
//default_bar
//default_baz
//stats +1 for things

foo.sweet();
//dude
//stats +1 for sweet

foo.dude();
//sweet

twill.unweave(foo_aspect);

foo.stuff("one", "two", "three");
// stuff

foo.things(1,2,3);
//things

foo.foo();
//undefined
//undefined

foo.sweet();
//method not defined

foo.dude();
//method not defined

todo:

This is a very early release and not everything is done just yet. Still todo:

  • advice.all methods are not implemented
  • unweaving is not supported yet.
  • make it work in the browser

how to develop

all code should have tests written in node-unit. Run the tests with:

jake test

FAQs

Package last updated on 16 Aug 2011

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc