{"library":"search-query-parser","title":"Search Query Syntax Parser","description":"The `search-query-parser` library provides a robust, dependency-free solution for parsing advanced search query strings into a structured JavaScript object. It supports syntax similar to popular search engines, allowing for field-specific searches (e.g., `from:user`, `subject:topic`), date ranges (`date:1/10/2013-15/04/2014`), multi-value fields, and exclusion syntax (`-keyword:value`). The current stable version is 1.6.0, released over five years ago, indicating a mature and stable, but not actively developed, state. Key features include configurable keywords and range fields, optional tokenization of free text, the ability to always return matched keyword values as arrays, and the inclusion of character offsets for parsed elements. Since version 1.6.0, it also offers a `stringify` method to convert the parsed object back into a query string. This package primarily targets CommonJS environments, relying on the `require` syntax.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install search-query-parser"],"cli":null},"imports":["const searchQuery = require('search-query-parser');","const { parse } = require('search-query-parser');","const { stringify } = require('search-query-parser');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const searchQuery = require('search-query-parser');\n\nconst query = 'from:hi@example.com,foo@example.org to:me subject:vacations date:1/10/2023-15/04/2024 important photos -archive';\nconst options = {\n  keywords: ['from', 'to', 'subject', 'important'],\n  ranges: ['date'],\n  tokenize: true,\n  alwaysArray: true,\n  offsets: false\n};\n\nconst parsedQuery = searchQuery.parse(query, options);\n\nconsole.log('Parsed Query Object:');\nconsole.log(JSON.stringify(parsedQuery, null, 2));\n\nconsole.log('\\nSpecific fields:');\nconsole.log('From:', parsedQuery.from); // Expected: ['hi@example.com', 'foo@example.org']\nconsole.log('To:', parsedQuery.to);     // Expected: ['me']\nconsole.log('Subject:', parsedQuery.subject); // Expected: ['vacations']\nconsole.log('Text:', parsedQuery.text); // Expected: ['photos']\nconsole.log('Date From:', parsedQuery.date.from);\nconsole.log('Excluded from archive:', parsedQuery.exclude.archive);\n\nconst queryStringified = searchQuery.stringify(parsedQuery);\nconsole.log('\\nStringified Query:', queryStringified);","lang":"javascript","description":"Demonstrates parsing a complex search query with keywords, ranges, exclusion, and then stringifying the result. It highlights configuring parser options and accessing different parts of the parsed object.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}