{"_id":"call-matcher","_rev":"199772","name":"call-matcher","description":"ECMAScript CallExpression matcher made from function/method signature","dist-tags":{"latest":"2.0.0"},"maintainers":[{"name":"twada","email":"takuto.wada@gmail.com"}],"time":{"modified":"2021-06-03T12:31:03.000Z","created":"2015-12-22T16:18:56.711Z","2.0.0":"2019-01-21T07:28:10.976Z","1.1.0":"2018-08-23T06:31:41.400Z","1.0.1":"2016-12-31T02:43:40.164Z","1.0.0":"2016-05-28T03:24:46.797Z","0.1.0":"2015-12-22T16:18:56.711Z"},"users":{},"author":{"name":"Takuto Wada","email":"takuto.wada@gmail.com","url":"https://github.com/twada"},"repository":{"type":"git","url":"git://github.com/twada/call-matcher.git"},"versions":{"2.0.0":{"name":"call-matcher","description":"ECMAScript CallExpression matcher made from function/method signature","version":"2.0.0","author":{"name":"Takuto Wada","email":"takuto.wada@gmail.com","url":"https://github.com/twada"},"bugs":{"url":"https://github.com/twada/call-matcher/issues"},"contributors":[{"name":"Renée Kooi","url":"https://github.com/goto-bus-stop"}],"dependencies":{"deep-equal":"^1.0.0","espurify":"^2.0.0","estraverse":"^4.0.0"},"devDependencies":{"babel-types":"^6.3.21","babylon":"^6.3.21","esprima":"^4.0.0","mocha":"^5.0.0","semistandard":"^13.0.1","snazzy":"^8.0.0"},"homepage":"https://github.com/twada/call-matcher","keywords":["ast","estree","ecmascript"],"license":"MIT","main":"index.js","repository":{"type":"git","url":"git://github.com/twada/call-matcher.git"},"scripts":{"preversion":"npm test","lint":"semistandard --verbose index.js test/test.js | snazzy","fmt":"semistandard --fix index.js test/test.js","test":"npm run lint && mocha test"},"semistandard":{"ignore":["/bench/","**/*.jsx"],"globals":["describe","beforeEach","it"]},"gitHead":"58d8cea9d857d1d7801ddc257f2ec10c33269c58","_id":"call-matcher@2.0.0","_npmVersion":"6.4.1","_nodeVersion":"10.15.0","_npmUser":{"name":"twada","email":"takuto.wada@gmail.com"},"dist":{"shasum":"a38bee4e9ddbeec76aa31cc20311085a34dd395b","size":5359,"noattachment":false,"key":"/call-matcher/-/call-matcher-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/call-matcher/download/call-matcher-2.0.0.tgz"},"maintainers":[{"name":"twada","email":"takuto.wada@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/call-matcher_2.0.0_1548055690838_0.2533766183394546"},"_hasShrinkwrap":false,"publish_time":1548055690976,"_cnpm_publish_time":1548055690976},"1.1.0":{"name":"call-matcher","description":"ECMAScript CallExpression matcher made from function/method signature","version":"1.1.0","author":{"name":"Takuto Wada","email":"takuto.wada@gmail.com","url":"https://github.com/twada"},"bugs":{"url":"https://github.com/twada/call-matcher/issues"},"dependencies":{"core-js":"^2.0.0","deep-equal":"^1.0.0","espurify":"^1.6.0","estraverse":"^4.0.0"},"devDependencies":{"babel-types":"^6.3.21","babylon":"^6.3.21","browserify":"^13.0.0","derequire":"^2.0.2","dereserve":"^1.0.0","esprima":"^4.0.0","jshint":"^2.8.0","licensify":"^3.1.1","mocha":"^5.0.0","package-json-filterify":"^1.0.4"},"files":["CHANGELOG.md","MIT-LICENSE.txt","README.md","index.js","dist/call-matcher.js"],"homepage":"https://github.com/twada/call-matcher","keywords":["ast","estree","ecmascript"],"license":"MIT","main":"index.js","repository":{"type":"git","url":"git://github.com/twada/call-matcher.git"},"scripts":{"dist":"mkdir -p dist && browserify index.js --plugin licensify --global-transform package-json-filterify --standalone CallMatcher | dereserve | derequire > ./dist/call-matcher.js","lint":"jshint index.js","preversion":"npm test","test":"npm run lint && mocha test","version":"npm run dist && git add -A dist"},"gitHead":"76f5dc2aedc7842b8f67adb512582e4621b40c6f","_id":"call-matcher@1.1.0","_npmVersion":"6.1.0","_nodeVersion":"10.7.0","_npmUser":{"name":"twada","email":"takuto.wada@gmail.com"},"dist":{"shasum":"23b2c1bc7a8394c8be28609d77ddbd5786680432","size":27597,"noattachment":false,"key":"/call-matcher/-/call-matcher-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/call-matcher/download/call-matcher-1.1.0.tgz"},"maintainers":[{"name":"twada","email":"takuto.wada@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/call-matcher_1.1.0_1535005901292_0.9986392392495471"},"_hasShrinkwrap":false,"publish_time":1535005901400,"_cnpm_publish_time":1535005901400},"1.0.1":{"name":"call-matcher","description":"ECMAScript CallExpression matcher made from function/method signature","version":"1.0.1","author":{"name":"Takuto Wada","email":"takuto.wada@gmail.com","url":"https://github.com/twada"},"bugs":{"url":"https://github.com/twada/call-matcher/issues"},"dependencies":{"core-js":"^2.0.0","deep-equal":"^1.0.0","espurify":"^1.6.0","estraverse":"^4.0.0"},"devDependencies":{"babel-types":"^6.3.21","babylon":"^6.3.21","browserify":"^13.0.0","derequire":"^2.0.2","dereserve":"^1.0.0","esprima":"^3.0.0","jshint":"^2.8.0","licensify":"^3.1.1","mocha":"^3.0.0","package-json-filterify":"^1.0.4"},"files":["CHANGELOG.md","MIT-LICENSE.txt","README.md","index.js","dist/call-matcher.js"],"homepage":"https://github.com/twada/call-matcher","keywords":["ast","estree","ecmascript"],"license":"MIT","main":"index.js","repository":{"type":"git","url":"git://github.com/twada/call-matcher.git"},"scripts":{"dist":"mkdir -p dist && browserify index.js --plugin licensify --global-transform package-json-filterify --standalone CallMatcher | dereserve | derequire > ./dist/call-matcher.js","lint":"jshint index.js","preversion":"npm test","test":"npm run lint && mocha test","version":"npm run dist && git add -A dist"},"gitHead":"3d605c0298339dd8104dcdaa6c8a639bd1eaca81","_id":"call-matcher@1.0.1","_shasum":"5134d077984f712a54dad3cbf62de28dce416ca8","_from":".","_npmVersion":"3.10.9","_nodeVersion":"7.1.0","_npmUser":{"name":"twada","email":"takuto.wada@gmail.com"},"maintainers":[{"name":"twada","email":"takuto.wada@gmail.com"}],"dist":{"shasum":"5134d077984f712a54dad3cbf62de28dce416ca8","size":20219,"noattachment":false,"key":"/call-matcher/-/call-matcher-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/call-matcher/download/call-matcher-1.0.1.tgz"},"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/call-matcher-1.0.1.tgz_1483152219928_0.46611776761710644"},"directories":{},"publish_time":1483152220164,"_cnpm_publish_time":1483152220164,"_hasShrinkwrap":false},"1.0.0":{"name":"call-matcher","description":"ECMAScript CallExpression matcher made from function/method signature","version":"1.0.0","author":{"name":"Takuto Wada","email":"takuto.wada@gmail.com","url":"https://github.com/twada"},"bugs":{"url":"https://github.com/twada/call-matcher/issues"},"dependencies":{"core-js":"^2.0.0","deep-equal":"^1.0.0","espurify":"^1.6.0","estraverse":"^4.0.0"},"devDependencies":{"babel-types":"^6.3.21","babylon":"^6.3.21","browserify":"^13.0.0","derequire":"^2.0.2","dereserve":"^0.1.1","esprima":"^2.0.0","jshint":"2.8.0","licensify":"^3.1.1","mocha":"^2.3.3"},"files":["CHANGELOG.md","MIT-LICENSE.txt","README.md","index.js","dist/call-matcher.js"],"homepage":"https://github.com/twada/call-matcher","keywords":["ast","estree","ecmascript"],"license":"MIT","main":"index.js","repository":{"type":"git","url":"git://github.com/twada/call-matcher.git"},"scripts":{"dist":"mkdir -p dist && browserify index.js --plugin licensify --standalone CallMatcher | dereserve | derequire > ./dist/call-matcher.js","lint":"jshint index.js","preversion":"npm test","test":"npm run lint && mocha test","version":"npm run dist && git add -A dist"},"gitHead":"14a2787fe81c2679f6db33840f8001aae91b0cf3","_id":"call-matcher@1.0.0","_shasum":"eafa31036dbfaa9c0d1716f12ddacfd9c69ef22f","_from":".","_npmVersion":"3.8.6","_nodeVersion":"6.1.0","_npmUser":{"name":"twada","email":"takuto.wada@gmail.com"},"maintainers":[{"name":"twada","email":"takuto.wada@gmail.com"}],"dist":{"shasum":"eafa31036dbfaa9c0d1716f12ddacfd9c69ef22f","size":19131,"noattachment":false,"key":"/call-matcher/-/call-matcher-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/call-matcher/download/call-matcher-1.0.0.tgz"},"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/call-matcher-1.0.0.tgz_1464405886273_0.13457019766792655"},"directories":{},"publish_time":1464405886797,"_cnpm_publish_time":1464405886797,"_hasShrinkwrap":false},"0.1.0":{"name":"call-matcher","description":"ECMAScript CallExpression matcher made from function/method signature","version":"0.1.0","author":{"name":"Takuto Wada","email":"takuto.wada@gmail.com","url":"https://github.com/twada"},"bugs":{"url":"https://github.com/twada/call-matcher/issues"},"dependencies":{"array-filter":"^1.0.0","array-foreach":"^1.0.1","array-map":"0.0.0","array-reduce":"0.0.0","deep-equal":"^1.0.0","espurify":"^1.5.0","estraverse":"^4.0.0","indexof":"0.0.1"},"devDependencies":{"babel-types":"^6.3.21","babylon":"^6.3.21","browserify":"^12.0.1","derequire":"^2.0.2","dereserve":"^0.1.1","esprima":"^2.0.0","jshint":"2.8.0","licensify":"^2.0.1","mocha":"^2.3.3"},"files":["CHANGELOG.md","MIT-LICENSE.txt","README.md","index.js","dist/call-matcher.js"],"homepage":"https://github.com/twada/call-matcher","keywords":["ast","estree","ecmascript"],"license":"MIT","main":"index.js","repository":{"type":"git","url":"git://github.com/twada/call-matcher.git"},"scripts":{"dist":"mkdir dist && browserify index.js --plugin licensify --standalone CallMatcher | dereserve | derequire > ./dist/call-matcher.js","lint":"jshint index.js","preversion":"npm test","test":"npm run lint && mocha test","version":"npm run dist && git add -A dist"},"gitHead":"af94b09dc5c9127ec4e5b897f5bfa26a61de216e","_id":"call-matcher@0.1.0","_shasum":"d7bd2d3a6b149f186b1e678e17d7c0a16b77fc33","_from":".","_npmVersion":"3.3.12","_nodeVersion":"5.1.0","_npmUser":{"name":"twada","email":"takuto.wada@gmail.com"},"maintainers":[{"name":"twada","email":"takuto.wada@gmail.com"}],"dist":{"shasum":"d7bd2d3a6b149f186b1e678e17d7c0a16b77fc33","size":16550,"noattachment":false,"key":"/call-matcher/-/call-matcher-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/call-matcher/download/call-matcher-0.1.0.tgz"},"directories":{},"publish_time":1450801136711,"_cnpm_publish_time":1450801136711,"_hasShrinkwrap":false}},"readme":"call-matcher\n================================\n\nECMAScript CallExpression matcher made from function/method signature\n\n[![Build Status][travis-image]][travis-url]\n[![NPM version][npm-image]][npm-url]\n[![Code Style][style-image]][style-url]\n[![License][license-image]][license-url]\n\n\nEXAMPLE\n---------------------------------------\n\nCreating CallExpression matcher for method signature `'assert.equal(actual, expected, [message])'`.\n\nThen match against `path/to/some_test.js`.\n\n```javascript\nvar CallMatcher = require('call-matcher');\nvar esprima = require('esprima');\nvar estraverse = require('estraverse');\nvar fs = require('fs');\n\nvar ast = esprima.parse('assert.equal(actual, expected, [message])');\nvar expression = ast.body[0].expression;\nvar matcher = new CallMatcher(expression);\n\nestraverse.traverse(esprima.parse(fs.readFileSync('path/to/some_test.js')), {\n    enter: function (currentNode, parentNode) {\n        if (matcher.test(currentNode)) {\n            // currentNode is a CallExpression that matches to the signature\n        }\n        var argMatched = matcher.matchArgument(currentNode, parentNode);\n        if (argMatched) {\n            if (argMatched.kind === 'mandatory') {\n                // mandatory arg (in this case, `actual` or `expected`)\n            } else if (argMatched.kind === 'optional') {\n                // optional arg (in this case, `message`)\n            }\n        }\n    }\n});\n```\n\nwhere content of `path/to/some_test.js` is:\n\n```javascript\nvar assert = require('assert');\nvar anotherAssert = assert;\nvar equal = assert.equal.bind(assert);\nvar foo = '2';\nvar bar = 2;\n\nassert.equal(foo, bar);  // matches\nassert.equal(bar, foo);  // matches\nassert.equal(foo, bar, 'foo shoule be equal to bar');  // matches (with optional arg)\n\nassert.equal();  // does not match (less args)\nassert.equal(foo);  // does not match (less args)\nassert.equal(foo, bar, 'hoge', 'fuga');  // does not match (too much args)\n\nassert.notEqual(foo, bar);  // does not match (callee method name differs)\nanotherAssert.equal(foo, bar);  // does not match (callee object name differs)\nequal(foo, bar);  // does not match (callee does not match)\n```\n\n`call-matcher` is a spin-off product of [power-assert](https://github.com/twada/power-assert) project.\n\nPull-requests, issue reports and patches are always welcomed.\n\n\nAPI\n---------------------------------------\n\n### var matcher = new CallMatcher(signatureAst, [options])\n\nCreate matcher object for a given expression.\n\n```javascript\nvar ast = esprima.parse('assert.equal(actual, expected, [message])');\nvar expression = ast.body[0].expression;\nvar matcher = new CallMatcher(expression);\n```\n\nAny signature string enclosed in bracket (for example, `[message]`) means optional parameters. Without bracket means mandatory parameters.\n\nReturns `matcher` object having four methods, `test`, `matchArgument`, `calleeAst`, and `argumentSignatures`.\n\n\n#### options\n\nan `object` for configuration options. If not passed, default options will be used.\n\n\n#### options.visitorKeys\n\n| type     | default value |\n|:---------|:--------------|\n| `object` | (return value of `estraverse.VisitorKeys`)   |\n\nVisitorKeys for AST traversal. See [estraverse.VisitorKeys](https://github.com/estools/estraverse/blob/4.0.0/estraverse.js#L217-L288) and [babel.types.VISITOR_KEYS](https://github.com/babel/babel/blob/v5.1.11/src/babel/types/visitor-keys.json).\n\n\n#### options.astWhiteList\n\n| type     | default value |\n|:---------|:--------------|\n| `object` | N/A           |\n\nType and property whitelist on creating AST clone. `astWhiteList` is an object containing NodeType as keys and properties as values.\n\n```js\n{\n    ArrayExpression: ['type', 'elements'],\n    ArrayPattern: ['type', 'elements'],\n    ArrowFunctionExpression: ['type', 'id', 'params', 'body', 'generator', 'expression'],\n    AssignmentExpression: ['type', 'operator', 'left', 'right'],\n    ...\n```\n\n\n### var isMatched = matcher.test(node)\n\nTests whether `node` matches the signature or not.\n\n - Returns `true` if matched.\n - Returns `false` if not matched.\n\n`node` should be an AST node object defined in [The ESTree Spec](https://github.com/estree/estree) (formerly known as [Mozilla SpiderMonkey Parser API](https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API)).\n\n\n### var argMatched = matcher.matchArgument(node, parentNode)\n\nReturns match result object representing whether `node` (and its `parentNode`) matches some argument of the signature or not.\n\n - Returns `null` if not matched.\n - If matched, returns object like `{index: 0, name: 'actual', kind: 'mandatory'}`, whose `index` is an index of matched argument, `name` is an argument name in the signature and `kind` is `'mandatory'` or `'optional'`.\n\n`node` and `parentNode` should be AST node objects defined in [The ESTree Spec](https://github.com/estree/estree) (formerly known as [Mozilla SpiderMonkey Parser API](https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API)).\n\n\n### var calleeAst = matcher.calleeAst()\n\nReturns clone of callee AST object based on signature passed to `CallMatcher` function. Returned tree is one of AST node objects defined in [The ESTree Spec](https://github.com/estree/estree) (formerly known as [Mozilla SpiderMonkey Parser API](https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API)) (in most cases, `Identifier` or `MemberExpression`).\n\n\n### var argSigs = matcher.argumentSignatures()\n\nReturns array of argument signature objects based on signature passed to `CallMatcher` function. Returns array of objects like `[{index: 0, name: 'actual', kind: 'mandatory'}]`, whose `index` is an index of matched argument, `name` is an argument name in the signature and `kind` is `'mandatory'` or `'optional'`.\n\n\n\nINSTALL\n---------------------------------------\n\n### via npm\n\nInstall\n\n    $ npm install --save call-matcher\n\n\nCHANGELOG\n---------------------------------------\nSee [CHANGELOG](https://github.com/twada/call-matcher/blob/master/CHANGELOG.md)\n\n\nAUTHOR\n---------------------------------------\n* [Takuto Wada](https://github.com/twada)\n\n\nCONTRIBUTORS\n---------------------------------------\n* [Renée Kooi](https://github.com/goto-bus-stop)\n\n\nLICENSE\n---------------------------------------\nLicensed under the [MIT](https://github.com/twada/call-matcher/blob/master/MIT-LICENSE.txt) license.\n\n\n[npm-url]: https://npmjs.org/package/call-matcher\n[npm-image]: https://badge.fury.io/js/call-matcher.svg\n\n[travis-url]: https://travis-ci.org/twada/call-matcher\n[travis-image]: https://secure.travis-ci.org/twada/call-matcher.svg?branch=master\n\n[style-url]: https://github.com/Flet/semistandard\n[style-image]: https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg\n\n[license-url]: https://github.com/twada/call-matcher/blob/master/MIT-LICENSE.txt\n[license-image]: https://img.shields.io/badge/license-MIT-brightgreen.svg\n","_attachments":{},"homepage":"https://github.com/twada/call-matcher","bugs":{"url":"https://github.com/twada/call-matcher/issues"},"license":"MIT"}