UNPKG

@inkline/inkline

Version:

Inkline is the Vue.js UI/UX Library built for creating your next design system

28 lines 1.04 kB
import { defaultValidationValues, reservedValidationFields, defaultFieldValidationValues } from '../constants/index.mjs'; /** * Initialize raw form schema by adding required default fields if they do not exist * * @param schema * @returns {*} */ export function initialize(schema) { const isField = Object.keys(schema).length === 0 || Array.isArray(schema.validators) || schema.hasOwnProperty('value'); const defaultValues = isField ? { ...defaultValidationValues, ...defaultFieldValidationValues } : defaultValidationValues; Object.entries(defaultValues) .forEach(([key, value]) => { if (!schema.hasOwnProperty(key)) { schema[key] = value; } }); Object.keys(schema) .filter((key) => !reservedValidationFields.includes(key)) .forEach((key) => { if (typeof schema[key] === 'object' || Array.isArray(schema[key])) { schema[key] = initialize(schema[key]); } }); return schema; } //# sourceMappingURL=initialize.mjs.map