{"id":23024447,"url":"https://github.com/thipages/bparser","last_synced_at":"2025-04-02T19:41:04.572Z","repository":{"id":136580026,"uuid":"352360115","full_name":"thipages/bparser","owner":"thipages","description":"A boolean expression parser","archived":false,"fork":false,"pushed_at":"2021-03-29T08:36:25.000Z","size":8,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-22T04:03:18.869Z","etag":null,"topics":["boolean","expression","parser"],"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/thipages.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":"2021-03-28T15:04:49.000Z","updated_at":"2021-09-13T02:10:41.000Z","dependencies_parsed_at":"2023-04-11T18:53:07.617Z","dependency_job_id":null,"html_url":"https://github.com/thipages/bparser","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thipages%2Fbparser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thipages%2Fbparser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thipages%2Fbparser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thipages%2Fbparser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thipages","download_url":"https://codeload.github.com/thipages/bparser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246720662,"owners_count":20822932,"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":["boolean","expression","parser"],"created_at":"2024-12-15T13:18:43.565Z","updated_at":"2025-04-02T19:41:04.549Z","avatar_url":"https://github.com/thipages.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bparser\n\nA boolean (OR, AND) expression parser\n\n## Installation\n- via npm : _npm i bparser_\n\n```javascript\nimport bparser from 'bparser';\n// then\nbparser(expression,regExp);\n\n```\n- via HTML\n```html\n\u003cscript src=\"min.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n    // then\n    bparser(expression,regExp);\n\u003c/script\u003e\n```\n## Usage\n```javscript\nconst pathsObjet = bparser(expression,regExp);\n```\n`expression` : String containing\n- comparison operator(s) : `AND,OR`\n- with optional opening/closing parentheses `(,)` \n- with items to be compared\n  \n`regExp` : RegExp allowing to identify the items to be compared\n\n`returns` an object with the following properties\n- `isValid`, a boolean for a valid/invalid expression\n- `results`, an array (`OR` list) of the different `AND` paths or an empty array of `isValid` is `false`\n\n\n## Examples\nRegExp: `/[a-z]/g`\n\nExpression                    | Results\n--------                      | ---------\n`a AND b`                     | `[[a, b]]`\n`a OR  b`                     | `[[a], [b]]`\n`a AND b AND c`               | `[[a, b, c]]`\n`a AND b OR  c`               | `[[a, b], [c]]`\n`a AND (b OR c)`              | `[[a, b], [a, c]]`\n`a AND (b OR c) AND (d OR e)` | `[[a, b, d], [a, b, e], [a, c, d], [a, c, e]]`\n\nRegExp: `/'.+?'/g`\n\nExpression                    | Results\n--------                      | ---------\n`\"'a' AND 'b' OR 'c'\" `         | `[\"'a'\",\"'b'\"],[\"'c'\"]`\n\n\n### More complex example\n\n###### Regex : `/[a-z]/g`\n###### Expression:\n```\n((a AND (b OR c)) AND (d AND e) AND (f OR g OR h)) OR i OR j\n```\n\n###### Results:\n```\n[[a,b,d,e,f],\n [a,c,d,e,f],\n [a,b,d,e,g],\n [a,c,d,e,g],\n [a,b,d,e,h],\n [a,c,d,e,h],\n [i],\n [j]]\n```\n## Related projects\n ###  [Boolean-parser](https://github.com/riichard/boolean-parser-js)\nThe majority of the examples comes from this other (and fun) implementation\n\n## Algorithm\nThe algorithm heavily relies on String and Regex.\nEven if the performance is slightly better than [Boolean-parser](https://github.com/riichard/boolean-parser-js), I think it can be dramatically improved considering:\n- one way analysis of the expression instead of two\n- better data structure for keeping states and merging them\n\nThis may have also an favorable impact on the LOC number.\n  \n... to be continued","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthipages%2Fbparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthipages%2Fbparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthipages%2Fbparser/lists"}