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 🙏

© 2026 – Pkg Stats / Ryan Hefner

json-history

v0.6.5

Published

* A plugin can `redo`, `undo` deep nested JSON. * **Vue** or **React** friendly. * Support `Date` as value but `regex` and `function` * min+gzipped 12.2kB * uses [google-diff-match-patch](https://github.com/google/diff-match-patch) for long text diffs (di

Readme

json-history

  • A plugin can redo, undo deep nested JSON.
  • Vue or React friendly.
  • Support Date as value but regex and function
  • min+gzipped 12.2kB
  • uses google-diff-match-patch for long text diffs (diff at character level)
  • Import jsondiffpatch but without the formatter.

The source code still messy but works fine. I will refactor once have time.

Installing

  yarn add json-history
const history = new JsonHistory({
  tree: object | array
})

Options

new JsonHistory({
  tree = {}, 
  steps = 50, // how many steps can redo 
  backUpDeltas = [], // can backup the previous deltas
  callback = {
    onRecorded() {},
    onEachPatch() {},
    onUndo() {},
    onUndid() {},
    onRedo() {},
    onRedid() {},
  },  
  setter(tree, key, value) {
    Vue.set(tree, key, value)
  },
  deleter(tree, key) {
    Vue.delete(tree, key)
  }
})

Record / Redo / Undo

Update any value of object or array by multi records. Can redo or undo after record.

Accept array or an object.

const history = new JsonHistory({
  tree: {
    1: [1, 3],
    a: [{}, { 1: 3 }],
    b: { c: 5, d: { e: 6 }}
  }
})

history.record({ 
  path: '1[4]',
  value: {},
  insertArray: true
})

expect(history.tree).toEqual({
  1: [1, 3, null, null, {}],
  a: [{}, {1: 3}],
  b: {c: 5, d: {e: 6}}
})

history.record([
  {
    path: '1[4]',
    value: [],
    insertArray: true
  },
  {
    path: '1[5]',
    value: [1, 2, 3]
  }
])

expect(history.tree).toEqual({
  1: [1, 3, null, null, [], [1, 2, 3]],
  a: [{}, {1: 3}],
  b: {c: 5, d: {e: 6}}
})

history.record([{
  path: 'a.b',
  value: 123
}])

expect(history.tree).toEqual({
  1: [1, 3, null, null, [], [1, 2, 3]],
  a: { b: 123 },
  b: {c: 5, d: {e: 6}}
})

expect(history.deltas.length).toEqual(3)

history.undo()
history.redo()
history.undo()
history.undo()
history.undo()
expect(history.tree).toEqual(tree)

Delete

Delete object key.

Same as record with undefined value.

const history = new JsonHistory({
  tree: {
    1: [1, 3],
    a: [{}, { 1: 3 }],
    b: { c: 5, d: { e: 6 }}
  }
})

history.delete([{
  path: '1'
}])

expect(history.tree).toEqual({
  a: [{}, {1: 3}],
  b: {c: 5, d: {e: 6}}
})

Snapshot

Replace the whole tree and record a step.

const history = new JsonHistory({
  tree: [1, 2, 3]
})

history.snapShot([1, { a: 4 }])

expect(history.tree).toEqual([1, { a: 4 }])

history.undo()

expect(history.tree).toEqual([1, 2, 3])

Merge records

Can merge multi actions, such as delete or record.

 const history = new JsonHistory({
  tree: {
    1: [1, 3],
    a: [{}, { 1: 3 }],
    b: { c: 5, d: { e: 6 }}
  }
})

history.recordsMerge(() => {
  history.record([
    {
      path: 'b',
      value: undefined
    }
  ])

  history.record([
    {
      path: 1,
      value: []
    }
  ])

  history.record([
    {
      path: 'a.length.length',
      value: {}
    }
  ])
})

expect(history.deltas.length).toEqual(1)

expect(history.tree).toEqual({
  1: [],
  a: {
    length: {
      length: {}
    }
  }
})

Clean records

Can pass a function to check the delta should delete or not.

const shouldDeleteFunction = function (defalt) {
  const key = Object.keys(delta)[0]
  return key === 'this one should delete'
}
cleanDeltas(shouldDeleteFunction)
const history = new JsonHistory({
  tree: {
    1: [1, 3],
    a: [{}, { 1: 3 }],
    b: { c: 5, d: { e: 6 }}
  }
})

history.record([
  {
    path: 'b',
    value: undefined
  }
])

history.record([
  {
path: 1,
value: []
  }
])

history.record([
  {
path: 'a.length.length',
value: {}
  }
])

history.undo()

history.cleanDeltas(delta => {
  const key = Object.keys(delta)[0]
  return key === '1'
})

history.undo()
history.undo()

expect(history.tree).toEqual({
  1: [],
  a: [{}, {1: 3}],
  b: {c: 5, d: {e: 6}}
})

More cases

https://github.com/lustan3216/json-history/tree/master/tests