{"id":15637934,"url":"https://github.com/zkat/pattycake","last_synced_at":"2026-02-26T03:39:43.891Z","repository":{"id":57320902,"uuid":"126261142","full_name":"zkat/pattycake","owner":"zkat","description":"playground for pattern matching api","archived":false,"fork":false,"pushed_at":"2018-03-29T07:50:25.000Z","size":409,"stargazers_count":99,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"latest","last_synced_at":"2025-04-28T17:08:02.062Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/tc39/proposal-pattern-matching","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zkat.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-22T01:19:45.000Z","updated_at":"2025-04-15T15:12:39.000Z","dependencies_parsed_at":"2022-08-26T01:11:04.344Z","dependency_job_id":null,"html_url":"https://github.com/zkat/pattycake","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zkat%2Fpattycake","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zkat%2Fpattycake/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zkat%2Fpattycake/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zkat%2Fpattycake/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zkat","download_url":"https://codeload.github.com/zkat/pattycake/tar.gz/refs/heads/latest","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zkat%2Fpattycake/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259143562,"owners_count":22811903,"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","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-03T11:15:33.527Z","updated_at":"2026-02-26T03:39:43.861Z","avatar_url":"https://github.com/zkat.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pattycake [![npm version](https://img.shields.io/npm/v/pattycake.svg)](https://npm.im/pattycake) [![license](https://img.shields.io/npm/l/pattycake.svg)](https://npm.im/pattycake) [![Travis](https://img.shields.io/travis/zkat/pattycake.svg)](https://travis-ci.org/zkat/pattycake) [![AppVeyor](https://ci.appveyor.com/api/projects/status/github/zkat/pattycake?svg=true)](https://ci.appveyor.com/project/zkat/pattycake) [![Coverage Status](https://coveralls.io/repos/github/zkat/pattycake/badge.svg?branch=latest)](https://coveralls.io/github/zkat/pattycake?branch=latest)\n\n[`pattycake`](https://github.com/zkat/pattycake) is a little playground being\nused to prototype concepts surrounding the [TC39 pattern matching\nproposal](https://github.com/tc39/proposal-pattern-matching). It's not a spec,\nit's not a standard, and it doesn't represent the actual look and feel of the JS\nfeature. But it'll help figure out what that could actually be!\n\n## Install\n\n`$ npm install pattycake`\n\n## Table of Contents\n\n* [Example](#example)\n* [API](#api)\n\n### Example\n\n```javascript\nimport match, {$} from 'pattycake'\n\nconst res = await fetch(jsonService)\nconst val = match (res) (\n  {\n    status: 200,\n    headers: {'Content-Length': $}\n  }, ({\n    headers: {'Content-Length', s}}\n  ) =\u003e `size is ${s}`,\n  {status: 404}, () =\u003e 'JSON not found',\n  $({status: $}, ({status}) =\u003e status \u003e= 400), () =\u003e throw new RequestError(res)\n)\n```\n\n### API\n\nThis documentation described the sugared version of the `match` expression. The\nAPI exported by `pattycake` is similar, but uses functions and different syntax\nfor the same underlying concepts.\n\nTo convert a sugary `match` to a `pattycake` match:\n1. Replace the main `{}` pair with `()`\n2. Separate match clauses and bodies into matcher expressions and a fat arrow function, using the parameter list for the fat arrow for destructuring.\n3. Replace any variable clauses in the match side with `match.$`.\n4. If using guards, convert the guard to a function and pass it as the last argument to `match.$`. If you weren't already using `match.$` for a certain clause (because it wasn't necessary), wrap that clause with `match.$` and pass the guard function as the second argument.\n5. If using `...rest`s with array or object matchers, replace the `...rest` with `$.rest` and destructure the array in the fat arrow body.\n\n##### Example\n\n```js\nmatch (x) {\n  {a: 1, b} =\u003e ...,\n  [1, 2, ...etc] =\u003e ...,\n  1 =\u003e ...,\n  'string' =\u003e ...,\n  true =\u003e ...,\n  null =\u003e ...,\n  /regexhere/ =\u003e ...\n}\n\n// Converts to...\nconst $ = match.$\nmatch (x) (\n  {a: 1, b: $}, ({b}) =\u003e ...,\n  [1, 2, $.rest], ([a, b, ...etc]) =\u003e ...,\n  1, () =\u003e ...,\n  'string', () =\u003e ...,\n  true, () =\u003e ...,\n  null, () =\u003e ...,\n  /regexhere/, () =\u003e ...\n)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzkat%2Fpattycake","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzkat%2Fpattycake","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzkat%2Fpattycake/lists"}