-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
2,866 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ name: dev | |
on: | ||
pull_request: | ||
branches: | ||
- dev | ||
- master | ||
|
||
jobs: | ||
build: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,17 +4,19 @@ | |
"description": "Another parser for advanced search query syntax.", | ||
"main": "build/cjs/src/index.js", | ||
"module": "build/esm/src/index.js", | ||
"types": "build/cjs/index.d.ts", | ||
"types": "build/cjs/src/index.d.ts", | ||
"files": [ | ||
"src", | ||
"build" | ||
], | ||
"scripts": { | ||
"build": "ts-build . --cjs --esm --out-dir build", | ||
"ci": "npm run test && npm run build", | ||
"prepublish": "npm run ci", | ||
"ci": "yarn test && yarn build", | ||
"prepare": "yarn build", | ||
"prepublishOnly": "yarn ci", | ||
"test": "jest", | ||
"testWatch": "jest --watch" | ||
"testWatch": "jest --watch", | ||
"semantic-release": "semantic-release" | ||
}, | ||
"author": "Julian Hundeloh <[email protected]> (https://approvals.cloud)", | ||
"license": "MIT", | ||
|
@@ -36,7 +38,8 @@ | |
"jest": "^24.8.0", | ||
"jest-cli": "^24.8.0", | ||
"prettier": "^1.18.2", | ||
"pretty-quick": "^1.11.1" | ||
"pretty-quick": "^1.11.1", | ||
"semantic-release": "^15.13.19" | ||
}, | ||
"config": { | ||
"commitizen": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
import { getQuotePairMap } from './utils' | ||
|
||
// types | ||
const RESET = 'RESET' | ||
const IN_OPERAND = 'IN_OPERAND' | ||
const IN_TEXT = 'IN_TEXT' | ||
const SINGLE_QUOTE = 'SINGLE_QUOTE' | ||
const DOUBLE_QUOTE = 'DOUBLE_QUOTE' | ||
|
||
type State = typeof RESET | typeof IN_OPERAND | typeof IN_TEXT | ||
type QuoteState = typeof RESET | typeof SINGLE_QUOTE | typeof DOUBLE_QUOTE | ||
type Keyword = Exclude<string, 'exclude'> | ||
|
@@ -12,13 +17,6 @@ type ParsedQuery = Record<string, any> & { | |
exclude: Record<string, Value[]> | ||
} | ||
|
||
// state tokens | ||
const RESET = 'RESET' | ||
const IN_OPERAND = 'IN_OPERAND' | ||
const IN_TEXT = 'IN_TEXT' | ||
const SINGLE_QUOTE = 'SINGLE_QUOTE' | ||
const DOUBLE_QUOTE = 'DOUBLE_QUOTE' | ||
|
||
/** | ||
* AdvancedSearchQuery is a parsed search string which allows you to fetch conditions | ||
* and text being searched. | ||
|
@@ -40,15 +38,14 @@ export default class AdvancedSearchQuery { | |
} | ||
|
||
/** | ||
* @param {String} str to parse e.g. 'to:me -from:[email protected] foobar'. | ||
* @param {String} string to parse e.g. 'to:me -from:[email protected] foobar'. | ||
* @param {Array} transformTextToConditions Array of functions to transform text into conditions | ||
* @returns {AdvancedSearchQuery} An instance of this class AdvancedSearchQuery. | ||
*/ | ||
static parse( | ||
str?: string | null, | ||
string: string = '', | ||
transformTextToConditions: Transformer[] = [] | ||
) { | ||
if (!str) str = '' | ||
const conditionArray: Condition[] = [] | ||
const textSegments: TextSegment[] = [] | ||
|
||
|
@@ -104,10 +101,10 @@ export default class AdvancedSearchQuery { | |
|
||
performReset() | ||
|
||
const quotePairMap = getQuotePairMap(str) | ||
const quotePairMap = getQuotePairMap(string) | ||
|
||
for (let i = 0; i < str.length; i++) { | ||
const char = str[i] | ||
for (let i = 0; i < string.length; i++) { | ||
const char = string[i] | ||
if (char === ' ') { | ||
if (inOperand()) { | ||
if (inQuote()) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.