0.0.7 • Published 1 year ago
ts-rplc v0.0.7
TS-RPLC
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
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
Install
npm install ts-rplc --save
Usage
All exported functions are curried
replaceProperty
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