added prototype
This commit is contained in:
19
webseite-gulp-ts/backend/utils/json-modifier.js
Normal file
19
webseite-gulp-ts/backend/utils/json-modifier.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import fs from 'node:fs';
|
||||
import { v4 as id } from 'uuid';
|
||||
|
||||
console.log(id()); // 97412ca6-c7a8-4868-a49b-3cf4c2258dd8
|
||||
|
||||
try {
|
||||
const data = JSON.parse(fs.readFileSync('../data/products.json', 'utf-8'));
|
||||
|
||||
const products = data.map((product, index) => {
|
||||
return { _id: product._id || id(), position: index + 1, ...product };
|
||||
});
|
||||
|
||||
console.log(products);
|
||||
|
||||
fs.writeFileSync('../data/products.json', JSON.stringify(products, null, 2), 'utf-8');
|
||||
console.log('File modified');
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
Reference in New Issue
Block a user