ice-components-dto-search
v2.0.0
Published
A simple DTO search utility
Readme
dto-search
A simple utility for searching through arrays of DTOs (Data Transfer Objects).
Installation
npm install dto-searchUsage
const { searchDtos } = require('dto-search');
const dtos = [
{ id: 1, name: 'John' },
{ id: 2, name: 'Jane' },
{ id: 3, name: 'John' }
];
// Search for DTOs with name 'John'
const results = searchDtos(dtos, 'name', 'John');
console.log(results);
// Output: [{ id: 1, name: 'John' }, { id: 3, name: 'John' }]API
searchDtos(dtos, field, value)
Searches through an array of DTOs for objects that have a specific field matching the given value.
Parameters
dtos(Array): Array of DTO objects to search throughfield(string): Field name to search invalue(*): Value to search for
Returns
- (Array): Array of matching DTOs
Throws
- Error if first argument is not an array
License
MIT
