# goldwasher-json

> Goldwasher lets you refine chunks of JSON data used in your tests by removing all values which don't inflience the result.

Latest version **0.6.0** (published 2019-04-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install goldwasher-json
pnpm add goldwasher-json
yarn add goldwasher-json
bun add goldwasher-json
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.0 |
| Published | 2019-04-03 |
| First published | 2019-03-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 100.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ivan Koshelev |
| Maintainers | ikoshelev |
| Keywords | data tree-shaking, data pruning, data, pruning, tree-shaking |

## Links

- npm: https://www.npmjs.com/package/goldwasher-json
- Repository: https://github.com/IKoshelev/goldwasher-json
- Homepage: https://github.com/IKoshelev/goldwasher-json#readme
- Issues: https://github.com/IKoshelev/goldwasher-json/issues
- npm.io page: https://npm.io/package/goldwasher-json

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^4.0.0

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 0.6.0 (latest) — 2019-04-03
- 0.5.0 — 2019-04-03
- 0.4.0 — 2019-04-02
- 0.3.0 — 2019-03-29
- 0.2.0 — 2019-03-29
- 0.1.0 — 2019-03-28

## README

# goldwasher-json

lets you refine chunks of JSON data used in your tests by removing all values which don't inflience the result.

`npm install --save-dev goldwasher-json`

## TL;DR;

```typescript
 // when you have a unit test... 
 it('simplePrice calclculation calculates correctly', () => {
    
    // which uses a big chunk of json you took from runtime\newtwork monitoring
    let bigChunkOfJson = getTestData();

    // you can temporarily add godlwash to the test, to get the minimal subset of data
    // that still passes the test
    let goldwashedData = goldwash(bigChunkOfJson, (data) => {
        
        let result = blackboxRateCalulationFunction(data); // orifinally used bigChunkOfJson

        return result.simplePrice === 88.752;
    });

    //and start using goldwashed data in your test instead of original full chunk
    console.log(JSON.stringify(goldwashedData));
});
```

## usage

Imagine a situation. In a car rental company, you start working on a 10 year old module 
for calculating different price rates. Your goal is to remove outdated irrelevant calculations
and start adding new features to the module without braking still used ones. 
A typical calculation function that you have to clean is 500+ lines of code :-(.

Ofcourse, you start by trying to cover your module with unit tests for most frequent paths. 
You check logs, retrieve JSON data for a typical used request and its resulting rate.

You end up with a test like this:

```typescript
let carRentalRequest = {
    renter: {
        name: "John Smith",
        loyaltyBonus: 0.07,
        rentalHistory: [
            { duration: 10, price: 1500, dates: [/**/] },
            { duration: 20, price: 3000, dates: [/**/] },
            { duration: 105, price: 12000, dates: [/**/] },
            // 2 years of rental history
        ]
    },
    rentOptions: {
        duration: 3,
        corporatePartner: 5,
        bonusMilage: 1000
        //...20 more options
    },
    carProfile: {
        rawPrice: 15000,
        inflationAdjustedPrice: 17200,
        amotrization: 0.72,
        taxationPremium: 0.02,
        articleC20Rate: 0.03,
        //... more of the same
        bonusCoeficients: {
            promo5for5: 0.12,
            miles1000: 2,
            coproratePartnership: 10,
            rideTheBrand: 1.2,
            //... 10 years of promo options
        }
    }
}

it('simplePrice calclculation calculates correctly', () => {

    let result = blackboxRateCalulationFunction(carRentalRequest);

    expect(result.simplePrice).to.equal(88.752);
});
```

Doesn't help much to understand, what is actually happening.
So, modify the test to temorarily include golwashing: 

```typescript
 it('simplePrice calclculation calculates correctly', () => {

    let goldwashedData = goldwash(carRentalRequest, (data) => {
        
        let result = blackboxRateCalulationFunction(data);

        return result.simplePrice === 88.752;
    });

    console.log(JSON.stringify(goldwashedData));
});
```

And in console you will get the subset of your JSON that still produces result expected by test.

```typescript 
{ 
    "renter": { 
        "name": "John Smith", 
        "loyaltyBonus": 0.07, 
        "rentalHistory": [
            null, 
            null, 
            { "duration": 105 }
        ] }, 
    "rentOptions": { 
        "duration": 3, 
        "corporatePartner": 5 
    }, 
    "carProfile": { 
        "inflationAdjustedPrice": 17200, 
        "amotrization": 0.72 
    } 
}
```

You can now use this data in your test instead of the previous intimidatingly big chunk.
You can also use it to better understand, which values play actual role in each calculation,
and remove unused values.

# async?

Yes, via `goldwashAsync`, which expect testing function to return Promise&lt;boolean&gt;

---
_Source: https://npm.io/package/goldwasher-json · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
