Registry / data / logic-query-parser

logic-query-parser

JSON →
library0.0.5jsnpmunverified

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.

npm install logic-query-parser
INSTALL
IMPORT
SIG · LOGIC-QUERY-PARSER
L
logic-query-parser
datajavascriptv0.0.5
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parser
const parser = require('logic-query-parser');
import parser from 'logic-query-parser';
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.
parser.parse
const parser = require('logic-query-parser'); const binaryTree = parser.parse('hello AND world');
const { parse } = require('logic-query-parser'); const binaryTree = parse('hello AND world');
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.
parser.utils.binaryTreeToQueryJson
const parser = require('logic-query-parser'); const query = parser.utils.binaryTreeToQueryJson(someBinaryTree);
import { utils } from 'logic-query-parser'; const query = utils.binaryTreeToQueryJson(someBinaryTree);
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.

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.

const parser = require('logic-query-parser'); // Parse a complex logic query string into a binary tree const binaryTree = parser.parse('(welcome OR bye) AND (hello OR ahoy)'); console.log('--- Binary Tree Structure ---'); console.log(JSON.stringify(binaryTree, null, 2)); // Convert the binary tree to a more usable JSON query form const query = parser.utils.binaryTreeToQueryJson(binaryTree); console.log('\n--- Converted Query Form ---'); console.log(JSON.stringify(query, null, 2)); // Example with options: custom spaces and default operator const customParser = require('logic-query-parser'); const options = { spaces: [' ', '\t', '-'], // Allow hyphen as a space character defaultOperator: 'or' // Use OR by default }; const customBinaryTree = customParser.parse(options, 'apple banana -orange'); console.log('\n--- Custom Options Example (Binary Tree) ---'); console.log(JSON.stringify(customBinaryTree, null, 2));
Debug
Known issues
gotchaThis 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.
fix
Use `const parser = require('logic-query-parser');` for importing the module.
affects: >=0.0.1
breakingThe 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.
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.
affects: >=0.0.1
gotchaThe `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.
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')`.
affects: >=0.0.1
Errors
Common errors & fixes
TypeError: parser.parse is not a function
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.
fix
Import the entire `parser` object first: `const parser = require('logic-query-parser');` then call `parser.parse(...)`.
ERR_REQUIRE_ESM: require() of ES Module ... from ... not supported.
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.
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.
Upgrade
Version history
0.0.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Amazon
1
Resources
logic-query-parser — npm install logic-query-parser · libregistry