diff --git a/src/index.js b/src/index.js index 983c56433..37482bacc 100644 --- a/src/index.js +++ b/src/index.js @@ -1 +1,4 @@ export { createHeadlessForm } from './createHeadlessForm'; + +export { pickXKey } from './internals/helpers'; +export { buildCompleteYupSchema } from './yupSchema'; diff --git a/src/internals/helpers.js b/src/internals/helpers.js index ff7f6e46a..81111ccf6 100644 --- a/src/internals/helpers.js +++ b/src/internals/helpers.js @@ -10,10 +10,12 @@ import isEmpty from 'lodash/isEmpty'; import isFunction from 'lodash/isFunction'; /** - * Returns the object from the JSON-schema node using the key. - * + * Shorthand to lookup for keys with `x-jsf-*` preffix. * @param {Object} node - JSON-schema node - * @param {String} key - JSON-schema key name + * @param {"presentation"|"errorMessage"} key - JSON-schema key name + * @example + * pickKey(properties, 'presentation') + * is the same as properties["x-jsf-presentation"] * @returns {Object} */ export function pickXKey(node, key) { diff --git a/src/yupSchema.js b/src/yupSchema.js index 6ec2cf84b..362afc9e7 100644 --- a/src/yupSchema.js +++ b/src/yupSchema.js @@ -8,6 +8,7 @@ import { convertDiskSizeFromTo } from './utils'; /** * @typedef {import('./createHeadlessForm').FieldParameters} FieldParameters + * @typedef {import('../createHeadlessForm').JsfConfig} JsfConfig */ export const DEFAULT_DATE_FORMAT = 'yyyy-MM-dd'; @@ -297,6 +298,14 @@ function getSchema(fields = [], config) { return newSchema; } +/** + * Returns the Yup schema structure of given fields. + * These fields must be the same from + * const { fields } = createHeadlessForm() + * @param {Fields[]} fields - List of fields + * @param {JsfConfig} config - Config + * @returns + */ export function buildCompleteYupSchema(fields, config) { return object().shape(getSchema(fields, config), getNoSortEdges(fields)); }