-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscratch.js
More file actions
38 lines (31 loc) · 910 Bytes
/
scratch.js
File metadata and controls
38 lines (31 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const fs = require("fs").promises;
const DB_PATH = "./db/db.json";
function transform(transFN) {
fs.readFile(DB_PATH)
.then(async (content) => {
let db = JSON.parse(content);
fs.writeFile(DB_PATH, JSON.stringify(transFN(db)));
})
.catch((e) => {
console.error(e);
});
}
transform((db) => {
Object.entries(db).forEach(([k, v]) => {
if (v.author) {
v.authors = v.author ? v.author : "";
}
delete v.author;
});
return db;
});
// // how to download an image for sharp (do we really have to go through the FS tho?)
// const fs = require("fs").promises;
// const path =
// "https://raw.githubusercontent.com/b2renger/Introduction_Arduino/master/assets/set_neopixels_rgb.gif";
// fetch(path)
// .then((res) => res.blob())
// .then((blob) => {
// console.log(blob);
// fs.writeFile(`./${path.split("/").pop()}`, blob.stream());
// });