node-query/node_modules/grunt-contrib-nodeunit/node_modules/hooker/package.json

46 lines
6.9 KiB
JSON
Raw Normal View History

2014-10-20 16:56:45 -04:00
{
"name": "hooker",
"description": "Monkey-patch (hook) functions for debugging and stuff.",
"version": "0.2.3",
"homepage": "http://github.com/cowboy/javascript-hooker",
"author": {
"name": "\"Cowboy\" Ben Alman",
"url": "http://benalman.com/"
},
"repository": {
"type": "git",
"url": "git://github.com/cowboy/javascript-hooker.git"
},
"bugs": {
"url": "https://github.com/cowboy/javascript-hooker/issues"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/cowboy/javascript-hooker/blob/master/LICENSE-MIT"
}
],
"dependencies": {},
"devDependencies": {
"grunt": "~0.2.1"
},
"keywords": [
"patch",
"hook",
"function",
"debug",
"aop"
],
"engines": {
"node": "*"
},
"main": "lib/hooker",
"scripts": {
"test": "grunt test"
},
"readme": "# JavaScript Hooker\n\nMonkey-patch (hook) functions for debugging and stuff.\n\n## Getting Started\n\nThis code should work just fine in Node.js:\n\nFirst, install the module with: `npm install hooker`\n\n```javascript\nvar hooker = require('hooker');\nhooker.hook(Math, \"max\", function() {\n console.log(arguments.length + \" arguments passed\");\n});\nMath.max(5, 6, 7) // logs: \"3 arguments passed\", returns 7\n```\n\nOr in the browser:\n\n```html\n<script src=\"dist/ba-hooker.min.js\"></script>\n<script>\nhook(Math, \"max\", function() {\n console.log(arguments.length + \" arguments passed\");\n});\nMath.max(5, 6, 7) // logs: \"3 arguments passed\", returns 7\n</script>\n```\n\nIn the browser, you can attach Hooker's methods to any object.\n\n```html\n<script>\nthis.exports = Bocoup.utils;\n</script>\n<script src=\"dist/ba-hooker.min.js\"></script>\n<script>\nBocoup.utils.hook(Math, \"max\", function() {\n console.log(arguments.length + \" arguments passed\");\n});\nMath.max(5, 6, 7) // logs: \"3 arguments passed\", returns 7\n</script>\n```\n\n## Documentation\n\n### hooker.hook\nMonkey-patch (hook) one or more methods of an object.\n#### Signature:\n`hooker.hook(object, [ props, ] [options | prehookFunction])`\n#### `props`\nThe optional `props` argument can be a method name, array of method names or null. If null (or omitted), all enumerable methods of `object` will be hooked.\n#### `options`\n* `pre` - (Function) a pre-hook function to be executed before the original function. Arguments passed into the method will be passed into the pre-hook function as well.\n* `post` - (Function) a post-hook function to be executed after the original function. The original function's result is passed into the post-hook function as its first argument, followed by the method arguments.\n* `once` - (Boolean) if true, auto-unhook the function after the first execution.\n* `passName` - (Boolean) if true, pass the name of the method into the pre-hook function as its first arg (preceding all other arguments), and into the post-hook function as the second arg (after result but preceding all other arguments).\n\n#### Returns:\nAn array of hooked method names.\n\n### hooker.unhook\nUn-monkey-patch (unhook) one or more methods of an object.\n#### Signature:\n`hooker.unhook(object [, props ])`\n#### `props`\nThe optional `props` argument can be a method name, array of method names or null. If null (or omitted), all methods of `object` will be unhooked.\n#### Returns:\nAn array of unhooked method names.\n\n### hooker.orig\nGet a reference to the original method from a hooked function.\n#### Signature:\n`hooker.orig(object, props)`\n\n### hooker.override\nWhen a pre- or post-hook returns the result of this function, the value\npassed will be used in place of the original function's return value. Any\npost-hook override value will take precedence over a pre-hook override value.\n#### Signature:\n`hooker.override(value)`\n\n### hooker.preempt\nWhen a pre-hook returns the result of this function, the value passed will\nbe used in place of the original function's return value, and the original\nfunction will NOT be executed.\n#### Signature:\n`hooker.preempt(value)`\n\n### hooker.filter\nWhen a pre-hook returns the result of this function, the context and\narguments passed will be applied into the original function.\n#### Signature:\n`hooker.filter(context, arguments)`\n\n\n## Examples\nSee the unit tests for more examples.\n\n```javascript\nvar hooker = require('hooker');\n// Simple logging.\nhooker.hook(Math, \"max\", function() {\n console.log(arguments.length + \" arguments passed\");\n});\nMath.max(5, 6, 7) // logs: \"3 arguments passed\", returns 7\n\nhooker.unhook(Math, \"max\"); // (This is assumed between all further examples)\nMath.max(5, 6, 7) // 7\n\n// Returning hooker.override(value) overrides the original value.\nhooker.hook(Math, \"max\", function() {\n if (arguments.length === 0) {\n return hooker.override(9000);\n }\n});\nMath.max(5, 6, 7) // 7\nMath.max() // 9000\n\n// Auto-unhook after one execution.\n
"readmeFilename": "README.md",
"_id": "hooker@0.2.3",
"_from": "hooker@>=0.2.3 <0.3.0"
}