MCPcopy Index your code
hub / github.com/darkreader/darkreader / validateArray

Function validateArray

src/utils/validation.ts:66–82  ·  view source on GitHub ↗
(obj: T, key: keyof T, validator: (x: V) => boolean)

Source from the content-addressed store, hash-verified

64 }
65
66 function validateArray<T extends Record<string, unknown>, V>(obj: T, key: keyof T, validator: (x: V) => boolean) {
67 if (!obj.hasOwnProperty(key)) {
68 return;
69 }
70 const wrongValues = new Set();
71 const arr: any[] = obj[key] as any;
72 for (let i = 0; i < arr.length; i++) {
73 if (!validator(arr[i])) {
74 wrongValues.add(arr[i]);
75 arr.splice(i, 1);
76 i--;
77 }
78 }
79 if (wrongValues.size > 0) {
80 errors.push(`Array "${key as string}" has wrong values: ${Array.from(wrongValues).map((v) => JSON.stringify(v)).join('; ')}`);
81 }
82 }
83
84 return {validateProperty, validateArray, errors};
85}

Callers 1

validateSettingsFunction · 0.85

Calls 1

addMethod · 0.80

Tested by

no test coverage detected