samedi 21 mai 2022

I want to add random numbers to my renaming script

Im very new to JS and node. I want to edit a bunch of files at once. This works great. But how can I change one of the lines to a random number...

My code looks like this:

const fs = require("fs");
const args = process.argv.slice(2);
const inputFolder = args[0];
const dir = `${__dirname}/${inputFolder}/`;
const inputFiles = fs.readdirSync(dir).sort();



inputFiles.forEach((file) => {
let id = file.split(".").shift();
let data = JSON.parse(fs.readFileSync(`${dir}/${file}`));

data.name = `Crypto Jackpot Golden Ticket #${id}`;
data.image = `ipfs://QmcDuio2fvEtRmukuTc6yZuh3cyfezX9DqujgduUuSfYLJ/${id}.png`;
data.description = `Hold this NFT to be included in weekly jackpots with 3 entries`;


fs.writeFileSync(`${dir}/${file}`, JSON.stringify(data, null, 2));
console.log(data);
});

Under data.descrition I want to edit a field called "DNA" so I would put: data.DNA = //BUT WHAT GOES HERE TO MAKE THIS A RANDOM NUMBER

Thanks in advance!!!




Aucun commentaire:

Enregistrer un commentaire