Skip to content

Commit 2312cb0

Browse files
author
Julian Hundeloh
committed
2 parents e2ddaf1 + 8f662c7 commit 2312cb0

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/index.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,14 @@ export default class AdvancedSearchQuery {
3838
}
3939

4040
/**
41-
* @param {String} str to parse e.g. 'to:me -from:[email protected] foobar'.
41+
* @param {String} string to parse e.g. 'to:me -from:[email protected] foobar'.
4242
* @param {Array} transformTextToConditions Array of functions to transform text into conditions
4343
* @returns {AdvancedSearchQuery} An instance of this class AdvancedSearchQuery.
4444
*/
4545
static parse(
46-
str?: string | null,
46+
string: string = '',
4747
transformTextToConditions: Transformer[] = []
4848
) {
49-
if (!str) str = ''
5049
const conditionArray: Condition[] = []
5150
const textSegments: TextSegment[] = []
5251

@@ -102,10 +101,10 @@ export default class AdvancedSearchQuery {
102101

103102
performReset()
104103

105-
const quotePairMap = getQuotePairMap(str)
104+
const quotePairMap = getQuotePairMap(string)
106105

107-
for (let i = 0; i < str.length; i++) {
108-
const char = str[i]
106+
for (let i = 0; i < string.length; i++) {
107+
const char = string[i]
109108
if (char === ' ') {
110109
if (inOperand()) {
111110
if (inQuote()) {

tests/index.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ describe('searchString', () => {
2828
expect(AdvancedSearchQuery.parse().getConditionArray()).toEqual([])
2929
expect(AdvancedSearchQuery.parse('').getConditionArray()).toEqual([])
3030
expect(AdvancedSearchQuery.parse(' ').getConditionArray()).toEqual([])
31-
expect(AdvancedSearchQuery.parse(null).getConditionArray()).toEqual([])
32-
expect(AdvancedSearchQuery.parse(null).getParsedQuery()).toEqual({
31+
expect(AdvancedSearchQuery.parse('').getConditionArray()).toEqual([])
32+
expect(AdvancedSearchQuery.parse('').getParsedQuery()).toEqual({
3333
exclude: {},
3434
})
3535
})

0 commit comments

Comments
 (0)