binhend 2.1.22 → 2.1.24

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "binhend",
3
- "version": "2.1.22",
3
+ "version": "2.1.24",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "Nguyen Duc Binh",
package/src/https.js CHANGED
@@ -1,91 +1,92 @@
1
- // @ts-nocheck
2
1
 
3
2
  const https = require('https');
4
3
 
5
4
  function HTTPS(url) {
6
5
  this.url = url;
7
6
  this.parameters = [];
7
+ };
8
8
 
9
- this.get = function(callback) {
10
- return this.request('GET', callback);
11
- }
12
-
13
- this.post = function(callback) {
14
- return this.request('POST', callback);
15
- }
16
-
17
- this.request = function(method, callback) {
18
- var URL = this.url + this.parameters.join('/') + (this.queries || '');
19
-
20
- var options = {
21
- method,
22
- headers: this.headers
23
- };
24
-
25
- var req = https.request(URL, options, function(res) {
26
- res.setEncoding('utf8');
27
-
28
- var data = '';
29
-
30
- res.on('data', (chunk) => {
31
- data += chunk;
32
- });
33
-
34
- res.on('end', () => {
35
- var response;
36
-
37
- try {
38
- response = JSON.parse(data);
39
- }
40
- catch(error) {
41
- response = data;
42
- }
43
-
44
- if (callback instanceof Function) {
45
- callback(response);
46
- }
47
- });
9
+ HTTPS.prototype.get = function(callback) {
10
+ return this.request('GET', callback);
11
+ }
12
+
13
+ HTTPS.prototype.post = function(callback) {
14
+ return this.request('POST', callback);
15
+ }
16
+
17
+ HTTPS.prototype.request = function(method, callback) {
18
+
19
+ var URL = this.url + this.parameters.join('/') + (this.queries || '');
20
+
21
+ var options = {
22
+ method,
23
+ headers: this.headers
24
+ };
25
+
26
+ var req = https.request(URL, options, function(res) {
27
+ res.setEncoding('utf8');
28
+
29
+ var data = '';
30
+
31
+ res.on('data', (chunk) => {
32
+ data += chunk;
48
33
  });
49
-
50
- req.on("error", (err) => {
51
- console.log("HTTPS request encounters error:" + err.message);
34
+
35
+ res.on('end', () => {
36
+ var response;
37
+
38
+ try {
39
+ response = JSON.parse(data);
40
+ }
41
+ catch(error) {
42
+ response = data;
43
+ }
44
+
45
+ if (callback instanceof Function) {
46
+ callback(response);
47
+ }
52
48
  });
53
-
54
- if (this.payload) {
55
- req.write(JSON.stringify(this.payload));
56
- }
57
-
58
- req.end();
59
-
60
- return this;
61
- }
62
-
63
- this.header = function(map) {
64
- this.headers = map;
65
- return this;
66
- }
67
-
68
- this.body = function(map) {
69
- this.payload = JSON.stringify(map);
70
- return this;
49
+ });
50
+
51
+ req.on('error', (err) => {
52
+ console.error(`[BINHEND][HTTPS] Error request: ${method} ${URL}`);
53
+ console.error(`[BINHEND][HTTPS] --- Error message: ${err.message}`);
54
+ });
55
+
56
+ if (this.payload) {
57
+ req.write(JSON.stringify(this.payload));
71
58
  }
72
-
73
- this.parameter = function(array) {
74
- if (array instanceof Array) {
75
- var last_char = this.url[this.url.length - 1];
76
- this.parameters = (last_char === '/' ? [] : ['']).concat(array);
77
- }
78
- return this;
59
+
60
+ req.end();
61
+
62
+ return this;
63
+ }
64
+
65
+ HTTPS.prototype.header = function(map) {
66
+ this.headers = map;
67
+ return this;
68
+ }
69
+
70
+ HTTPS.prototype.body = function(map) {
71
+ this.payload = JSON.stringify(map);
72
+ return this;
73
+ }
74
+
75
+ HTTPS.prototype.parameter = function(array) {
76
+ if (array instanceof Array) {
77
+ var lastChar = this.url[this.url.length - 1];
78
+ this.parameters = (lastChar === '/' ? [] : ['']).concat(array);
79
79
  }
80
-
81
- this.query = function(map) {
82
- var query_string = '';
83
- for (var key in map) {
84
- query_string += key + '=' + map[key] + '&';
85
- }
86
- this.queries = '?' + query_string;
87
- return this;
80
+ return this;
81
+ }
82
+
83
+ HTTPS.prototype.query = function(map) {
84
+ var queryString = '';
85
+ for (var key in map) {
86
+ queryString += key + '=' + map[key] + '&';
88
87
  }
89
- };
88
+ this.queries = '?' + queryString;
89
+ return this;
90
+ }
90
91
 
91
92
  module.exports = { HTTPS };
@@ -31,7 +31,7 @@ function generate(sourceRootPath, outputRootPath, callbackDone) {
31
31
  // not return here, but wait for next "if" statement to be copied to build folder, then return there.
32
32
  }
33
33
 
34
- if (fileExtension !== '.js') {
34
+ if (fileExtension !== '.js' && fileExtension !== '.mjs') {
35
35
  // any files not JS (.css, .jpg, etc.) will be copied to build folder.
36
36
  return cloneFileIfNew(fileSourcePath, fileOutputPath);
37
37
  }
@@ -48,7 +48,7 @@ function generate(sourceRootPath, outputRootPath, callbackDone) {
48
48
  }
49
49
 
50
50
  function mapConfigValues(content) {
51
- var matches = content.matchAll(/{\/\*(.+?)\*\/}/g); // match all terms wrapped in format: {/*TERM*/}
51
+ var matches = content.matchAll(/{\/\*(.*?)\*\/}/g); // match all terms wrapped in format: {/*TERM*/}
52
52
 
53
53
  var map = {};
54
54