Skip to content

Commit

Permalink
Makes filter optional
Browse files Browse the repository at this point in the history
  • Loading branch information
queercat committed Jan 13, 2024
1 parent 72b622a commit e3916c3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion docusnore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,17 @@ export class Docusnore {
* @param filter the filter to apply to the key, if any.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public async update<T extends object = any>(key: string, value: T | ((item: T) => T), filter: (item: T) => boolean) {
public async update<T extends object = any>(key: string, value: T | ((item: T) => T), filter?: (item: T) => boolean) {
const data = await this.read();
const updated = data[key].map((item: T) => {
if (filter === undefined) {
if (typeof value !== "function") {
return value;
}

return value(item);
}

if (filter(item)) {
if (typeof value !== "function") {
return value;
Expand Down

0 comments on commit e3916c3

Please sign in to comment.