{"_id":"f-matches","_rev":"1720572","name":"f-matches","description":"Composable version of Lodash.matches()","dist-tags":{"latest":"1.1.0"},"maintainers":[{"name":"nene","email":"npm@triin.net"}],"time":{"modified":"2026-11-10T20:54:32.000Z","created":"2018-04-01T18:29:45.286Z","1.1.0":"2018-04-25T08:16:19.212Z","1.0.0":"2018-04-01T18:29:45.286Z"},"users":{},"author":{"name":"Rene Saarsoo","email":"nene@triin.net"},"repository":{"type":"git","url":"git+https://github.com/nene/f-matches.git"},"versions":{"1.1.0":{"name":"f-matches","version":"1.1.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":"e4801677a681ab551e047ab6914ed97bd6fb073e","_id":"f-matches@1.1.0","_shasum":"18e98545000bf381007b7a9f99a69eed0d304336","_from":".","_npmVersion":"3.10.10","_nodeVersion":"6.13.1","_npmUser":{"name":"nene","email":"npm@triin.net"},"dist":{"shasum":"18e98545000bf381007b7a9f99a69eed0d304336","tarball":"http://registry-npm.ywwl.com/f-matches/download/f-matches-1.1.0.tgz","fileCount":4,"unpackedSize":8002,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJa4DlUCRA9TVsSAnZWagAATv8P/jtInaJD1MQvKOLChbOD\nv6Lv4jot9vbpq7Y9GJL3LRheQBIWQm23mDt29hILw2Xaz9dsUtsZp3FPXsLg\nnwdjyvhPq7baOfCzhH50fEGzZNpRWojCSkeQPJlba6IKK1jYLuz2ElVNlEY7\nhNMSiHKas5F/V0yoFRczyfjZfRM26lhqCE0hgqQOtNy/gFSfp7xv/3tGSHeU\nAJlIuXPjt8bz9pCxNWq2nLF8FL6myqia+2UHhherJFxjbm4VY8lQkqlz2yIX\nw72oC+yc/RwexSsdo30ONggNS0peRGyAKVesg5nj+5wIAMRq07UCNm1FxKY3\nS1XSadjkPF5m0z5CvJUvrVq7qTV0M0ZIOa1tcrL2FCCo6p5pl5smaTc3MukE\nEdvfzAZRGD871s4srmfE4gn2XRamUYrkoSs4REaJ5Hpfb4+GTJtgrkQ8ycTn\nxCx0jINluDceve3Ossr4t/rp1KtncO9Ej9+pInKXpPy5SqvU/+13BBb9/l91\nOYYPrLKG0XCbnwV+b/jC1334TG55OwwQr0SkQgHyq64k38bS0RksfWNgFgKE\niGLkOX0ivU/0FMe6cxvuKc4rwHMBY0gcDM9scZ4Y6DXrYWlBtKOTaJW64CNm\nmU8vTdNpkjQpZpF/64NyepQBJ8j3yt7odpGR5P3aasCEnPbgopHXIj8XjKbj\nsNUX\r\n=u85v\r\n-----END PGP SIGNATURE-----\r\n","integrity":"sha512-8NALQS5oB1+9hkEwiRjsRroTAQ7zKmXjxe0ZcMHDRrFIR54PhSJp7Rm+Q5+tgJ7eO5ejCgbUPNXeiflX18Rt0Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIG/KlSELTQRgdnWMHjRP0qDxPTSwzCvOpmkFs+d/7oayAiEAmk1+6pS/Xt7Zc3CDtzp06JtmfiY6buKyyV5O2BuP8eM="}],"size":3292,"noattachment":false,"key":"/f-matches/-/f-matches-1.1.0.tgz"},"maintainers":[{"name":"nene","email":"npm@triin.net"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/f-matches_1.1.0_1524644179070_0.6297330513007178"},"_hasShrinkwrap":false,"publish_time":1524644179212,"_cnpm_publish_time":1524644179212},"1.0.0":{"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,"publish_time":1522607385286,"_cnpm_publish_time":1522607385286}},"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","_attachments":{},"homepage":"https://github.com/nene/f-matches","bugs":{"url":"https://github.com/nene/f-matches/issues"},"license":"MIT"}