mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-05 19:41:12 +08:00
This also adds CC-BY-4.0 to the list of accepted licenses. DISABLE_THIRD_PARTY_CHECK=update dependencies Bug: chromium:1083142 Change-Id: I8612de2fba52dae32eeb71af79d5aacfde52142b Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2220097 Reviewed-by: Paul Lewis <aerotwist@chromium.org> Commit-Queue: Mathias Bynens <mathias@chromium.org>
42 lines
898 B
JavaScript
42 lines
898 B
JavaScript
'use strict';
|
|
|
|
const _ = require('lodash');
|
|
|
|
/**
|
|
* @template T
|
|
* @typedef {(i: T) => boolean} Validator
|
|
*/
|
|
|
|
/**
|
|
* Check whether the variable is an object and all it's properties are arrays of string values:
|
|
*
|
|
* ignoreProperties = {
|
|
* value1: ["item11", "item12", "item13"],
|
|
* value2: ["item21", "item22", "item23"],
|
|
* value3: ["item31", "item32", "item33"],
|
|
* }
|
|
* @template T
|
|
* @param {Validator<T>|Validator<T>[]} validator
|
|
* @returns {(value: {[k: any]: T|T[]}) => boolean}
|
|
*/
|
|
module.exports = (validator) => (value) => {
|
|
if (!_.isPlainObject(value)) {
|
|
return false;
|
|
}
|
|
|
|
return Object.values(value).every((value) => {
|
|
if (!Array.isArray(value)) {
|
|
return false;
|
|
}
|
|
|
|
// Make sure the array items are strings
|
|
return value.every((item) => {
|
|
if (Array.isArray(validator)) {
|
|
return validator.some((v) => v(item));
|
|
}
|
|
|
|
return validator(item);
|
|
});
|
|
});
|
|
};
|