{"id":17922597,"url":"https://github.com/rreverser/xmatch","last_synced_at":"2025-09-21T03:31:04.476Z","repository":{"id":66153588,"uuid":"131637871","full_name":"RReverser/xmatch","owner":"RReverser","description":"Simple pattern matching for ES6","archived":false,"fork":false,"pushed_at":"2018-05-01T10:06:08.000Z","size":16,"stargazers_count":102,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-04T20:09:31.716Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/xmatch","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RReverser.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-30T19:30:10.000Z","updated_at":"2023-10-12T05:45:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"9b4713e9-756b-45d9-a2a8-f12f117eac9a","html_url":"https://github.com/RReverser/xmatch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/RReverser/xmatch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RReverser%2Fxmatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RReverser%2Fxmatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RReverser%2Fxmatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RReverser%2Fxmatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RReverser","download_url":"https://codeload.github.com/RReverser/xmatch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RReverser%2Fxmatch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276189884,"owners_count":25600280,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-21T02:00:07.055Z","response_time":72,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-28T20:39:56.437Z","updated_at":"2025-09-21T03:31:04.208Z","avatar_url":"https://github.com/RReverser.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# xmatch\n\nSimple pattern matching for ES6 (no transpilation!)\n\n## Property matching\n\n```javascript\nconst { match } = require('xmatch');\n\nmatch(obj, [\n\t({ x }) =\u003e console.log('x', x),\n\t({ y }) =\u003e console.log('y', y),\n\t({ z }) =\u003e console.log('z', z),\n\t// Exhaustive match; will throw `xmatch.UnmatchedPatternError` unless uncommented:\n\t// other =\u003e console.error('Something else', other),\n]);\n```\n\n## Iterable matching\n\n```javascript\nconst { match } = require('xmatch');\n\nmatch(arr, [\n\t([]) =\u003e 'empty',\n\t([x]) =\u003e `x=${x}`,\n\t([x, y]) =\u003e `x=${x},y=${y}`,\n\t([x, y, ...{ length }]) =\u003e `x=${x},y=${y},rest.length=${length}`,\n]);\n```\n\n## Custom guards\n\n```javascript\nconst { match, guard } = require('xmatch');\n\nmatch(obj, [\n\t({ command }) =\u003e {\n\t\t// When you want to match simple values:\n\t\tguard(command === 'ignore');\n\t\t/* Do nothing */\n\t},\n\t({ command }) =\u003e {\n\t\t// Or, say, match result of regex:\n\t\tlet [, name, args] = guard(command.match(/^(\\w+):(.*)$/));\n\t\tconsole.log({ name, args });\n\t},\n\t({ command }) =\u003e {\n\t\tthrow new Error(`Invalid command: ${command}`);\n\t},\n]);\n```\n\n## Shape assertions\n\n```javascript\nconst { guard } = require('xmatch');\n\nconst { x, y } = guard({ x: 1, y: 2 }); // OK\nconst { x, y } = guard({ x: 1, z: 2 }); // throws `xmatch.UnmatchedPatternError`\n```\n\n## Known issues\n\n*   You can't use literals directly in patterns (this is limitation of ES6 syntax, can be fixed as part of https://github.com/tc39/proposal-pattern-matching).\n*   You can't use default values for parameters. This is limitation of the way matching is implemented, and you'll have to resolve defaults yourself if that's what you want.\n*   Trying to further destructure or access undefined properties of an object will also trigger the match guard ([#1](https://github.com/RReverser/xmatch/issues/1)). This is tricky to workaround without changing the syntax, but I'll look into it (and happy to hear any suggestions).\n*   This uses dynamic metaprogramming via [`Proxy`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) which might have undesirable performance effect on hot code paths. If your benchmarks suggest it's causing critical performance issues, consider using transpiler plugins instead.\n*   `Proxy` is not implemented in pre-ES6 browsers and can't be polyfilled, so use this only if you're okay with the supported target set: https://caniuse.com/#feat=proxy\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frreverser%2Fxmatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frreverser%2Fxmatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frreverser%2Fxmatch/lists"}