json-version-control
Advanced tools
Comparing version 1.2.0 to 1.2.1
12
index.js
@@ -20,4 +20,6 @@ const fs = require("fs"); | ||
// Ensure the history directory exists | ||
if (!fs.existsSync(this.historyDirectory)) { | ||
fs.mkdirSync(this.historyDirectory); | ||
try { | ||
fs.mkdirSync(this.historyDirectory, { recursive: true }); | ||
} catch (err) { | ||
console.error(`Error creating history directory: ${err}`); | ||
} | ||
@@ -27,3 +29,7 @@ | ||
if (!fs.existsSync(this.headFilePath)) { | ||
this.writeJsonFile(this.headFilePath, {}); | ||
try { | ||
fs.writeFileSync(this.headFilePath, "{}"); | ||
} catch (err) { | ||
console.error(`Error creating head file: ${err}`); | ||
} | ||
} | ||
@@ -30,0 +36,0 @@ } |
{ | ||
"name": "json-version-control", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "A lightweight and easy-to-use package that provides version control functionality for JSON files.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -67,6 +67,14 @@ # json-version-control | ||
// Save a new version | ||
const newData = { name: 'John Doe', age: 30 }; | ||
vc.saveNewVersion(newData); | ||
// Save a new version - Version 1 | ||
const dataV1 = { name: 'John Doe', age: 30 }; | ||
vc.saveNewVersion(dataV1); | ||
// Save a new version - Version 2 | ||
const dataV2 = { name: 'John Doe', age: 35 }; | ||
vc.saveNewVersion(dataV2); | ||
// Save a new version - Version 3 | ||
const dataV3 = { name: 'John Smith', age: 35 }; | ||
vc.saveNewVersion(dataV3); | ||
// Get the list of available history versions | ||
@@ -76,3 +84,3 @@ const historyVersions = vc.getHistoryVersions(); | ||
// Revert to a previous version | ||
// Revert to a previous version - Revert to Version 2 | ||
const previousVersion = vc.getPreviousVersion(); | ||
@@ -86,3 +94,3 @@ if (previousVersion) { | ||
// Apply the next version | ||
// Apply the next version - Apply Version 3 | ||
const nextVersion = vc.getNextVersion(); | ||
@@ -95,2 +103,19 @@ if (nextVersion) { | ||
} | ||
// Get the source object from the initial version | ||
const initialVersion = vc.getInitialVersion(); | ||
console.log('Source object from the initial version:', initialVersion); | ||
// Get the source object from the latest version | ||
const latestVersion = vc.getLatestVersion(); | ||
console.log('Source object from the latest version:', latestVersion); | ||
// Apply the initial version | ||
vc.applyInitialVersion(); | ||
console.log('Applied the initial version.'); | ||
// Apply the latest version | ||
vc.applyLatestVersion(); | ||
console.log('Applied the latest version.'); | ||
``` | ||
@@ -97,0 +122,0 @@ ## License |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15549
286
121