{"id":21261509,"url":"https://github.com/chenasraf/search-ast-parser-js","last_synced_at":"2026-04-21T16:33:29.900Z","repository":{"id":160079086,"uuid":"524537155","full_name":"chenasraf/search-ast-parser-js","owner":"chenasraf","description":"Easy parser for search query strings, for you to use in your filters.","archived":false,"fork":false,"pushed_at":"2023-05-02T21:53:16.000Z","size":348,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-27T20:43:40.998Z","etag":null,"topics":["ast","ast-parser","javascript","parser","search-query","typescript"],"latest_commit_sha":null,"homepage":"https://chenasraf.github.io/search-ast-parser-js/","language":"TypeScript","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/chenasraf.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"chenasraf","patreon":null,"open_collective":null,"ko_fi":"casraf","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":["https://www.paypal.com/cgi-bin/webscr?cmd=_donations\u0026business=TSH3C3ABGQM22\u0026currency_code=ILS\u0026source=url"]}},"created_at":"2022-08-14T00:20:37.000Z","updated_at":"2023-05-01T21:35:18.000Z","dependencies_parsed_at":"2023-05-14T04:00:18.985Z","dependency_job_id":null,"html_url":"https://github.com/chenasraf/search-ast-parser-js","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/chenasraf/search-ast-parser-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenasraf%2Fsearch-ast-parser-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenasraf%2Fsearch-ast-parser-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenasraf%2Fsearch-ast-parser-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenasraf%2Fsearch-ast-parser-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chenasraf","download_url":"https://codeload.github.com/chenasraf/search-ast-parser-js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenasraf%2Fsearch-ast-parser-js/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32100153,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-21T11:25:29.218Z","status":"ssl_error","status_checked_at":"2026-04-21T11:25:28.499Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["ast","ast-parser","javascript","parser","search-query","typescript"],"created_at":"2024-11-21T04:43:37.322Z","updated_at":"2026-04-21T16:33:29.881Z","avatar_url":"https://github.com/chenasraf.png","language":"TypeScript","funding_links":["https://github.com/sponsors/chenasraf","https://ko-fi.com/casraf","https://www.paypal.com/cgi-bin/webscr?cmd=_donations\u0026business=TSH3C3ABGQM22\u0026currency_code=ILS\u0026source=url"],"categories":[],"sub_categories":[],"readme":"\u003ch1\u003eSearch Query AST Parser for JS\u003c/h1\u003e\n\n[NPM](https://www.npmjs.com/package/search-parse) |\n[Documentation](https://chenasraf.github.io/search-ast-parser-js)\n\nThis is a package for JS applications that parses search queries with the common search operator\nfeatures such as logical or/and, grouping, phrases (in quotes), etc.\n\nThis package only implements a very simple `filter` utility function that takes a list of items or\nobjects with a map to string function, and returns elements matching the query.\n\nFor more advanced use-cases, you can easily implement your own filter function.  \nSee [utils.ts#filter](/src/utils.ts#L10) for an example.\n\n---\n\n\u003c!-- toc --\u003e\n\u003cdetails\u003e\n\u003csummary\u003eTable of contents\u003c/summary\u003e\n\n- [Example results](#example-results)\n- [How to use](#how-to-use)\n- [Supported operators](#supported-operators)\n  - [Implemented](#implemented)\n  - [To Do](#to-do)\n\n\u003c/details\u003e\n\u003c!-- tocstop --\u003e\n\n---\n\n## Example results\n\n**Input:** `orange OR \"golden apple\"`\n\n**Explanation:** the word \"orange\" or the exact phrase \"golden apple\"\n\n**Output**:\n\n```js\nconst result = [\n  {\n    type: 'operator',\n    value: 'or',\n    left: {\n      type: 'word',\n      value: 'orange',\n    },\n    right: {\n      type: 'phrase',\n      value: 'golden apple',\n      quote: '\"',\n    },\n  },\n]\n```\n\n**Input:** `(mango banana lemon) OR apple -pineapple`\n\n**Explanation:** Either one of the words: \"mango\", \"banana\", or \"lemon\"; OR the word \"apple\";\nexclude all results containing \"pineapple\"\n\n**Output**:\n\n```js\nconst result = [\n  {\n    type: 'operator',\n    value: 'or',\n    left: {\n      type: 'group',\n      children: [\n        {\n          type: 'word',\n          value: 'mango',\n        },\n        {\n          type: 'word',\n          value: 'banana',\n        },\n        {\n          type: 'word',\n          value: 'lemon',\n        },\n      ],\n    },\n    right: {\n      type: 'word',\n      value: 'apple',\n    },\n  },\n  {\n    type: 'exclude',\n    value: 'pineapple',\n  },\n]\n```\n\n## How to use\n\nInstall the package using `pnpm`, `npm` or `yarn`:\n\n```shell\npnpm add search-parse\nnpm install search-parse\nyarn add search-parse\n```\n\nSimply pass a string to the parse function to get the results.\n\n```js\nimport { parse } from 'search-parse'\nconst results = parse('(mango banana lemon) OR apple -pineapple')\n```\n\n## Supported operators\n\nThis is the comprehensive list of operators and their object results:\n\n### Implemented\n\n- **Word:** `example`\n\n  Any single word. Only alpha-numeric characters, dashes and underscores are considered a word. The\n  rest is considered whitespace, which is ignored by the parser, but will cause the surrounding\n  tokens to be broken apart.\n\n  **Object:**\n\n  ```js\n  {\n    type: 'word', // constant\n    value: 'example' // this is the actual word in the string\n  }\n  ```\n\n- **Phrase:** `\"an example\"` or `'an example'`\n\n  A phrase can contain one or more characters. These characters are used as is and not validated as\n  words, so they can include all sorts of special characters.\n\n  A phrase can start with either a single or double quote, and must terminate using the same quote.\n  The other type of quote than the one starting this sequence is ignored and considered part of the\n  phrase itself when it inside it.\n\n  **Object:**\n\n  ```js\n  {\n    type: 'phrase', // constant\n    value: 'an example', // the phrase contained in the quote\n    quote: '\"' // the quote used to start and end this sequence\n  }\n  ```\n\n- **Group:** `(one two three)`\n\n  A group can consist of one or more words or other types of values such as phrases or exclusions. A\n  group logically puts its contents together, usually this is meant as an implicit OR operation but\n  you can implement it as you require.\n\n  **Object:**\n\n  ```js\n  {\n    type: 'group', // constant\n    children: [\n      // all types of children nodes such as word, phrase, etc\n      {\n        type: 'word',\n        value: 'one'\n      },\n      {\n        type: 'word',\n        value: 'two'\n      },\n      {\n        type: 'word',\n        value: 'three'\n      }\n    ]\n  }\n  ```\n\n- **Logical operators _OR_ and _AND_:** `a OR b` or `a | b`, and `a AND b` or `a \u0026 b`\n\n  Logical operators group their immediate left and immediate right in a logical operation.\n\n  **Object:**\n\n  ```js\n  {\n    type: 'operator',\n    value: 'or', // or: 'and'\n    left: { // whatever is on the left of the operator - word, phrase, etc\n      type: 'word',\n      value: 'a'\n    },\n    right: { // whatever is on the right of the operator - word, phrase, etc\n      type: 'word',\n      value: 'b'\n    }\n  }\n  ```\n\n### To Do\n\n- **Exclusion:** `-example`\n\n  An exclusion is an indication to not include results using the given word, phrase or group.\n\n  **Object:**\n\n  ```js\n  {\n    type: 'exclusion',\n    value: { // all types of children nodes such as word, phrase, etc\n      type: 'word',\n      value: 'example'\n    }\n  }\n  ```\n\n- **Domain:** `example-domain:example-token`\n\n  A domain prefix signals the following token to only refer to the prefixing domain. For example, a\n  user could search `name:apple` to only search the word `apple` within the `name` property of the\n  object being searched on.\n\n  **Object:**\n\n  ```js\n  {\n    type: 'domain',\n    domain: 'example-domain',\n    value: { // all types of children nodes such as word, phrase, etc\n      type: 'word',\n      value: 'example-token',\n    }\n  }\n  ```\n\n- **User:** `@example-user`\n\n  A user query can signal only searching content from a specific user.\n\n  **Object:**\n\n  ```js\n  {\n    type: 'user',\n    value: 'example-user',\n  }\n  ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchenasraf%2Fsearch-ast-parser-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchenasraf%2Fsearch-ast-parser-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchenasraf%2Fsearch-ast-parser-js/lists"}