first-npm-package-nicule
Version:
This isi first npm package
20 lines (16 loc) • 673 B
text/typescript
import { HypermediaAction } from 'first-npm-package-nicule/core';
export function hideFieldIfNotNull(fieldName: string): (hypermediaAction: HypermediaAction) => HypermediaAction {
return (hypermediaAction: HypermediaAction) => {
const { fields: oldFields, ...rest } = hypermediaAction;
const fields = oldFields.map(({ name, type, value, ...restField }) => {
if (name === fieldName && (value !== undefined && value !== null)) {
type = 'hidden';
}
return { name, type, value, ...restField };
});
return {
...rest,
fields
};
};
}