ts-array-filter
v1.1.0
Published
A TypeScript library that provides a simple and intuitive .where(...) method for filtering arrays based on specified filters.
Downloads
2
Maintainers
Readme
TS Array Filter
A TypeScript library that provides a simple and intuitive .where(...) method for filtering arrays based on specified filters. It includes a generic filter interface for better type checking and autocompletion. Version 1.1.0 introduces new filters for enhanced functionality.
Installation
Install the package using npm:
npm install ts-array-filter
Usage
Import the library in your TypeScript project:
import 'ts-array-filter';
Declare an interface for your data:
interface Example {
id: number;
name: string;
tags: string[];
}
Create a sample data array:
const data: Example[] = [
{ id: 1, name: 'Example 1', tags: ['tag1', 'tag2'] },
{ id: 2, name: 'Example 2', tags: ['tag2', 'tag3'] },
{ id: 3, name: 'Example 3', tags: ['tag1', 'tag3'] },
];
Apply filters using the .where(...) method:
const result = data.where([
{ field: 'id', operator: '>', value: 1 },
{ field: 'tags', operator: 'array-contains', value: 'tag3' },
]);
Supported Filters
- < less than
- <= less than or equal to
- == equal to
- ">" greater than
- ">=" greater than or equal to
- != not equal to
- array-contains
- array-contains-any
- in
- not-in
- startswith
- endswith
- contains
- regex
- null
- not-null
- true
- false
- exists
- not-exists
Contributing
If you would like to contribute to the development of this library, please follow these steps:
- Fork the repository on GitHub.
- Clone the forked repository to your local machine.
- Make your changes and commit them to your forked repository.
- Create a Pull Request from your fork to the original repository.
Please ensure that your changes are well-tested and documented. We appreciate your help in improving this library!
License
This library is released under the MIT License. See the LICENSE file for more information.