@util.js/node-files 0.41.3 → 0.41.5
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/README.md +0 -1
- package/lib/Files.js +6 -6
- package/package.json +9 -10
- package/test/FilesTest.js +33 -33
- package/test/Files_sanitizeFilename_Test.js +1 -1
- package/LICENSE +0 -21
package/README.md
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
<p>
|
|
6
6
|
<a href="https://www.npmjs.com/package/@util.js/node-files"><img alt="NPM Status" src="https://img.shields.io/npm/v/@util.js/node-files.svg?style=flat"></a>
|
|
7
|
-
<a href="https://travis-ci.org/creemama/utiljs"><img alt="Travis CI Build Status" src="https://img.shields.io/travis/creemama/utiljs/master.svg?style=flat-square&label=Travis+CI"></a>
|
|
8
7
|
</p>
|
|
9
8
|
|
|
10
9
|
@util.js/node-files is part of [Util.js](https://github.com/creemama/utiljs).
|
package/lib/Files.js
CHANGED
|
@@ -135,17 +135,17 @@ module.exports = class Files {
|
|
|
135
135
|
return (async function () {
|
|
136
136
|
if (!objects().isDefined(params))
|
|
137
137
|
throw new TypeError(
|
|
138
|
-
`We expected params to be defined, but it was ${params}
|
|
138
|
+
`We expected params to be defined, but it was ${params}.`,
|
|
139
139
|
);
|
|
140
140
|
const { dir, ext } = params;
|
|
141
141
|
|
|
142
142
|
if (!objects().isDefined(dir))
|
|
143
143
|
throw new TypeError(
|
|
144
|
-
`We expected params.dir to be defined, but it was ${dir}
|
|
144
|
+
`We expected params.dir to be defined, but it was ${dir}.`,
|
|
145
145
|
);
|
|
146
146
|
if (!objects().isDefined(ext))
|
|
147
147
|
throw new TypeError(
|
|
148
|
-
`We expected params.ext to be defined, but it was ${ext}
|
|
148
|
+
`We expected params.ext to be defined, but it was ${ext}.`,
|
|
149
149
|
);
|
|
150
150
|
|
|
151
151
|
const files = await thiz.readdir(dir);
|
|
@@ -167,18 +167,18 @@ module.exports = class Files {
|
|
|
167
167
|
filesWithExtensionSync(params) {
|
|
168
168
|
if (!objects().isDefined(params))
|
|
169
169
|
throw new TypeError(
|
|
170
|
-
`We expected params to be defined, but it was ${params}
|
|
170
|
+
`We expected params to be defined, but it was ${params}.`,
|
|
171
171
|
);
|
|
172
172
|
|
|
173
173
|
const { dir, ext } = params;
|
|
174
174
|
|
|
175
175
|
if (!objects().isDefined(dir))
|
|
176
176
|
throw new TypeError(
|
|
177
|
-
`We expected params.dir to be defined, but it was ${dir}
|
|
177
|
+
`We expected params.dir to be defined, but it was ${dir}.`,
|
|
178
178
|
);
|
|
179
179
|
if (!objects().isDefined(ext))
|
|
180
180
|
throw new TypeError(
|
|
181
|
-
`We expected params.ext to be defined, but it was ${ext}
|
|
181
|
+
`We expected params.ext to be defined, but it was ${ext}.`,
|
|
182
182
|
);
|
|
183
183
|
|
|
184
184
|
const files = this.readdirSync(dir);
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Chris Topher <c@creemama.com>",
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"@util.js/objects": "0.41.
|
|
5
|
-
"@util.js/promises": "0.41.
|
|
6
|
-
"@util.js/strings": "0.41.
|
|
4
|
+
"@util.js/objects": "0.41.5",
|
|
5
|
+
"@util.js/promises": "0.41.5",
|
|
6
|
+
"@util.js/strings": "0.41.5",
|
|
7
7
|
"graceful-fs": "4.2.11",
|
|
8
|
-
"mkdirp": "3.0.
|
|
8
|
+
"mkdirp": "3.0.1",
|
|
9
9
|
"ncp": "2.0.0",
|
|
10
|
-
"read-last-lines": "1.
|
|
11
|
-
"rimraf": "
|
|
12
|
-
"sanitize-filename": "1.6.
|
|
13
|
-
"touch": "3.1.
|
|
10
|
+
"read-last-lines": "1.10.0",
|
|
11
|
+
"rimraf": "6.1.3",
|
|
12
|
+
"sanitize-filename": "1.6.4",
|
|
13
|
+
"touch": "3.1.1"
|
|
14
14
|
},
|
|
15
15
|
"description": "JavaScript Node.js utility methods for files",
|
|
16
16
|
"devDependencies": {
|
|
@@ -38,6 +38,5 @@
|
|
|
38
38
|
"type": "git",
|
|
39
39
|
"url": "https://github.com/creemama/utiljs/tree/master/packages/utiljs-node-files"
|
|
40
40
|
},
|
|
41
|
-
"version": "0.41.
|
|
42
|
-
"gitHead": "e17139b7f85c3abec178d8facdacc2aa6c5bb553"
|
|
41
|
+
"version": "0.41.5"
|
|
43
42
|
}
|
package/test/FilesTest.js
CHANGED
|
@@ -45,7 +45,7 @@ describe("Files", function () {
|
|
|
45
45
|
lines = await files.readLastLines(
|
|
46
46
|
new URL("file://" + __filename),
|
|
47
47
|
3,
|
|
48
|
-
"utf8"
|
|
48
|
+
"utf8",
|
|
49
49
|
);
|
|
50
50
|
expect(lines).to.eql(" });\n });\n});\n");
|
|
51
51
|
}
|
|
@@ -53,14 +53,14 @@ describe("Files", function () {
|
|
|
53
53
|
lines = await files.readLastLines(
|
|
54
54
|
Buffer.from(__filename, "utf8"),
|
|
55
55
|
3,
|
|
56
|
-
"utf8"
|
|
56
|
+
"utf8",
|
|
57
57
|
);
|
|
58
58
|
expect(lines).to.eql(" });\n });\n});\n");
|
|
59
59
|
|
|
60
60
|
lines = await files.readLastLines(
|
|
61
61
|
Buffer.from(__filename, "utf8"),
|
|
62
62
|
3,
|
|
63
|
-
Buffer.from("utf8", "utf8")
|
|
63
|
+
Buffer.from("utf8", "utf8"),
|
|
64
64
|
);
|
|
65
65
|
expect(lines).to.eql(" });\n });\n});\n");
|
|
66
66
|
});
|
|
@@ -159,7 +159,7 @@ describe("Files", function () {
|
|
|
159
159
|
.readLastLines(new URL("http://www.google.com"), 3)
|
|
160
160
|
.then((lines) => assert.fail())
|
|
161
161
|
.catch((error) =>
|
|
162
|
-
expect(error.message).to.eql("The URL must be of scheme file")
|
|
162
|
+
expect(error.message).to.eql("The URL must be of scheme file"),
|
|
163
163
|
);
|
|
164
164
|
|
|
165
165
|
// The method fails if path is a directory.
|
|
@@ -168,8 +168,8 @@ describe("Files", function () {
|
|
|
168
168
|
.then((lines) => assert.fail())
|
|
169
169
|
.catch((error) =>
|
|
170
170
|
expect(error.message).to.eql(
|
|
171
|
-
"EISDIR: illegal operation on a directory, read"
|
|
172
|
-
)
|
|
171
|
+
"EISDIR: illegal operation on a directory, read",
|
|
172
|
+
),
|
|
173
173
|
);
|
|
174
174
|
|
|
175
175
|
// The method fails if path is one of the primitive types other than string.
|
|
@@ -198,7 +198,7 @@ describe("Files", function () {
|
|
|
198
198
|
files.readLastLines(__dirname, 3, (error, lines) => {
|
|
199
199
|
try {
|
|
200
200
|
expect(error.message).to.eql(
|
|
201
|
-
"EISDIR: illegal operation on a directory, read"
|
|
201
|
+
"EISDIR: illegal operation on a directory, read",
|
|
202
202
|
);
|
|
203
203
|
callback();
|
|
204
204
|
} catch (e) {
|
|
@@ -212,8 +212,8 @@ describe("Files", function () {
|
|
|
212
212
|
.then((lines) => assert.fail())
|
|
213
213
|
.catch((error) =>
|
|
214
214
|
expect(error.message).to.eql(
|
|
215
|
-
"Cannot convert a Symbol value to a number"
|
|
216
|
-
)
|
|
215
|
+
"Cannot convert a Symbol value to a number",
|
|
216
|
+
),
|
|
217
217
|
);
|
|
218
218
|
});
|
|
219
219
|
it("should fail if the encoding is invalid", async function () {
|
|
@@ -221,14 +221,14 @@ describe("Files", function () {
|
|
|
221
221
|
.readLastLines(__filename, 3, false)
|
|
222
222
|
.then((lines) => assert.fail())
|
|
223
223
|
.catch((error) =>
|
|
224
|
-
expect(error.message).to.eql("Unknown encoding: false")
|
|
224
|
+
expect(error.message).to.eql("Unknown encoding: false"),
|
|
225
225
|
);
|
|
226
226
|
|
|
227
227
|
await files
|
|
228
228
|
.readLastLines(__filename, 3, NaN)
|
|
229
229
|
.then((lines) => assert.fail())
|
|
230
230
|
.catch((error) =>
|
|
231
|
-
expect(error.message).to.eql("Unknown encoding: NaN")
|
|
231
|
+
expect(error.message).to.eql("Unknown encoding: NaN"),
|
|
232
232
|
);
|
|
233
233
|
|
|
234
234
|
await files
|
|
@@ -245,7 +245,7 @@ describe("Files", function () {
|
|
|
245
245
|
.readLastLines(__filename, 3, "frog")
|
|
246
246
|
.then((lines) => assert.fail())
|
|
247
247
|
.catch((error) =>
|
|
248
|
-
expect(error.message).to.eql("Unknown encoding: frog")
|
|
248
|
+
expect(error.message).to.eql("Unknown encoding: frog"),
|
|
249
249
|
);
|
|
250
250
|
|
|
251
251
|
await files
|
|
@@ -253,8 +253,8 @@ describe("Files", function () {
|
|
|
253
253
|
.then((lines) => assert.fail())
|
|
254
254
|
.catch((error) =>
|
|
255
255
|
expect(error.message).to.eql(
|
|
256
|
-
"Cannot convert a Symbol value to a string"
|
|
257
|
-
)
|
|
256
|
+
"Cannot convert a Symbol value to a string",
|
|
257
|
+
),
|
|
258
258
|
);
|
|
259
259
|
});
|
|
260
260
|
});
|
|
@@ -469,7 +469,7 @@ describe("Files", function () {
|
|
|
469
469
|
} catch (err) {
|
|
470
470
|
done(err);
|
|
471
471
|
}
|
|
472
|
-
}
|
|
472
|
+
},
|
|
473
473
|
);
|
|
474
474
|
});
|
|
475
475
|
it("should return [] if dir is empty", (done) => {
|
|
@@ -486,7 +486,7 @@ describe("Files", function () {
|
|
|
486
486
|
} catch (err) {
|
|
487
487
|
done(err);
|
|
488
488
|
}
|
|
489
|
-
}
|
|
489
|
+
},
|
|
490
490
|
);
|
|
491
491
|
});
|
|
492
492
|
it("should have a forward slash separating directory and filename in returned filenames if dir does not contain a slash at the end", async function () {
|
|
@@ -520,7 +520,7 @@ describe("Files", function () {
|
|
|
520
520
|
} catch (err) {
|
|
521
521
|
done(err);
|
|
522
522
|
}
|
|
523
|
-
}
|
|
523
|
+
},
|
|
524
524
|
);
|
|
525
525
|
});
|
|
526
526
|
});
|
|
@@ -586,13 +586,13 @@ describe("Files", function () {
|
|
|
586
586
|
});
|
|
587
587
|
it("should return [] if dir is empty", function () {
|
|
588
588
|
expect(
|
|
589
|
-
files.filesWithExtensionSync({ dir: emptyDir, ext: "json" })
|
|
589
|
+
files.filesWithExtensionSync({ dir: emptyDir, ext: "json" }),
|
|
590
590
|
).to.have.members([]);
|
|
591
591
|
});
|
|
592
592
|
it("should have a forward slash separating directory and filename in returned filenames if dir does not contain a slash at the end", function () {
|
|
593
593
|
return prepareDirWithJsonFiles().then(() => {
|
|
594
594
|
expect(
|
|
595
|
-
files.filesWithExtensionSync({ dir: jsonDir, ext: "json" })
|
|
595
|
+
files.filesWithExtensionSync({ dir: jsonDir, ext: "json" }),
|
|
596
596
|
).to.have.members([
|
|
597
597
|
jsonDir + "/package.json",
|
|
598
598
|
jsonDir + "/server.json",
|
|
@@ -603,7 +603,7 @@ describe("Files", function () {
|
|
|
603
603
|
it("should not have two forward slashes in returned filenames if dir contains a slash at the end", function () {
|
|
604
604
|
return prepareDirWithJsonFiles().then(() => {
|
|
605
605
|
expect(
|
|
606
|
-
files.filesWithExtensionSync({ dir: jsonDir, ext: "json" })
|
|
606
|
+
files.filesWithExtensionSync({ dir: jsonDir, ext: "json" }),
|
|
607
607
|
).to.have.members([
|
|
608
608
|
jsonDir + "/package.json",
|
|
609
609
|
jsonDir + "/server.json",
|
|
@@ -614,14 +614,14 @@ describe("Files", function () {
|
|
|
614
614
|
it("should return [] if there are files in dir matching ext but ext starts with a period", function () {
|
|
615
615
|
return prepareDirWithJsonFiles().then(() => {
|
|
616
616
|
expect(
|
|
617
|
-
files.filesWithExtensionSync({ dir: jsonDir, ext: ".json" })
|
|
617
|
+
files.filesWithExtensionSync({ dir: jsonDir, ext: ".json" }),
|
|
618
618
|
).to.have.members([]);
|
|
619
619
|
});
|
|
620
620
|
});
|
|
621
621
|
it("should return [] if ext is empty", function () {
|
|
622
622
|
return prepareDirWithJsonFiles().then(() => {
|
|
623
623
|
expect(
|
|
624
|
-
files.filesWithExtensionSync({ dir: jsonDir, ext: "" })
|
|
624
|
+
files.filesWithExtensionSync({ dir: jsonDir, ext: "" }),
|
|
625
625
|
).to.have.members([]);
|
|
626
626
|
});
|
|
627
627
|
});
|
|
@@ -654,7 +654,7 @@ describe("Files", function () {
|
|
|
654
654
|
} catch (err) {
|
|
655
655
|
done(err);
|
|
656
656
|
}
|
|
657
|
-
}
|
|
657
|
+
},
|
|
658
658
|
);
|
|
659
659
|
});
|
|
660
660
|
it("should error for UnlikelyToExist.js", async function () {
|
|
@@ -808,7 +808,7 @@ describe("Files", function () {
|
|
|
808
808
|
cb(null);
|
|
809
809
|
},
|
|
810
810
|
],
|
|
811
|
-
done
|
|
811
|
+
done,
|
|
812
812
|
);
|
|
813
813
|
});
|
|
814
814
|
});
|
|
@@ -839,7 +839,7 @@ describe("Files", function () {
|
|
|
839
839
|
cb();
|
|
840
840
|
},
|
|
841
841
|
],
|
|
842
|
-
done
|
|
842
|
+
done,
|
|
843
843
|
);
|
|
844
844
|
});
|
|
845
845
|
});
|
|
@@ -902,7 +902,7 @@ describe("Files", function () {
|
|
|
902
902
|
},
|
|
903
903
|
files.writeFile,
|
|
904
904
|
],
|
|
905
|
-
done
|
|
905
|
+
done,
|
|
906
906
|
);
|
|
907
907
|
});
|
|
908
908
|
|
|
@@ -921,7 +921,7 @@ describe("Files", function () {
|
|
|
921
921
|
} catch (err) {
|
|
922
922
|
done(err);
|
|
923
923
|
}
|
|
924
|
-
}
|
|
924
|
+
},
|
|
925
925
|
);
|
|
926
926
|
});
|
|
927
927
|
it("should successfully read three files when called with option 'utf8'", (done) => {
|
|
@@ -936,13 +936,13 @@ describe("Files", function () {
|
|
|
936
936
|
} catch (err) {
|
|
937
937
|
done(err);
|
|
938
938
|
}
|
|
939
|
-
}
|
|
939
|
+
},
|
|
940
940
|
);
|
|
941
941
|
});
|
|
942
942
|
it("should successfully read three files when called with options", async function () {
|
|
943
943
|
const string = await files.readFiles(
|
|
944
944
|
[targetDir + "/c.txt", targetDir + "/a.txt", targetDir + "/c.txt"],
|
|
945
|
-
{ encoding: "utf8", flag: "r" }
|
|
945
|
+
{ encoding: "utf8", flag: "r" },
|
|
946
946
|
);
|
|
947
947
|
expect(string).to.equal("cac");
|
|
948
948
|
});
|
|
@@ -958,7 +958,7 @@ describe("Files", function () {
|
|
|
958
958
|
} catch (err) {
|
|
959
959
|
done(err);
|
|
960
960
|
}
|
|
961
|
-
}
|
|
961
|
+
},
|
|
962
962
|
);
|
|
963
963
|
});
|
|
964
964
|
it("should return a Promise if callback is null", async function () {
|
|
@@ -1019,7 +1019,7 @@ describe("Files", function () {
|
|
|
1019
1019
|
} catch (err) {
|
|
1020
1020
|
done(err);
|
|
1021
1021
|
}
|
|
1022
|
-
}
|
|
1022
|
+
},
|
|
1023
1023
|
);
|
|
1024
1024
|
});
|
|
1025
1025
|
});
|
|
@@ -1051,7 +1051,7 @@ describe("Files", function () {
|
|
|
1051
1051
|
},
|
|
1052
1052
|
files.mkdirp,
|
|
1053
1053
|
],
|
|
1054
|
-
done
|
|
1054
|
+
done,
|
|
1055
1055
|
);
|
|
1056
1056
|
});
|
|
1057
1057
|
|
|
@@ -1090,7 +1090,7 @@ describe("Files", function () {
|
|
|
1090
1090
|
},
|
|
1091
1091
|
files.isFile.bind(files),
|
|
1092
1092
|
],
|
|
1093
|
-
done
|
|
1093
|
+
done,
|
|
1094
1094
|
);
|
|
1095
1095
|
});
|
|
1096
1096
|
it("should throw TypeError when filename is null", async function () {
|
|
@@ -18,7 +18,7 @@ describe("Files#sanitizeFilename", () => {
|
|
|
18
18
|
});
|
|
19
19
|
it("should throw an error if the filename is not a string", () => {
|
|
20
20
|
expect(() =>
|
|
21
|
-
files.sanitizeFilename(["~/.\u0000ssh/authorized_keys"])
|
|
21
|
+
files.sanitizeFilename(["~/.\u0000ssh/authorized_keys"]),
|
|
22
22
|
).to.throw(Error);
|
|
23
23
|
});
|
|
24
24
|
});
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright 2018 Chris Topher (c@creemama.com)
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
-
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
-
the Software without restriction, including without limitation the rights to
|
|
8
|
-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
9
|
-
of the Software, and to permit persons to whom the Software is furnished to do
|
|
10
|
-
so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|