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