Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function handleAddField(fieldName, body, root) {
if (_.contains(specialFields, fieldName)) {
root.addProp(fieldName, body);
return;
}
if (_.isObject(body)) {
// if reducer specifies a nested field
// if it's a prop
const dots = dot.dot({
[fieldName]: body
});
_.each(dots, (value, key) => {
addFieldIfRequired(root, key, value);
});
} else {
// if reducer does not specify a nested field, and the field does not exist.
addFieldIfRequired(root, fieldName, body);
}
}
getDocumentValue(fieldName)
{
if(this.doesDocumentValueExist(fieldName))
{
let doc = {};
Dot.copy(fieldName, fieldName, this.props.doc, doc);
doc = Dot.dot(doc);
// If it's a number
if(!isNaN(parseFloat(doc[fieldName])) && isFinite(doc[fieldName]))
{
// Return it as a String
return doc[fieldName].toString();
}
return doc[fieldName];
}
return false;
}
Object.keys(this.props.schema).map(fieldName =>
{
if(typeof state[`${fieldName}_fieldValue`] !== 'undefined' &&
!(this.props.type === 'insert' && state[`${fieldName}_fieldValue`] === '') &&
this.getDocumentValue(fieldName) !== this.getStateOrDefaultSchemaValue(fieldName, null, null, state))
{
formFields[fieldName] = this.getStateOrDefaultSchemaValue(fieldName, null, null, state); // Gets the state value
if(fieldName.indexOf('.') > 0) // If this fieldName belongs to object
{
let fieldNameObj = Dot.object(Object.assign({}, {[fieldName]: formFields[fieldName]})), // Get the entire object
// schemaKey = fieldName.substr(0, fieldName.lastIndexOf('.')); // Get the parent object key
schemaKey = fieldName.substr(0, fieldName.indexOf('.')); // Get the parent object key
Dot.copy(schemaKey, schemaKey, this.props.doc, fieldNameObj); // Copy the original object
formFields = {...Dot.dot(fieldNameObj), ...formFields}; // Turn the original object into dotted object and then merge it with the new fieldName value
}
}
});
export default function(validationErrors) {
if (validationErrors.length === 0) return null
const errors = {}
for (const validationError of validationErrors) {
errors[validationError.key] = validationError.code
}
return dot.dot(errors)
}
return languageFiles.reduce((accumulator, file) => {
const language = file.fileName.substring(file.fileName.lastIndexOf('/') + 1, file.fileName.lastIndexOf('.'));
const flattenedObject = dot.dot(file.content);
const i18nInFile = Object.keys(flattenedObject).map((key, index) => {
return {
line: index,
path: key,
file: file.fileName,
};
});
accumulator[language] = i18nInFile;
return accumulator;
}, {});
}
config.loadValuesFile = function(valuesPath) {
const doc = yaml.safeLoad(fs.readFileSync(valuesPath, "utf8"));
const flat = dot.dot(doc);
Object.keys(flat).forEach(key => {
const capitalKey = key
.replace(/([A-Z])/g, "_$1")
.toUpperCase()
.replace(/\./g, "_")
.replace(/^GLOBAL_/, "");
this[capitalKey] = flat[key];
});
};
export default function (allowedBody, clientBody) {
const allowedBodyDot = _.keys(dot.dot(allowedBody));
const clientBodyDot = _.keys(dot.dot(clientBody));
const intersection = _.intersection(allowedBodyDot, clientBodyDot);
const build = {};
intersection.forEach(intersectedField => {
build[intersectedField] = 1;
});
return dot.object(build);
}