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 getFieldsValue(schema, state, mustOK = true) {
const fieldNames = Object.keys(schema);
let result = {};
if (is.propertyDefined(schema, 'collectValues')) {
result = {
...getCollectValues(schema.collectValues, state)
};
}
fieldNames.forEach(name => {
if (is.not.propertyDefined(state, name)) {
// eslint-disable-next-line no-console
console.warn(`[veasy]: No ${name} found in state.`);
return;
}
const fieldState = state[name];
if (mustOK && fieldState.status !== FieldStatus.ok) return;
result[name] = fieldState.value;
});
isRegisteredComponent = child => {
// Skip HTML element
if (is.string(child.type)) return false;
if (!is.propertyDefined(child.props, 'name')) return false;
const childName = child.props.name;
const names = Object.keys(this.props.schema);
return names.includes(childName);
};
Flowa.prototype._indexTasks = function(task, taskName, runnerType, depth, parentTaskName) {
// The current property is not a task
if (is.not.function(task) && is.not.json(task)) {
return;
}
// Duplicated task name
if (is.propertyDefined(this._tasks, taskName)) {
throw new Error('The task ' + taskName + ' is duplicated. Tasks names should be unique');
}
// Invalid runner type
if (is.not.propertyDefined(this._runners, runnerType)) {
throw new Error('The type ' + runnerType + ' is not a valid runner type');
}
this._tasks[taskName] = task;
this._tasksDepths[taskName] = depth;
this._tasksParents[taskName] = parentTaskName;
this._tasksRunnersTypes[taskName] = runnerType;
// Is a compound task
if (this._isCompoundTask(taskName)) {
Object.keys(schema).forEach(ruleInSchema => {
if (is.propertyDefined(matcher, ruleInSchema)) {
ruleRunner(
ruleInSchema,
matcher[ruleInSchema],
fieldName,
fieldState.value,
schema
);
}
else if (ruleInSchema === 'beforeValidation') {
fieldState.value = handleBeforeValidation(
fieldState.value,
schema.beforeValidation
);
}
// TODO: Do something when the rule is not match
// else if (ruleInSchema !== 'default') {
schemaItems.forEach(name => {
if (is.propertyDefined(userState, name)) {
initialState[name] = {
...initialState[name],
...userState[name]
};
}
});
export function createInitialValue(schema) {
if (is.propertyDefined(schema, 'default')) {
return schema.default;
} else if (is.propertyDefined(schema, 'min')) {
return schema.min;
}
return '';
}
export function createInitialValue(schema) {
if (is.propertyDefined(schema, 'default')) {
return schema.default;
} else if (is.propertyDefined(schema, 'min')) {
return schema.min;
}
return '';
}