@sprucelabs/schema
Version:
Static and dynamic binding plus runtime validation and transformation to ensure your app is sound. 🤓
18 lines (17 loc) • 734 B
JavaScript
/** Pass the select options directly to create a value/label hash */
export function selectChoicesToHash(options) {
const partial = {};
options.forEach((option) => {
//@ts-ignore
partial[option.value] = option.label;
});
return partial;
}
/** Take a definition and a field name and returns a value/label hash */
export function schemaChoicesToHash(definition, fieldName) {
var _a, _b, _c, _d;
// @ts-ignore
return selectChoicesToHash(
// @ts-ignore
(_d = (_c = (_b = (_a = definition.fields) === null || _a === void 0 ? void 0 : _a[fieldName]) === null || _b === void 0 ? void 0 : _b.options) === null || _c === void 0 ? void 0 : _c.choices) !== null && _d !== void 0 ? _d : []);
}