{"name":"f-matches","version":"1.0.0","description":"Composable version of Lodash.matches()","main":"index.js","scripts":{"lint":"eslint source.js","test":"mocha --compilers js:babel-register test.js","prepublish":"babel matches.js --out-file index.js"},"engines":{"node":">=4"},"files":["index.js"],"repository":{"type":"git","url":"git+https://github.com/nene/f-matches.git"},"keywords":["lodash","utility","pattern-matching"],"author":{"name":"Rene Saarsoo","email":"nene@triin.net"},"license":"MIT","bugs":{"url":"https://github.com/nene/f-matches/issues"},"homepage":"https://github.com/nene/f-matches","dependencies":{"lodash":"^4.17.5"},"devDependencies":{"babel-cli":"^6.26.0","babel-preset-env":"^1.6.1","babel-register":"^6.26.0","chai":"^4.1.2","eslint":"^4.19.1","mocha":"^5.0.5"},"gitHead":"261a01a4fa6392bb76c158b7feadb702d81bc870","_id":"f-matches@1.0.0","_shasum":"ecefa35a153c1e0bd0d094d2f21b17a5543314fe","_from":".","_npmVersion":"3.10.10","_nodeVersion":"6.11.1","_npmUser":{"name":"nene","email":"npm@triin.net"},"dist":{"shasum":"ecefa35a153c1e0bd0d094d2f21b17a5543314fe","tarball":"http://registry-npm.ywwl.com/f-matches/download/f-matches-1.0.0.tgz","fileCount":4,"unpackedSize":7523,"integrity":"sha512-SQ1a7dRXpR7iOaSh6D9tMXRUQs8zxKH1LvhSxMMDz/RGvfXGbhx/HTwf3IVu6vMHOSc9YBefBI6kUgo/Ec+0iw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDxPVnkXNO5VFeFCZzTWfEpXml1DiNcGSTAL68GTga+rwIhAKzFUxMRDisIo75TciGqsvlfvza6iXst29RxnIgweYNm"}],"size":3203,"noattachment":false,"key":"/f-matches/-/f-matches-1.0.0.tgz"},"maintainers":[{"name":"nene","email":"npm@triin.net"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/f-matches_1.0.0_1522607385166_0.36838967970964576"},"_hasShrinkwrap":false,"readme":"# f-matches: Composable version of Lodash.matches()\n\nAn utility used by [Lebab][] for complex matching of AST nodes.\n\nThe package exports 4 curried functions:\n\n- `matches :: Pattern -> Obj -> (Bool|Obj)`\n- `extract :: Name -> Pattern -> Obj -> (Bool|Obj)`\n- `extractAny :: Name -> Obj -> (Bool|Obj)`\n- `matchesLength :: Pattern -> Array -> (Bool|Obj)`\n\nFor details, just read the source, it's really small.\n\nAlternatively, [read how Lebab uses this for patterns in syntax trees.][lebab-blog]\n\n## Example\n\n```js\nimport {matches, matchesLength, extract} from \"f-matches\";\n\n// Function for matching string literal\nconst isStringLiteral = matches({\n    \"type\": \"Literal\",\n    // Unlike in Lodash.matches(),\n    // we can provide a function to assert if object field matches.\n    \"value\": (v) => typeof v === 'string',\n});\n\n// Function for matching: <local> = require(<source>)\nconst isRequireDeclarator = matches({\n    \"type\": \"VariableDeclarator\",\n    // Store the matching identifier under key: \"local\"\n    \"id\": extract(\"local\", {\n        \"type\": \"Identifier\",\n    }),\n    \"init\": {\n        \"type\": \"CallExpression\",\n        \"callee\": {\n            \"type\": \"Identifier\",\n            \"name\": \"require\"\n        },\n        \"arguments\": matchesLength([\n            // Store the matching string literal under key: \"source\"\n            extract(\"source\", isStringLiteral),\n        ]),\n    },\n});\n\n// Function for matching: var <local> = require(<source>)\nconst isRequire = matches({\n    \"type\": \"VariableDeclaration\",\n    // Match array of exactly 1 element (not 1 or more elements, which is the default)\n    \"declarations\": matchesLength([\n        isRequireDeclarator,\n    ]),\n    \"kind\": \"var\",\n});\n\n// Transform require() call to ES6 import statement.\nestraverse.replace(ast, {\n    enter(node) {\n        const match = isRequire(node);\n        if (match) {\n            return {\n                \"type\": \"ImportDeclaration\",\n                \"specifiers\": [\n                    {\n                        \"type\": \"ImportDefaultSpecifier\",\n                        \"local\": match.local\n                    }\n                ],\n                \"source\": match.source\n            };\n        }\n    }\n});\n```\n\n[Lebab]: https://github.com/lebab/lebab\n[lebab-blog]: http://nene.github.io/2016/04/02/matches-ast\n","publish_time":1522607385286,"_cnpm_publish_time":1522607385286,"dist-tags":{"latest":"1.1.0"}}