@sprucelabs/schema
Version:
Static and dynamic binding plus runtime validation and transformation to ensure your app is sound. 🤓
21 lines (20 loc) • 701 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.selectChoicesToHash = selectChoicesToHash;
exports.schemaChoicesToHash = schemaChoicesToHash;
/** Pass the select options directly to create a value/label hash */
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 */
function schemaChoicesToHash(definition, fieldName) {
// @ts-ignore
return selectChoicesToHash(
// @ts-ignore
definition.fields?.[fieldName]?.options?.choices ?? []);
}