{"id":26643684,"url":"https://github.com/kosich/babel-plugin-partial-expressions","last_synced_at":"2025-03-24T20:34:40.345Z","repository":{"id":57125480,"uuid":"362804966","full_name":"kosich/babel-plugin-partial-expressions","owner":"kosich","description":null,"archived":false,"fork":false,"pushed_at":"2021-05-14T20:02:46.000Z","size":686,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-11T18:05:54.980Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kosich.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-29T12:11:37.000Z","updated_at":"2021-05-14T20:02:48.000Z","dependencies_parsed_at":"2022-08-31T19:10:44.461Z","dependency_job_id":null,"html_url":"https://github.com/kosich/babel-plugin-partial-expressions","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kosich%2Fbabel-plugin-partial-expressions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kosich%2Fbabel-plugin-partial-expressions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kosich%2Fbabel-plugin-partial-expressions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kosich%2Fbabel-plugin-partial-expressions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kosich","download_url":"https://codeload.github.com/kosich/babel-plugin-partial-expressions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245349204,"owners_count":20600784,"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":"2025-03-24T20:34:39.581Z","updated_at":"2025-03-24T20:34:40.323Z","avatar_url":"https://github.com/kosich.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Partial Expressions - Babel plugin\n\nTry it in this **[babel playground](https://babeljs.io/repl#?browsers=defaults%2C%20not%20ie%2011%2C%20not%20ie_mob%2011\u0026build=\u0026builtIns=usage\u0026corejs=3.6\u0026spec=false\u0026loose=false\u0026code_lz=DYUwLgBAlgdgxhAvBAfhA-hA1BAjAbgCg4B7GAZxNADpgSBzACljkYBZcBKTow0SAA5QBIACZIIbAAwQAPgD4M2CACYipClRC0GjISNE8gA\u0026debug=false\u0026forceAllTransforms=false\u0026shippedProposals=false\u0026circleciRepo=\u0026evaluate=false\u0026fileSize=false\u0026timeTravel=false\u0026sourceType=module\u0026lineWrap=false\u0026presets=stage-0%2Cstage-1\u0026prettier=false\u0026targets=\u0026version=7.13.17\u0026externalPlugins=%40kosich%2Fbabel-plugin-partial-expressions-experiment%400.0.4)**.\n\nOr install it via\n\n```\nnpm i @kosich/babel-plugin-partial-expressions-experiment -D\n```\n\nAnd then add it to your `babel.config.json` as [described here](https://babeljs.io/docs/en/plugins).\n\n_NOTE: put it before pipeline operator plugins, if you use those._\n\n## About\n\nPartial expressions is a syntax sugar to simplify writing expression that are awating one additional variable.\n\nSyntax:\n- `_` is a placeholder for the value\n- `~` is used to mark partial expression root and is required whenever we use `_` (except for RHS pipes)\n\nExamples:\n\n```js\nlet bang = ~ _ + '!';\n// equals to\nlet bang = x =\u003e x + '!';\n```\n\nAs a partially applied function:\n\n```js\nlet bangLog = ~ console.log(_, '!');\n// equals to\nlet bangLog = x =\u003e console.log(x, '!');\n```\n\nAnd as a context of application:\n\n```js\nlet toBase16 = ~ _.toString(16);\n// equals to\nlet toBase16 = x =\u003e x.toString(16);\n```\n\nIt is also compatible with the [pipeline operator](https://github.com/tc39/proposal-pipeline-operator):\n\nI tried to cover a special case for **pipes**, when `_` is in RHS of a pipe. E.g:\n\n```js\nlet value = 42 |\u003e _ + 1 |\u003e console.log;\n// equals to\nlet value = 42 |\u003e (x =\u003e x + 1) |\u003e console.log;\n```\n\nSimilarly, we can do partial application:\n\n```js\n42 |\u003e console.log(_, '!');\n// equals to\n42 |\u003e (x =\u003e console.log(x, '!'));\n```\n\nAnd as a context:\n\n```js\n42 |\u003e _.toString(16) |\u003e _.toUpperCase();\n// equals to\n42 |\u003e (x =\u003e x.toString(16)) |\u003e (x =\u003e x.toUpperCase());\n```\n\n## Rules\n\n1. Expression is considered partial if an unbound `_` symbol is used in it.\n\n2. Expression boudaries are limited by following:\n\n    2.1 `~` operator\n    `let a = ~ _ + '!'` equals `let a = x =\u003e x + '!'`\n\n    2.2 RHS in pipeline operator    \n    `42 |\u003e _ + 1 |\u003e console.log` equals `42 |\u003e (x =\u003e x + 1) |\u003e console.log`\n\n## The End 🙂\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkosich%2Fbabel-plugin-partial-expressions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkosich%2Fbabel-plugin-partial-expressions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkosich%2Fbabel-plugin-partial-expressions/lists"}