New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

monkey-patch

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

monkey-patch

Monkey Patching Dependency Injector

latest
npmnpm
Version
0.0.3
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

Build
Status

About

monkey is a small JavaScript library, written in CoffeeScript for monkey patching dependent functionality into objects. Dependency Injection (DI) is a concept that allows components, such database access, to be swapped in/out during run time instead of compile time.

This allows an application to change its functionality without changing its logic. This is very useful when testing an application, being able to swap in a database component for a fake on that writes to nowhere.

Since JavaScript allows objects to be changed during runtime, it is easy to simply monkey patch in a new piece of functionality for different use cases.

API

monkey provides two core functions:

  • monkey.patch
  • monkey.unpatch

Example

Here is an example where monkey being used to inject functionality for a test

class User 
    save: () -> # real functionality
    find: (id) -> # look up the user

user = new User
monkey.patch user, 
    save: () -> true
    find: () -> new User 

... run some tests ... 

# revert user back to normal
monkey.unpatch user

# do some other change to user
monkey.patch user, 
    save: () -> false
    find: () -> null

... etc ..

Keywords

dependency

FAQs

Package last updated on 06 Sep 2012

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