Last active
September 5, 2016 20:36
-
-
Save sosnovskyas/353708eb47889f084abe4dca4663ce97 to your computer and use it in GitHub Desktop.
re-generate guid's in file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var guid = /([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/ig; | |
var inputFile = 'input.json'; | |
var outputFile = 'result.json'; | |
// читаем | |
fs.readFile(inputFile, 'utf8', function (err,data) { | |
if (err) { | |
return console.log(err); | |
} | |
// console.log(data); | |
// преобразуем | |
data = data.replace(guid, () => { | |
function s4() { | |
return Math.floor((1 + Math.random()) * 0x10000) | |
.toString(16) | |
.substring(1); | |
} | |
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + | |
s4() + '-' + s4() + s4() + s4(); | |
}); | |
// пищем | |
fs.writeFile(outputFile, data, 'utf8', function(err) { | |
if(err) { | |
return console.log(err); | |
} | |
console.log("The file was saved!"); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment