{"id":23391425,"url":"https://github.com/ahrefs/ppx_deriving_variant_string","last_synced_at":"2025-04-11T09:59:10.375Z","repository":{"id":238449306,"uuid":"796541036","full_name":"ahrefs/ppx_deriving_variant_string","owner":"ahrefs","description":"OCaml PPX deriver that generates converters between regular or polymorphic variants and strings","archived":false,"fork":false,"pushed_at":"2024-05-16T08:22:01.000Z","size":15,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-03T00:17:03.855Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"OCaml","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/ahrefs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","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":"2024-05-06T06:37:58.000Z","updated_at":"2024-11-17T16:31:36.000Z","dependencies_parsed_at":"2024-05-16T09:35:15.003Z","dependency_job_id":null,"html_url":"https://github.com/ahrefs/ppx_deriving_variant_string","commit_stats":null,"previous_names":["ahrefs/ppx_deriving_variant_string"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahrefs%2Fppx_deriving_variant_string","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahrefs%2Fppx_deriving_variant_string/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahrefs%2Fppx_deriving_variant_string/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahrefs%2Fppx_deriving_variant_string/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahrefs","download_url":"https://codeload.github.com/ahrefs/ppx_deriving_variant_string/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248371969,"owners_count":21093132,"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-12-22T04:17:27.483Z","updated_at":"2025-04-11T09:59:10.360Z","avatar_url":"https://github.com/ahrefs.png","language":"OCaml","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ppx_deriving_variant_string\n\nOCaml PPX deriver that generates converters between regular or polymorphic\nvariants and strings. Supports both OCaml and Reason casing.\n\n## Quick Start\n\nInstall: `opam install ppx_deriving_variant_string`.\n\nIn Reason syntax:\n\n```reason\n[@deriving (fromString, toString)]\ntype foo =\n  | [@as \"first\"] First\n  | Second;\n\nlet a = fooFromString(\"first\"); /* Some(First) */\nlet b = fooFromString(\"Second\"); /* Some(Second) */\nlet c = fooFromString(\"First\"); /* None */\nlet d = fooToString(First); /* \"first\" */\nlet e = fooToString(Second); /* \"Second\" */\n```\n\nIn OCaml syntax:\n\n```ocaml\ntype foo =\n  | First [@as \"first\"]\n  | Second\n[@@deriving of_string, to_string]\n\nlet a = foo_of_string \"first\" (* Some(First) *)\nlet b = foo_of_string \"Second\" (* Some(Second) *)\nlet c = foo_of_string \"First\" (* None *)\nlet d = foo_to_string First (* \"first\" *)\nlet e = foo_to_string Second (* \"Second\" *)\n```\n\n## Name mangling\n\nIf the type where the PPX is applied is named `t`, the generated functions won't\ninclude any prefix and will be just `toString`, `fromString` (or `to_string`,\n`of_string`).\n\n## Why not ppx_deriving `show`?\n\nThe original `ppx_deriving` includes a plugin named\n[show](https://github.com/ocaml-ppx/ppx_deriving#plugin-show) which has some\noverlap in functionality. However it was missing a few things:\n\n- it doesn't include functionality to convert from strings to variants\n- `show`shows a backtick for polymorphic variants\n- it does support `as` (it's called `printer`), which supports cases with\n  variants with payloads, but it's a bit more heavyweight, as one has to pass a\n  formatter instead of just a\n  string, [example](https://github.com/ocaml-ppx/ppx_deriving/blob/35dfd4ad83e58bcfbc03b564e5fe6df06b6cbdd7/src_test/show/test_deriving_show.cppo.ml#L219)\n- `printer` is only supported in polyvars for some reason, but not on regular\n  variants, which was a feature we wanted to have\n\n## Why not Melange `jsConverter`?\n\nWe originally used Melange\n[jsConverter](https://melange.re/v2.0.0/communicate-with-javascript/#conversion-functions),\nbut we ran into limitations when making code compatible with [universal\nlibraries](https://melange.re/blog/posts/dune-universal-libraries-preview), that\nhave to run both on the client and the server.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahrefs%2Fppx_deriving_variant_string","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahrefs%2Fppx_deriving_variant_string","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahrefs%2Fppx_deriving_variant_string/lists"}