ts-rplc
TypeScript icon, indicating that this package has built-in type declarations

0.0.7 • Public • Published

CI codecov npm version

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

Package Sidebar

Install

npm i ts-rplc

Weekly Downloads

5

Version

0.0.7

License

MIT

Unpacked Size

8 kB

Total Files

8

Last publish

Collaborators

  • jarkkosk