contador-de-metas 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/contador.js +109 -0
  2. package/package.json +21 -0
package/contador.js ADDED
@@ -0,0 +1,109 @@
1
+ // import dependecies
2
+ const fs = require("fs");
3
+ const readline = require("readline");
4
+
5
+ const rl = readline.createInterface({
6
+ input: process.stdin,
7
+ output: process.stdout,
8
+ });
9
+
10
+ // Cria uma função que retorna uma Promise para perguntar algo ao usuário
11
+ const askQuestion = (question) => {
12
+ return new Promise((resolve) => {
13
+ rl.question(question, (answer) => {
14
+ resolve(answer);
15
+ });
16
+ });
17
+ };
18
+
19
+ // read the text and split it on new lines
20
+ // const lines = fs.readFileSync("todo-18012025" + ".txt").toString().split("\r\n");
21
+ const lines = fs.readFileSync(".todo-16112025" + ".txt").toString().split("\n");
22
+ // const lines = fs.readFileSync("Novo Documento" + ".txt").toString().split("\n");
23
+
24
+ // All of the parse topics
25
+ let oldchanges = [];
26
+ let newchanges = [];
27
+
28
+ const regex = /(?:-\s*)?\[.*?\]|(?:-\s*)?.*?\|/;
29
+ // [ alguma coisa ]
30
+ // - [ alguma coisa ]
31
+ // alguma coisa|
32
+ // - alguma coisa|
33
+
34
+ // const regex = /\[X\]/
35
+ // [X]
36
+
37
+ // const regex = /\[\s*x\s*\]|\[\s*X\s*\]/
38
+ // [x], [X], [ x ], [ X ]
39
+
40
+ let contadorConclusao = 0
41
+ const regexConclusao = /\[\s*[^ ]+\s*\]/
42
+ // [x], [X], [ x ], [ X ], [ nao ]
43
+
44
+ let contadorNovaMeta = 0
45
+ const regexNovaMeta = /^[ \t]*-.*/;
46
+ // linhas que começam com traços mas pode ter tabulações ou espaços antes.
47
+
48
+ (async () => {
49
+ for(let i = 0; i<lines.length; i+=1){
50
+ if(lines[i].match(regexNovaMeta)){
51
+ oldchanges.push(lines[i])
52
+ console.log(lines[i])
53
+ contadorNovaMeta++
54
+ }
55
+ }
56
+ console.log(contadorNovaMeta, "novas metas ontem.")
57
+ const resposta1 = await askQuestion("Deseja continuar?")
58
+
59
+ let updatedLines
60
+ if(resposta1 == 1){
61
+ updatedLines = lines.map(line => {
62
+ // Verifica se a linha corresponde ao padrão
63
+ if (regexNovaMeta.test(line)) {
64
+ // Faz o replace apenas se o padrão for encontrado
65
+ // newchanges.push(line)
66
+ return line.replace(/-\s*/, '');
67
+ }
68
+ // Retorna a linha original se não corresponder ao padrão
69
+ return line;
70
+ });
71
+ // console.log(updatedLines)
72
+ }
73
+ // process.exit(0);
74
+
75
+ for(let j = 0; j<lines.length; j+=1){
76
+ if(lines[j].match(regexConclusao)){
77
+ oldchanges.push(lines[j])
78
+ console.log(lines[j])
79
+ contadorConclusao++
80
+ }
81
+ }
82
+ console.log(contadorConclusao, "concluídos ontem.")
83
+ const resposta2 = await askQuestion("Deseja continuar?")
84
+
85
+ if(resposta2 == 1 && resposta2 == 1){
86
+
87
+ updatedLines = updatedLines.map(line => {
88
+ // Verifica se a linha corresponde ao padrão
89
+ if (regexConclusao.test(line)) {
90
+ // Faz o replace apenas se o padrão for encontrado
91
+ // newchanges.push(line)
92
+ return line.replace(/\[\s*[^ ]+\s*\]/, 'X|');
93
+ }
94
+ // Retorna a linha original se não corresponder ao padrão
95
+ return line;
96
+ });
97
+ // console.log(updatedLines)
98
+
99
+ let txt = updatedLines.join("\n")
100
+ // console.log(txt)
101
+ fs.writeFileSync('Novo Documento' + '.txt', txt)
102
+ }
103
+
104
+ rl.close()
105
+ console.log(oldchanges)
106
+ console.log("-" + contadorConclusao + "-" + contadorNovaMeta + "-")
107
+ })();
108
+
109
+
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "contador-de-metas",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "contador.js",
6
+ "type": "module",
7
+ "files": ["contador.js"],
8
+ "scripts": {
9
+ "test": "echo \"Error: no test specified\" && exit 1"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/caio-venancio/contador-de-metas.git"
14
+ },
15
+ "author": "Caio Venâncio",
16
+ "license": "ISC",
17
+ "bugs": {
18
+ "url": "https://github.com/caio-venancio/contador-de-metas/issues"
19
+ },
20
+ "homepage": "https://github.com/caio-venancio/contador-de-metas#readme"
21
+ }