@quarkly/atomize
Version:
Library for creating atomic react components
33 lines (29 loc) • 955 B
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import { hashPropsWithAliases } from '../constants/dict';
import { PropInfoCollisionError } from './errors';
var configuration = {
useValidate: process.env === 'development'
};
export var configure = function configure(override) {
configuration = _extends(_extends({}, configuration), override);
};
var validateNodes = function validateNodes(nodes) {
return nodes.reduce(function (acc, _ref) {
var key = _ref[0],
nodeInfo = _ref[1];
validateNode(acc, nodeInfo, key);
acc[key] = nodeInfo;
return acc;
}, {});
};
var validateNode = function validateNode(tree, node, key) {
if (!configuration.useValidate) {
return;
}
if (hashPropsWithAliases[key]) {
throw new PropInfoCollisionError("key " + key + " in propInfo must be unque, found in style name");
}
};
export default (function (propInfo) {
return validateNodes(Object.entries(propInfo));
});