first-npm-package-nicule
Version:
This isi first npm package
20 lines (17 loc) • 691 B
text/typescript
import { Hypermedia, HypermediaAction } from 'first-npm-package-nicule/core';
export function prefixValue(fieldName: string, prefix: string): (hypermediaAction: HypermediaAction, hypermedia: Hypermedia) => HypermediaAction {
return (hypermediaAction: HypermediaAction) => {
const { fields: oldFields, ...rest } = hypermediaAction;
const fields = [];
oldFields.forEach(({ name, value, ...remainder }) => {
if (fieldName === name) {
value = prefix + value;
}
fields.push({ name, value, ...remainder });
});
return {
...rest,
fields
};
};
}