open-consul/ui/packages/consul-ui/app/utils/search/predicate.js
Ronald 6bcb98ea71
Add UI copyright headers files (#16614)
* Add copyright headers to UI files

* Ensure copywrite file ignores external libs
2023-03-14 09:18:55 -04:00

28 lines
672 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
export default class PredicateSearch {
constructor(items, options) {
this.items = items;
this.options = options;
}
search(s) {
const predicate = this.predicate(s);
// Test the value of each key for each object against the regex
// All that match are returned.
return this.items.filter((item) => {
return Object.entries(this.options.finders).some(([key, finder]) => {
const val = finder(item);
if (Array.isArray(val)) {
return val.some(predicate);
} else {
return predicate(val);
}
});
});
}
}