{"id":14691,"library":"logic-query-parser","title":"Logic Query Parser","description":"The `logic-query-parser` package provides a JavaScript utility for parsing logic search strings into a binary tree representation. It takes a query string, supports `AND`, `OR`, parentheses, and double quotes, and can be configured with custom space characters and a default operator. Additionally, it offers a utility function to convert the binary tree into a more usable JSON query form, simplifying programmatic interpretation. This package is currently at version 0.0.5 and was last published approximately 7 years ago, indicating it is no longer actively maintained. Its primary use case is to transform human-readable logical expressions into a structured data format suitable for backend search or filtering operations.","status":"abandoned","version":"0.0.5","language":"javascript","source_language":"en","source_url":"https://github.com/AnyFetch/logic-query-parser","tags":["javascript","logic","query","parser","search"],"install":[{"cmd":"npm install logic-query-parser","lang":"bash","label":"npm"},{"cmd":"yarn add logic-query-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add logic-query-parser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is an older CommonJS module. Modern ESM imports are not directly supported without a transpiler or Node.js's `--experimental-json-modules` flag for older Node versions, or using a wrapper.","wrong":"import parser from 'logic-query-parser';","symbol":"parser","correct":"const parser = require('logic-query-parser');"},{"note":"The `parser` object itself is the default export, and `parse` is a method on it. Direct destructuring of `parse` from the `require` statement will fail.","wrong":"const { parse } = require('logic-query-parser');\nconst binaryTree = parse('hello AND world');","symbol":"parser.parse","correct":"const parser = require('logic-query-parser');\nconst binaryTree = parser.parse('hello AND world');"},{"note":"The `utils` object is nested under the `parser` object. Attempting to destructure `utils` directly from the top-level import is incorrect for this CommonJS module.","wrong":"import { utils } from 'logic-query-parser';\nconst query = utils.binaryTreeToQueryJson(someBinaryTree);","symbol":"parser.utils.binaryTreeToQueryJson","correct":"const parser = require('logic-query-parser');\nconst query = parser.utils.binaryTreeToQueryJson(someBinaryTree);"}],"quickstart":{"code":"const parser = require('logic-query-parser');\n\n// Parse a complex logic query string into a binary tree\nconst binaryTree = parser.parse('(welcome OR bye) AND (hello OR ahoy)');\n\nconsole.log('--- Binary Tree Structure ---');\nconsole.log(JSON.stringify(binaryTree, null, 2));\n\n// Convert the binary tree to a more usable JSON query form\nconst query = parser.utils.binaryTreeToQueryJson(binaryTree);\n\nconsole.log('\\n--- Converted Query Form ---');\nconsole.log(JSON.stringify(query, null, 2));\n\n// Example with options: custom spaces and default operator\nconst customParser = require('logic-query-parser');\nconst options = {\n  spaces: [' ', '\\t', '-'], // Allow hyphen as a space character\n  defaultOperator: 'or' // Use OR by default\n};\nconst customBinaryTree = customParser.parse(options, 'apple banana -orange');\n\nconsole.log('\\n--- Custom Options Example (Binary Tree) ---');\nconsole.log(JSON.stringify(customBinaryTree, null, 2));","lang":"javascript","description":"This quickstart demonstrates parsing a complex logic query into a binary tree and then converting it to a simplified JSON query structure, also showing how to use custom parsing options."},"warnings":[{"fix":"Use `const parser = require('logic-query-parser');` for importing the module.","message":"This package is a CommonJS module and does not natively support ES module (`import`) syntax. Attempting to use `import` statements directly will result in errors in modern Node.js environments unless transpiled or wrapped.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Consider migrating to a more actively maintained logic parsing library for new projects or critical applications. Evaluate existing implementations carefully for stability and security vulnerabilities.","message":"The package version (0.0.5) is extremely low and was last updated approximately 7 years ago. This indicates an abandoned status, meaning no further updates, bug fixes, or security patches are likely. Production use is risky.","severity":"breaking","affected_versions":">=0.0.1"},{"fix":"If providing options, ensure the options object is the first argument: `parser.parse(options, 'my query')`. If no options, pass the string directly: `parser.parse('my query')`.","message":"The `parser.parse` function expects either a single string argument or an options object as the first argument followed by the string. Passing the string as the first argument when an options object is expected will lead to incorrect parsing.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Import the entire `parser` object first: `const parser = require('logic-query-parser');` then call `parser.parse(...)`.","cause":"Attempting to destructure `parse` directly from the `require` statement (e.g., `const { parse } = require('logic-query-parser');`). The `require` call returns the `parser` object itself, and `parse` is a method on that object.","error":"TypeError: parser.parse is not a function"},{"fix":"Use CommonJS `require` syntax: `const parser = require('logic-query-parser');`. If modern ESM syntax is mandatory, consider a build step (e.g., Webpack, Rollup) to transpile or find an alternative library.","cause":"Attempting to import `logic-query-parser` using ES module `import` syntax (`import parser from 'logic-query-parser';`) in a Node.js project configured for CommonJS or in an environment where direct ESM `require` is not enabled for CJS modules.","error":"ERR_REQUIRE_ESM: require() of ES Module ... from ... not supported."}],"ecosystem":"npm"}