readlineq 2.0.5 → 3.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.
- package/LICENSE +0 -0
- package/README.md +0 -0
- package/index.js +49 -92
- package/package.json +8 -4
- package/test/index.js +8 -9
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
File without changes
|
package/index.js
CHANGED
|
@@ -1,92 +1,49 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* read lines by file path
|
|
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
|
-
* @param
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
// outputStream.on(
|
|
52
|
-
// "finish",
|
|
53
|
-
// function handleFinish() {
|
|
54
|
-
// resolve();
|
|
55
|
-
// }
|
|
56
|
-
// );
|
|
57
|
-
|
|
58
|
-
// outputStream.on(
|
|
59
|
-
// "error",
|
|
60
|
-
// function handleFinish(err) {
|
|
61
|
-
// reject(err);
|
|
62
|
-
// }
|
|
63
|
-
// );
|
|
64
|
-
// });
|
|
65
|
-
// }
|
|
66
|
-
//
|
|
67
|
-
/**
|
|
68
|
-
* Write lines to file
|
|
69
|
-
* @param {[type]} from_ [description]
|
|
70
|
-
* @param {[type]} to_ [description]
|
|
71
|
-
* @return {[type]} [description]
|
|
72
|
-
*/
|
|
73
|
-
function _write(lines, to_) {
|
|
74
|
-
if (typeof lines === "string") {
|
|
75
|
-
fs.writeFileSync(to_, lines);
|
|
76
|
-
} else if (lines.length > 0) {
|
|
77
|
-
fs.writeFileSync(to_, lines.join(""));
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* write or read data
|
|
83
|
-
* @param {[type]} file_path [description]
|
|
84
|
-
* @param {[type]} obj [description]
|
|
85
|
-
* @return {[type]} [description]
|
|
86
|
-
*/
|
|
87
|
-
exports = module.exports = function (file_path, obj) {
|
|
88
|
-
if (obj) {
|
|
89
|
-
return _write(obj, file_path);
|
|
90
|
-
}
|
|
91
|
-
return _read(file_path);
|
|
92
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* read lines by file path
|
|
3
|
+
*/
|
|
4
|
+
import Debug from "debug";
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
|
|
7
|
+
const debug = Debug("readlineq");
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* read file into lines
|
|
11
|
+
* @param {[type]} file_path [description]
|
|
12
|
+
* @return {[type]} [description]
|
|
13
|
+
*/
|
|
14
|
+
function _read(file_path) {
|
|
15
|
+
let lines = [];
|
|
16
|
+
const allFileContents = fs.readFileSync(file_path, 'utf-8');
|
|
17
|
+
allFileContents.split(/\r?\n/).forEach(line => {
|
|
18
|
+
lines.push(line + "\n");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return lines;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Write lines to file
|
|
26
|
+
* @param {[type]} from_ [description]
|
|
27
|
+
* @param {[type]} to_ [description]
|
|
28
|
+
* @return {[type]} [description]
|
|
29
|
+
*/
|
|
30
|
+
function _write(lines, to_) {
|
|
31
|
+
if (typeof lines === "string") {
|
|
32
|
+
fs.writeFileSync(to_, lines);
|
|
33
|
+
} else if (lines.length > 0) {
|
|
34
|
+
fs.writeFileSync(to_, lines.join(""));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* write or read data
|
|
40
|
+
* @param {[type]} file_path [description]
|
|
41
|
+
* @param {[type]} obj [description]
|
|
42
|
+
* @return {[type]} [description]
|
|
43
|
+
*/
|
|
44
|
+
export default function (file_path, obj) {
|
|
45
|
+
if (obj) {
|
|
46
|
+
return _write(obj, file_path);
|
|
47
|
+
}
|
|
48
|
+
return _read(file_path);
|
|
49
|
+
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "readlineq",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Read or write file by lines with promise.",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"directories": {
|
|
7
8
|
"test": "test"
|
|
8
9
|
},
|
|
@@ -25,9 +26,12 @@
|
|
|
25
26
|
},
|
|
26
27
|
"homepage": "https://github.com/chatopera/node-readlineq#readme",
|
|
27
28
|
"dependencies": {
|
|
28
|
-
"debug": "^
|
|
29
|
+
"debug": "^4.4.3"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
|
-
"ava": "^
|
|
32
|
+
"ava": "^6.4.1"
|
|
33
|
+
},
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=18.0.0"
|
|
32
36
|
}
|
|
33
|
-
}
|
|
37
|
+
}
|
package/test/index.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import test from "ava";
|
|
2
|
+
import readlineq from "../index.js";
|
|
2
3
|
|
|
3
|
-
test('Readlines # read', async (t)=>{
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
// console.log(lines);
|
|
4
|
+
test('Readlines # read', async (t) => {
|
|
5
|
+
var lines = readlineq('./tmp/stopwords.txt');
|
|
6
|
+
console.log(lines);
|
|
7
7
|
t.pass()
|
|
8
8
|
})
|
|
9
9
|
|
|
10
|
-
test('Readlines # write', async (t)=>{
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
// console.log(lines);
|
|
10
|
+
test('Readlines # write', async (t) => {
|
|
11
|
+
var lines = readlineq('./tmp/test.txt', ["foo\n", "bar\n"]);
|
|
12
|
+
console.log(lines);
|
|
14
13
|
t.pass()
|
|
15
14
|
})
|