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

change-path

v0.0.1

Published

Given a new and old object, report changes

Downloads

5

Readme

#ChangePath

WARNING: EXPERIMENTAL MODULE

CODE IS TERRIBLY INEFFICIENT. JUST A POC.

CURRENTLY NO DATA VERSIONING SO DATA CAN EASILY FALL OUT OF SYNC.

DO NOT USE!!!!!!!!!!!

Given two objects, check for changes and report back the differences.

Build Status

##Origin

Designed to make responding to data changes particuarly easy at the most granular level.

Im my case when a user connects they are served the cached data (as html), the next time the JSON api is polled the two versions are compared with changePath, relevant changes are then sent out over websokets.

The intention being to ensure the user is always looking at the latest data but minimise data being sent over the wire.

##Install

npm install changePath

##Usage

The change path function only expects two objects.

    changePath = require('changePath');

    var obj1 = {
        foo: 'bar'
    };

    var obj2 = {
        foo: 'bar',
        baz: 'cheese'
    }

    var results = changePath('obj2', obj1, obj2);

    //results = [
    //    {
    //      change: 'new property added',
    //      name: 'obj2.baz',
    //      newValue: 'cheese',
    //      oldValue: null
    //    }
    //];

#Arrays Change path will report changes to an array of objects just so long as the items have an unique id property. Eg:

var oldData = {
    cheese: [
        {
            id: 1,
            name: 'Brie'
        }
    ]
}

var newData = {
    cheese: [
        {
            id: 1,
            name: 'Brie'
        },
        {
            id: 2,
            name: 'Red Leicester'
        }
    ]
}

var results = changePath('newData', oldData, newData);


##Change Codes

###Objects

The following changes codes would be reported against an object:

  • PROP_CREATE A new property has been added to an object.

  • PROP_UPDATE The value of a property has changed.

  • PROP_DELETE A property no longer exists.

###Arrays

The following change codes would be reports against an array:

  • ITEM_CREATE A new item has been added to the array.

  • ITEM_DELETE An item has been removed from an array.

  • ITEM_MOVE An items position in the array has changed. When new items are added/removed from the start of an array the offset is considered so the other items in the array should not report being moved.

  • ITEMS_SWAPPED Two items in the list have change position

#TODO

  • Simple arrays
  • TYPE_CHANGE