You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

intercepts

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

intercepts

Intercepts event with `before` and `after`.

0.0.1
latest
Source
npmnpm
Version published
Weekly downloads
3
200%
Maintainers
1
Weekly downloads
 
Created
Source

intercepts

Intercepts event with before and after.

Installation

npm install intercepts

Quick Start

var intercepts = require('intercepts')

function Users() {
  intercepts(this)

  f(this.before)
  f(this.after)
  f(this.intercepts)

  this.create = function (data, callback, onError) {
    this.intercepts('create', arguments, create)

    function create(done) {
      log('create data', data)

      eq(data.age, 21)
      data.age = 22
      done()
    }

    return this
  }

}

var users = new Users

users.before('create', function (done) {
  log('before create', this)

  var data = this[0]
  eq(data.name, 'jack')
  eq(data.age, 20)
  data.age = 21

  done()
})

users.after('create', function (done) {
  log('after create', this)

  var data = this[0]
  eq(data.name, 'jack')
  eq(data.age, 22)

  done()
})

users.create({name: 'jack', age: 20}, function () {
  log('create successful')
}, function () {
  log('create error')
})

API

var intercepts = require('intercepts');
var obj = {};
intercepts(obj);

obj.before(String name, Function callback)

obj.after(String name, Function callback)

obj.intercepts(String name, Object arguments, Function itself)

License

MIT

Keywords

intercepts

FAQs

Package last updated on 21 Sep 2013

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