-
Notifications
You must be signed in to change notification settings - Fork 4
/
space-out.mjs
61 lines (54 loc) · 1.6 KB
/
space-out.mjs
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import luxon from "luxon";
import fs from "fs";
import process from "process";
import { getRoamDate, nth } from "./helpers.mjs";
const DateTime = luxon.DateTime;
var data = "";
process.stdin.resume();
process.stdin.on("data", function(buf) {
data += buf.toString();
});
process.stdin.on("end", function() {
function chunkArray(myArray, chunk_size) {
var index = 0;
var arrayLength = myArray.length;
var tempArray = [];
for (index = 0; index < arrayLength; index += chunk_size) {
let myChunk = myArray.slice(index, index + chunk_size);
// Do something if you want with the group
tempArray.push(myChunk);
}
return tempArray;
}
const [instructionsRaw, ...linesRaw] = data.split("\n");
const instructions = instructionsRaw.replace(/[\-\#]/g, "").trim();
const [ratioStr, sizeStr, indent, initialStr] = instructions.split(",");
const ratio = parseInt(ratioStr || "1", 10);
const size = parseInt(sizeStr || "1", 10);
const initial = parseInt(initialStr || "1", 10);
const lines = chunkArray(linesRaw, size);
let c = 0;
const day = DateTime.local().plus({ days: initial });
lines.forEach(line => {
c += ratio;
if (day.plus({ days: c }).weekday > 5) {
c += 1;
}
if (day.plus({ days: c }).weekday > 5) {
c += 1;
}
if (indent) {
console.log(`[[${getRoamDate(day.plus({ days: c }))}]]`);
}
line.forEach(l => {
if (l.trim() === "") {
return;
}
if (indent) {
console.log(` ${l}`);
} else {
console.log(`${l} #[[${getRoamDate(day.plus({ days: c }))}]]`);
}
});
});
});