@util.js/node-http 0.41.0 → 0.41.2

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/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
 
3
- var Urls = require("./lib/Urls");
3
+ const Urls = require("./lib/Urls");
4
4
  module.exports = new Urls();
package/lib/Urls.js CHANGED
@@ -28,7 +28,7 @@ class Urls {
28
28
  })
29
29
  .on("error", (error) => {
30
30
  files().unlink(destination, (unlinkError) => {
31
- cb(unlinkError ? unlinkError : error);
31
+ cb(unlinkError || error);
32
32
  });
33
33
  });
34
34
  const timeout = determineTimeout(callbackOrOptions);
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "author": "Chris Topher <c@creemama.com>",
3
3
  "dependencies": {
4
- "@util.js/node-files": "0.41.0",
5
- "@util.js/promises": "0.41.0"
4
+ "@util.js/node-files": "0.41.2",
5
+ "@util.js/promises": "0.41.2"
6
6
  },
7
7
  "description": "JavaScript utility methods for URLs",
8
8
  "keywords": [
@@ -27,6 +27,6 @@
27
27
  "type": "git",
28
28
  "url": "https://github.com/creemama/utiljs/tree/master/packages/utiljs-node-http"
29
29
  },
30
- "version": "0.41.0",
31
- "gitHead": "1ae0fda34e06ffbc546c5ba0025b0b59a0c7727d"
30
+ "version": "0.41.2",
31
+ "gitHead": "174b81ec0ead0221b9bb6617bc254b025bd20a5a"
32
32
  }
package/test/UrlsTest.js CHANGED
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
 
3
- const expect = require("chai").expect,
4
- files = require("@util.js/node-files"),
5
- targetDir = __dirname + "/../target",
6
- urls = require("..");
3
+ const expect = require("chai").expect;
4
+ const files = require("@util.js/node-files");
5
+ const targetDir = files.join(__dirname, "..", "target");
6
+ const urls = require("..");
7
7
  let fileNum = 0;
8
8
 
9
9
  describe("Urls", () => {
@@ -33,11 +33,11 @@ describe("Urls", () => {
33
33
 
34
34
  describe("#download(url, destination)", () => {
35
35
  it("handles HTTP requests", () =>
36
- download_url_destination("http://www.google.com"));
36
+ downloadUrlDestination("http://www.google.com"));
37
37
  it("handles HTTPS requests", () =>
38
- download_url_destination("https://www.google.com"));
38
+ downloadUrlDestination("https://www.google.com"));
39
39
  it("should throw an error if the protocol is not HTTP or HTTPS", () =>
40
- download_url_destination("ftp://www.google.com").then(
40
+ downloadUrlDestination("ftp://www.google.com").then(
41
41
  (value) => {
42
42
  throw new Error("Unexpected success");
43
43
  },
@@ -46,7 +46,7 @@ describe("Urls", () => {
46
46
  }
47
47
  ));
48
48
  it("should throw an error if there is no protocol", () =>
49
- download_url_destination("www.google.com").then(
49
+ downloadUrlDestination("www.google.com").then(
50
50
  (value) => {
51
51
  throw new Error("Unexpected success");
52
52
  },
@@ -55,24 +55,26 @@ describe("Urls", () => {
55
55
  }
56
56
  ));
57
57
  it("handles HTTP errors", () =>
58
- download_url_destination("http://doesnotexist:8080", {
58
+ downloadUrlDestination("http://doesnotexist:8080", {
59
59
  timeout: 50,
60
60
  }).then(
61
61
  (value) => {
62
62
  throw new Error("Unexpected success");
63
63
  },
64
64
  (error) => {
65
+ if (!error) throw new Error("Unexpected");
65
66
  /* expected */
66
67
  }
67
68
  ));
68
69
  it("handles HTTPS errors", () =>
69
- download_url_destination("https://doesnotexist:8443", {
70
+ downloadUrlDestination("https://doesnotexist:8443", {
70
71
  timeout: 50,
71
72
  }).then(
72
73
  (value) => {
73
74
  throw new Error("Unexpected success");
74
75
  },
75
76
  (error) => {
77
+ if (!error) throw new Error("Unexpected");
76
78
  /* expected */
77
79
  }
78
80
  ));
@@ -80,11 +82,11 @@ describe("Urls", () => {
80
82
 
81
83
  describe("#download(url, destination, callback)", () => {
82
84
  it("handles HTTP requests", (callback) =>
83
- download_url_destination_callback("http://www.google.com", callback));
85
+ downloadUrlDestinationCallback("http://www.google.com", callback));
84
86
  it("handles HTTPS requests", (callback) =>
85
- download_url_destination_callback("https://www.google.com", callback));
87
+ downloadUrlDestinationCallback("https://www.google.com", callback));
86
88
  it("handles HTTP errors", (callback) =>
87
- download_url_destination_callback(
89
+ downloadUrlDestinationCallback(
88
90
  "http://doesnotexist:8080",
89
91
  { timeout: 50 },
90
92
  (error) => {
@@ -93,7 +95,7 @@ describe("Urls", () => {
93
95
  }
94
96
  ));
95
97
  it("handles HTTPS errors", (callback) =>
96
- download_url_destination_callback(
98
+ downloadUrlDestinationCallback(
97
99
  "https://doesnotexist:8443",
98
100
  { timeout: 50 },
99
101
  (error) => {
@@ -122,6 +124,7 @@ describe("Urls", () => {
122
124
  throw new Error("Unexpected success");
123
125
  },
124
126
  (error) => {
127
+ if (!error) throw new Error("Unexpected");
125
128
  /* expected */
126
129
  }
127
130
  ));
@@ -131,6 +134,7 @@ describe("Urls", () => {
131
134
  throw new Error("Unexpected success");
132
135
  },
133
136
  (error) => {
137
+ if (!error) throw new Error("Unexpected");
134
138
  /* expected */
135
139
  }
136
140
  ));
@@ -160,13 +164,13 @@ describe("Urls", () => {
160
164
  });
161
165
  });
162
166
 
163
- async function download_url_destination(url, options) {
167
+ async function downloadUrlDestination(url, options) {
164
168
  await files.mkdirp(targetDir);
165
169
  const destination =
166
170
  targetDir +
167
171
  "/" +
168
172
  files.sanitizeFilename(
169
- fileNum++ + ".download_url_destination." + url + ".html",
173
+ fileNum++ + ".downloadUrlDestination." + url + ".html",
170
174
  { replacement: "_" }
171
175
  );
172
176
 
@@ -186,11 +190,11 @@ async function download_url_destination(url, options) {
186
190
  .then(verifyFile);
187
191
  }
188
192
 
189
- function download_url_destination_callback() {
190
- async_download_url_destination_callback(...arguments);
193
+ function downloadUrlDestinationCallback() {
194
+ asyncDownloadUrlDestinationCallback(...arguments);
191
195
  }
192
196
 
193
- async function async_download_url_destination_callback(
197
+ async function asyncDownloadUrlDestinationCallback(
194
198
  url,
195
199
  callbackOrOptions,
196
200
  callback
@@ -201,7 +205,7 @@ async function async_download_url_destination_callback(
201
205
  targetDir +
202
206
  "/" +
203
207
  files.sanitizeFilename(
204
- fileNum++ + ".async_download_url_destination_callback." + url + ".html",
208
+ fileNum++ + ".asyncDownloadUrlDestinationCallback." + url + ".html",
205
209
  { replacement: "_" }
206
210
  );
207
211
  const options = callbackOrOptions