{"id":16858028,"url":"https://github.com/leeoniya/uexpr","last_synced_at":"2025-04-11T07:48:09.739Z","repository":{"id":207821023,"uuid":"720182296","full_name":"leeoniya/uExpr","owner":"leeoniya","description":"A conditional expression compiler","archived":false,"fork":false,"pushed_at":"2024-01-02T12:20:35.000Z","size":15,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-25T05:24:46.885Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/leeoniya.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":"2023-11-17T19:01:45.000Z","updated_at":"2024-12-03T13:12:33.000Z","dependencies_parsed_at":"2023-11-17T20:28:40.024Z","dependency_job_id":"9115a51c-87f5-454a-a569-e0a1ed6c4de9","html_url":"https://github.com/leeoniya/uExpr","commit_stats":null,"previous_names":["leeoniya/uexpr"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leeoniya%2FuExpr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leeoniya%2FuExpr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leeoniya%2FuExpr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leeoniya%2FuExpr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leeoniya","download_url":"https://codeload.github.com/leeoniya/uExpr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248359577,"owners_count":21090551,"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-13T14:11:15.537Z","updated_at":"2025-04-11T07:48:09.710Z","avatar_url":"https://github.com/leeoniya.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## μExpr\n\nA conditional expression compiler _(MIT Licensed)_\n\n---\n### Introduction\n\nμExpr is a compiler for conditional expressions and filters/matchers that can be stored in JSON.\nIt is similar in purpose to https://jsonlogic.com/ with the following differences:\n\n1. Simplified syntax, without objects\n2. Reduced scope that focuses on matching (emitting either `true` or `false`)\n3. Attains native (25x faster) runtime performance by using `new Function()` with carefully placed guards\n\n\u003c!-- https://react-querybuilder.js.org/demo --\u003e\n\n---\n### Example\n\n```js\nimport {\n  compileExpr,\n  compileMatcher,\n  compileFilter\n} from \"../src/uExpr.mjs\";\n\nlet matcher = compileMatcher(\n  ['||',\n    ['^', '.name', 'foo'],\n    ['\u0026\u0026',\n      ['==', '.meta.dataTopic', 'unsubscribe'],\n      ['some', '.fields', ['==', '.type', 'string']]\n    ],\n  ]\n);\n```\n\nIf you were to write this logic by hand it would look like this:\n\n```js\nlet matcher = ($, $i = 0) =\u003e (\n  $.name.startsWith(\"foo\") ||\n  (\n    $.meta.dataTopic == \"unsubscribe\" \u0026\u0026\n    $.fields.some(($, $i) =\u003e $.type == \"string\")\n  )\n);\n```\n\nNow you can use the compiled function as the callback to `Array.filter()`:\n\n```js\nlet frames = [\n  {\n    name: 'foobar',\n    meta: {\n      dataTopic: 'subscribe'\n    },\n    fields: [\n      {\n        type: 'number'\n      },\n    ]\n  },\n  {\n    name: 'something',\n    meta: {\n      dataTopic: 'unsubscribe'\n    },\n    fields: [\n      {\n        type: 'string'\n      },\n    ]\n  },\n  {\n    name: 'other',\n    meta: {\n      dataTopic: 'cancellation'\n    },\n    fields: [\n      {\n        type: 'string'\n      },\n    ]\n  },\n];\n\nlet filtered = frames.filter(matcher);\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleeoniya%2Fuexpr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleeoniya%2Fuexpr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleeoniya%2Fuexpr/lists"}