readlineq 2.0.3 → 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 +7 -7
- package/README.md +21 -16
- package/index.js +49 -92
- package/package.json +37 -33
- package/test/index.js +13 -14
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Copyright 2017 Hai Liang Wang <hailiang.hl.wang@gmail.com>
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
-
|
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
-
|
|
7
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.OF
|
|
1
|
+
Copyright 2017 Hai Liang Wang <hailiang.hl.wang@gmail.com>
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.OF
|
package/README.md
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
# readlineq
|
|
2
|
-
read or write file by lines with promise.
|
|
3
|
-
|
|
4
|
-
```
|
|
5
|
-
var readlineq = require('readlineq');
|
|
6
|
-
# read lines
|
|
7
|
-
var lines = await readlineq('./tmp/stopwords.txt');
|
|
8
|
-
// console.log(lines);
|
|
9
|
-
|
|
10
|
-
# write lines
|
|
11
|
-
|
|
12
|
-
// console.log(lines);
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
# LICENSE
|
|
16
|
-
MIT
|
|
1
|
+
# readlineq
|
|
2
|
+
read or write file by lines with promise.
|
|
3
|
+
|
|
4
|
+
```
|
|
5
|
+
var readlineq = require('readlineq');
|
|
6
|
+
# read lines with Promise
|
|
7
|
+
var lines = await readlineq('./tmp/stopwords.txt');
|
|
8
|
+
// console.log(lines);
|
|
9
|
+
|
|
10
|
+
# write lines which is sync by default
|
|
11
|
+
readlineq('./tmp/test.txt', ["foo\n", "bar\n"]);
|
|
12
|
+
// console.log(lines);
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
# LICENSE
|
|
16
|
+
MIT
|
|
17
|
+
|
|
18
|
+
[![chatoper banner][co-banner-image]][co-url]
|
|
19
|
+
|
|
20
|
+
[co-banner-image]: https://user-images.githubusercontent.com/3538629/135558449-9739c98c-30aa-4b49-916b-87182520c0c6.png
|
|
21
|
+
[co-url]: https://www.chatopera.com
|
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,33 +1,37 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "readlineq",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Read file by lines",
|
|
5
|
-
"main": "index.js",
|
|
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
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "readlineq",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "Read or write file by lines with promise.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"directories": {
|
|
8
|
+
"test": "test"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "ava"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+ssh://git@github.com/chatopera/node-readlineq.git"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"text",
|
|
19
|
+
"read-text",
|
|
20
|
+
"write-text"
|
|
21
|
+
],
|
|
22
|
+
"author": "Hai Liang Wang <hailiang.hl.wang@gmail.com>",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/chatopera/node-readlineq/issues"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://github.com/chatopera/node-readlineq#readme",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"debug": "^4.4.3"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"ava": "^6.4.1"
|
|
33
|
+
},
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=18.0.0"
|
|
36
|
+
}
|
|
37
|
+
}
|
package/test/index.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var lines =
|
|
6
|
-
|
|
7
|
-
t.pass()
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
test('Readlines # write', async (t)=>{
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
t.pass()
|
|
1
|
+
import test from "ava";
|
|
2
|
+
import readlineq from "../index.js";
|
|
3
|
+
|
|
4
|
+
test('Readlines # read', async (t) => {
|
|
5
|
+
var lines = readlineq('./tmp/stopwords.txt');
|
|
6
|
+
console.log(lines);
|
|
7
|
+
t.pass()
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
test('Readlines # write', async (t) => {
|
|
11
|
+
var lines = readlineq('./tmp/test.txt', ["foo\n", "bar\n"]);
|
|
12
|
+
console.log(lines);
|
|
13
|
+
t.pass()
|
|
15
14
|
})
|