diff --git a/package.json b/package.json index ffc56e4..f2928f6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/js-filter", - "version": "0.0.3", + "version": "0.0.4", "description": "用于 JavaScript 数组的 SQL LIKE 过滤器函数", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/index.ts b/src/index.ts index d7e5246..cbd9317 100644 --- a/src/index.ts +++ b/src/index.ts @@ -33,10 +33,10 @@ class Lexer { } } - private readString(): string { + private readString(quote: string): string { this.pos++; let result = ''; - while (this.pos < this.input.length && this.input[this.pos] !== "'") { + while (this.pos < this.input.length && this.input[this.pos] !== quote) { result += this.input[this.pos]; this.pos++; } @@ -76,8 +76,8 @@ class Lexer { const char = this.input[this.pos]; - if (char === "'") { - return { type: 'STRING', value: this.readString(), pos: this.pos }; + if (char === "'" || char === '"') { + return { type: 'STRING', value: this.readString(char), pos: this.pos }; } if (/\d/.test(char)) { diff --git a/test/test-and.ts b/test/test-and.ts new file mode 100644 index 0000000..f9eebec --- /dev/null +++ b/test/test-and.ts @@ -0,0 +1,12 @@ +import { filter } from '../src/index.ts'; + +const data = [ + { path: 'good', key: 'searchInfo', value: 1 }, + { path: 'good', key: 'other', value: 2 }, + { path: 'bad', key: 'searchInfo', value: 3 }, +]; + +// 测试使用 AND 和双引号 +console.log('Testing: WHERE path = \'good\' AND key = "searchInfo"'); +const result = filter(data, 'WHERE path = \'good\' AND key = "searchInfo"'); +console.log('Result:', JSON.stringify(result, null, 2));