Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions projects/swimlane/ngx-ui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Fix (`ngx-date-range-picker`): Preset values now retain their relative expressions when cancel is clicked, instead of being converted to timestamps
- Fix (`ngx-date-range-picker`): Fix highlight the date for given `selectedRange` values.
- Fix (`ngx-select`): Fix filtering of numeric option values.

## 50.1.3 (2025-09-23)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,43 @@ describe('containsFilter', () => {
expect(res).toBeTruthy();
});

it('should be undefined if value is not string or object', () => {
const res = containsFilter(1, '1', {});
expect(res).toBeUndefined();
it('should convert number to string and return true when filter matches', () => {
const res = containsFilter(123, '123', {});
expect(res).toBeTruthy();
});

it('should convert number to string and return true when filter matches partially', () => {
const res = containsFilter(123, '12', {});
expect(res).toBeTruthy();
});

it('should convert number to string and return false when filter does not match', () => {
const res = containsFilter(123, '456', {});
expect(res).toBeFalsy();
});

it('should handle number filtering with case sensitive option', () => {
const res = containsFilter(123, '123', { filterCaseSensitive: true });
expect(res).toBeTruthy();
});

it('should handle alphanumeric string filtering with numbers', () => {
const res = containsFilter('ABC123', '123', {});
expect(res).toBeTruthy();
});

it('should handle alphanumeric string filtering with partial numbers', () => {
const res = containsFilter('ABC123', '12', {});
expect(res).toBeTruthy();
});

it('should handle alphanumeric string filtering with letters and numbers', () => {
const res = containsFilter('ABC123', 'BC1', {});
expect(res).toBeTruthy();
});

it('should return false for alphanumeric string when filter does not match', () => {
const res = containsFilter('ABC123', 'XYZ', {});
expect(res).toBeFalsy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ export function containsFilter(
if (value === undefined || value === null || depth > 2) {
return false;
}

if (typeof value === 'number') {
value = String(value);
}
if (typeof value === 'string') {
if (!isNaN(+value)) {
return value === keyword;
}

const escapedKeyword = escapeRegExp(keyword);
// eslint-disable-next-line
const idx = options.filterCaseSensitive ? value.indexOf(keyword) : value.search(new RegExp(escapedKeyword, 'i'));
Expand Down
Loading