ts-rplc is a utility tool to replace properties in an object. The catch is that this tool replaces properties anywhere in the object. It can handle complex structure including arrays etc. TL;DR replace property anywhere in an object
Motivation for creating this tool came from the need to sometimes make test data deterministic. Rather than always write a sketchy solution to this trivial task, I implemented a simple package utilizing fp-ts
npm install ts-rplc --save
All exported functions are curried
string -> string -> Object | Object[] -> Object | Object[]
import { replaceProperty } from 'ts-rplc';
const obj = {
test: 123,
};
/**
* 'test' => property name to search
* 'NewValue' => new value for property
* 'obj' => object or object array to transform
* */
const result = replaceProperty('test')('NewValue')(obj);
const expectedResult = {
test: 'NewValue',
};
// More examples can be found in src/replace-property/index.test.ts