npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

goldwasher-json

v0.6.0

Published

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

Downloads

5

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;

 // 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:

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:

 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.

{ 
    "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<boolean>