-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutils.js
More file actions
executable file
·41 lines (33 loc) · 843 Bytes
/
utils.js
File metadata and controls
executable file
·41 lines (33 loc) · 843 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
39
40
41
const exec = require('./promises/exec');
const fs = require('fs');
const home = require('os').homedir();
function getConsoleSize(stdout) {
const dataString = String(stdout);
let lines = dataString.split('\n');
let cols = Number(lines[0].match(/^COLUMNS=([0-9]+);$/)[1]);
return cols;
}
function hideCursor() {
term("\033[?025l");
}
function term() {
console.log([...arguments].join(""));
}
function deleteItem(array, index) {
if (index === undefined) return array;
return [...array.slice(0, index), ...array.slice(index + 1)];
}
function saveFile(fileName, data) {
const dir = home + "/.codespell/";
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
fs.writeFileSync(fileName, data);
}
module.exports = {
term,
hideCursor,
saveFile,
deleteItem,
getConsoleSize
}