{"_id":"@baiyu/logic-query-parser","name":"@baiyu/logic-query-parser","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@baiyu/logic-query-parser","version":"1.0.0","description":"Generate binary tree with a logic query string as input","main":"index.js","scripts":{"test":"mocha","build":"babel src -d dist"},"author":{"name":"boybai.work@gmail.com"},"license":"MIT","devDependencies":{"babel-cli":"^6.26.0","babel-preset-es2015":"^6.24.1","mocha":"^10.2.0"},"gitHead":"4ef51e9c9ea01096dd9765b69c560c85a72a94f9","_id":"@baiyu/logic-query-parser@1.0.0","_nodeVersion":"16.17.1","_npmVersion":"8.15.0","dist":{"integrity":"sha512-gUcey5r51WF14OnRA/4Bazzm9nT/eyjJgG8wvMxKvAAaMl18aDr/5g29nsDkCWuNA46pJfwcxuEf62x5by620A==","shasum":"5d8cef515ca00e979c077d86da427f28353563db","tarball":"https://registry.npmjs.org/@baiyu/logic-query-parser/-/logic-query-parser-1.0.0.tgz","fileCount":37,"unpackedSize":153715,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIA4Qspv3Eo/n1Cj8E/c8SuClJ8X5Dhubf3OFF1Wjl0W+AiBbGigCSGMAqebHDbc6/phyy4b0d9ov7cOKlbFkG94/2Q=="}]},"_npmUser":{"name":"baiyu","email":"602316022@qq.com"},"directories":{},"maintainers":[{"name":"baiyu","email":"602316022@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/logic-query-parser_1.0.0_1689930159123_0.05041990477555047"},"_hasShrinkwrap":false}},"time":{"created":"2023-07-21T09:02:39.007Z","1.0.0":"2023-07-21T09:02:39.284Z","modified":"2023-07-21T09:02:39.602Z"},"maintainers":[{"name":"baiyu","email":"602316022@qq.com"}],"description":"Generate binary tree with a logic query string as input","author":{"name":"boybai.work@gmail.com"},"license":"MIT","readme":"# Logic Query Parser\n\nGenerate binary tree with a logic query string as input\n\n# How to install?\n\n```\nnpm install -S @baiyu/logic-query-parser\n```\n\nCheck everything is working with `npm test`.\n\n# How to use it\n\nThis lib provides a function parser whick take an optional options object and a string parameter, then returning a binary tree.\nAs binary trees are not easy to use, this lib also provides an utility function which convert said binaryTree to a more usable query form\n\nAvalaible options are for now :\n\n- `spaces` : String / array containing all spaces characters. Default : \" \\n\\t\"\n- `defaultOperator` : Default operator to use between two strings. Default : 'and'\n\nAvailable operators for now : AND, OR, parens, double quote\n\n# Example\n\n```js\nvar parser = require(\"@baiyu/logic-query-parser\");\n\nvar binaryTree = parser.parse(\"hello AND welcome\");\n// or\nvar binaryTree = parser.parse(\"hello + welcome\");\n```\n\nThe binaryTree for this example will be :\n\n```js\n{\n  lexeme: {\n    type: 'and'\n  },\n  left: {\n    lexeme: {\n      type: 'string',\n      value: 'hello'\n    },\n    left: null,\n    right: null\n  },\n  right: {\n    lexeme: {\n      type: 'string',\n      value: 'welcome'\n    },\n    left: null,\n    right: null\n  }\n}\n```\n\nAnother example, slightly more complex:\n\n```js\nvar parser = require(\"@baiyu/logic-query-parser\");\n\nvar binaryTree = parser.parse(\"(welcome OR bye) AND (hello OR ahoy)\");\n// or\nvar binaryTree = parser.parse(\"(welcome / bye) + (hello / ahoy)\");\n```\n\nAnd the binary tree :\n\n```js\n{\n  lexeme: {\n    type: \"and\"\n  },\n  left: {\n    lexeme: {\n      type: \"or\"\n    },\n    left: {\n      lexeme: {\n        type: \"string\",\n        value: \"welcome\"\n      },\n      left: null,\n      right: null\n    },\n    right: {\n      lexeme: {\n        type: \"string\",\n        value: \"bye\"\n      },\n      left: null,\n      right: null\n    }\n  },\n  right: {\n    lexeme: {\n      type: \"or\"\n    },\n    left: {\n      lexeme: {\n        type: \"string\",\n        value: \"hello\"\n      },\n      left: null,\n      right: null\n    },\n    right: {\n      lexeme: {\n        type: \"string\",\n        value: \"ahoy\"\n      },\n      left: null,\n      right: null\n    }\n  }\n}\n```\n\nAs said before, trees are useful but not easy to use. You can also get the \"query form\":\n\n```js\nvar parser = require(\"@baiyu/logic-query-parser\");\n\nvar binaryTree = parser.parse(\"(welcome OR bye) AND (hello OR ahoy)\");\n// or\nvar binaryTree = parser.parse(\"(welcome / bye) + (hello / ahoy)\");\n\nvar query = parser.utils.binaryTreeToQueryJson(binaryTree);\n```\n\nReturning:\n\n```js\n{\n  type: \"and\",\n  values: [\n    {\n      type: \"or\",\n      values: [\n        {\n          type: \"string\",\n          value: \"welcome\"\n        },\n        {\n          type: \"string\",\n          value: \"bye\"\n        }\n      ]\n    },\n    {\n      type: \"or\",\n      values: [\n        {\n          type: \"string\",\n          value: \"hello\"\n        },\n        {\n          type: \"string\",\n          value: \"ahoy\"\n        }\n      ]\n    }\n  ]\n}\n```\n\nTake a look at `config/tests.js` for more samples\n\nSupport: `boybai.work@gmail.com`.\n\nLinks: [@baiyu/logic-query-parser](https://github.com/AnyFetch/@baiyu/logic-query-parser)\n","readmeFilename":"README.md"}