Skip to content

Commit

Permalink
Merge pull request #15 from mok-liee/master
Browse files Browse the repository at this point in the history
fix: toString method can now handle 0 as number
  • Loading branch information
sisimomo authored Aug 30, 2024
2 parents 589f776 + c6557d8 commit a3b73be
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/comparators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ 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}`;
}
}

Expand Down
4 changes: 4 additions & 0 deletions test/comparators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

0 comments on commit a3b73be

Please sign in to comment.