From b957d4ccedb5413fa78ceecc16764dff1b143fd9 Mon Sep 17 00:00:00 2001 From: mok-liee <6745620+mok-liee@users.noreply.github.com> Date: Mon, 26 Aug 2024 16:23:00 +0200 Subject: [PATCH 1/2] fix: toString method can now handle 0 as number --- src/comparators.ts | 12 +++++------- test/comparators.test.ts | 4 ++++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/comparators.ts b/src/comparators.ts index b7a5bb4..9bc252e 100755 --- a/src/comparators.ts +++ b/src/comparators.ts @@ -7,14 +7,12 @@ export abstract class Comparator implements Item { constructor(protected selector: Function | string, protected comparatorKeyWord: string, protected value?: string | number) {} toString(): string { - if (this.value) { - if (typeof this.value === 'number') { - return `${this.selector} ${this.comparatorKeyWord} ${this.value}`; - } else { - return `${this.selector} ${this.comparatorKeyWord} '${this.value}'`; - } + if (typeof this.value === 'undefined' || this.value === null) return `${this.selector} ${this.comparatorKeyWord}`; + if (typeof this.value === 'number') { + return `${this.selector} ${this.comparatorKeyWord} ${this.value}`; + } else { + return `${this.selector} ${this.comparatorKeyWord} '${this.value}'`; } - return `${this.selector} ${this.comparatorKeyWord}`; } } diff --git a/test/comparators.test.ts b/test/comparators.test.ts index 75667d9..2d086a9 100755 --- a/test/comparators.test.ts +++ b/test/comparators.test.ts @@ -95,3 +95,7 @@ test('not in string[]', () => { test('not in number[]', () => { expect(sfNotIn('status', [1, 2]).toString()).toBe('status not in [1, 2]'); }); + +test('.toString() can handle 0 as number', () => { + expect(sfEqual('id', 0).toString()).toBe('id : 0'); +}); From c6557d8cf8e1207a8c29a5cc2ab4840a013f56ae Mon Sep 17 00:00:00 2001 From: mok-liee <6745620+mok-liee@users.noreply.github.com> Date: Thu, 29 Aug 2024 15:55:52 +0200 Subject: [PATCH 2/2] style: change style of if statement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Simon Vallières --- src/comparators.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/comparators.ts b/src/comparators.ts index 9bc252e..32089a0 100755 --- a/src/comparators.ts +++ b/src/comparators.ts @@ -7,7 +7,9 @@ export abstract class Comparator implements Item { constructor(protected selector: Function | string, protected comparatorKeyWord: string, protected value?: string | number) {} toString(): string { - if (typeof this.value === 'undefined' || this.value === null) return `${this.selector} ${this.comparatorKeyWord}`; + if (typeof this.value === 'undefined' || this.value === null) { + return `${this.selector} ${this.comparatorKeyWord}`; + } if (typeof this.value === 'number') { return `${this.selector} ${this.comparatorKeyWord} ${this.value}`; } else {