tweak-tools
Version:
Tweak your React projects until awesomeness
25 lines (24 loc) • 835 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getValuesForPaths = void 0;
const _1 = require(".");
/**
* Takes a data object with { [path.key]: value } and returns { [key]: value }.
* Also warns when two similar keys are being used by the user.
*
* @param data
* @param paths
* @param shouldWarn
*/
function getValuesForPaths(data, paths) {
return Object.entries((0, _1.pick)(data, paths)).reduce(
// Typescript complains that SpecialInput type doesn't have a value key.
// But getValuesForPath is only called from paths that are inputs,
// so they always have a value key.
// @ts-expect-error
(acc, [, { value, disabled, key }]) => {
acc[key] = disabled ? undefined : value;
return acc;
}, {});
}
exports.getValuesForPaths = getValuesForPaths;