{"id":16153215,"url":"https://github.com/jameslmilner/tracked-json","last_synced_at":"2025-08-08T19:23:29.027Z","repository":{"id":41422283,"uuid":"509527327","full_name":"JamesLMilner/tracked-json","owner":"JamesLMilner","description":"JavaScript library for frictionless undo/redo for JSON objects ","archived":false,"fork":false,"pushed_at":"2022-07-08T13:43:20.000Z","size":1064,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-03T03:39:04.205Z","etag":null,"topics":["history","json","redo","undo","versions"],"latest_commit_sha":null,"homepage":"https://JamesLMilner.github.io/tracked-json","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JamesLMilner.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-01T16:50:15.000Z","updated_at":"2024-04-26T07:07:40.000Z","dependencies_parsed_at":"2022-09-13T04:41:31.844Z","dependency_job_id":null,"html_url":"https://github.com/JamesLMilner/tracked-json","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JamesLMilner%2Ftracked-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JamesLMilner%2Ftracked-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JamesLMilner%2Ftracked-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JamesLMilner%2Ftracked-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JamesLMilner","download_url":"https://codeload.github.com/JamesLMilner/tracked-json/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247569138,"owners_count":20959758,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["history","json","redo","undo","versions"],"created_at":"2024-10-10T01:10:36.153Z","updated_at":"2025-04-06T23:38:16.227Z","avatar_url":"https://github.com/JamesLMilner.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TrackedJSON\n\n![TackedJSON CI](https://github.com/JamesLMilner/tracked-json/actions/workflows/ci.yml/badge.svg)\n\nTrackedJSON is a JavaScript library which provides frictionless undo/redo for JSON objects.\n\nTrackedJSON tries to maintain a relatively minimal API - the core of the library is the `.data` property which represents the JSON object you want to keep track of. You can update it just like a regular JavaScript object, with the only requirement being that properties have to be valid JSON types.\n\n## Install\n\n```shell\nnpm install tracked-json\n```\n\n## Basic Usage\n\nYou can use it like so:\n\n```javascript\nconst tracked = new TrackedJSON();\n\n// tracked.data is an empty object at this point\n\ntracked.data.value = 1;\ntracked.data.value = 2;\ntracked.data.value = 3;\n\ntracked.undo();\ntracked.undo();\n\n// tracked.data.value === 1\n\ntracked.redo();\ntracked.redo();\n\n// tracked.data.value === 3\n```\n\n## Docs\n\n[See the docs here](https://jameslmilner.github.io/tracked-json/)\n\nCommon questions answered on usage:\n\n### How many undo/redo operations are there for my data object?\n\nYou can get the size of the undo stack using `undoSize` like so:\n\n```javascript\nconst tracked = new TrackedJSON({ initialState: { value: 0 } });\ntracked.data.value = 1;\ntracked.data.value = 2;\nconsole.log(tracked.undoSize); // 2\ntracked.undo();\ntracked.undo();\nconsole.log(tracked.redoSize); // 2\n```\n\n### How do I instantiate with a given state?\n\nYou can instantiate an object with a starting state like so:\n\n```javascript\nconst tracked = new TrackedJSON({ initialState: { value: 0 } });\nconsole.log(tracked.data.value); // 0\n```\n\n### Can I replace the whole data object with a new one?\n\nIf you want to replace the whole data object, this is possible and will be tracked as normal, like so:\n\n```javascript\nconst tracked = new TrackedJSON();\ntracked.data.value = 0;\ntracked.data = { value: 1 };\ntracked.undo();\nconsole.log(tracked.data.value); // 0\n```\n\n### Do I need to guard against non JSON?\n\nProperties and nested properties of the data object must be valid JSON. Attempting to set non valid JSON properties and will throw an error like so:\n\n```javascript\nconst tracked = new TrackedJSON();\ntracked.data.value = {}; // does not throw error\ntracked.data.value = 1; // does not throw error\ntracked.data.value = []; // does not throw error\ntracked.data.value = \"string\"; // does not throw error\ntracked.data.value = true; // does not throw error\n\ntracked.data.value = new Map(); // throws error\n```\n\n# License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjameslmilner%2Ftracked-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjameslmilner%2Ftracked-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjameslmilner%2Ftracked-json/lists"}