-
-
Notifications
You must be signed in to change notification settings - Fork 735
/
Copy pathfunctions.ts
99 lines (86 loc) · 2.72 KB
/
functions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
* @module
* This module demonstrates TypeDoc's support for functions.
*
* Use the [`@module`](https://typedoc.org/guides/doccomments/#%40module) tag to
* tell TypeDoc that a comment block describes the entire module.
*/
/**
* Calculates the square root of a number.
* @param x the number to calculate the root of.
* @returns the square root if `x` is non-negative or `NaN` if `x` is negative.
*/
export function sqrt(x: number): number {
return Math.sqrt(x);
}
/**
* Calculates the square root of a number.
*
* `sqrtArrowFunction` is defined using a variable declaration:
*
* ```
* export const sqrtArrowFunction = (x: number): number => Math.sqrt(x);
* ```
*
* TypeDoc is smart and documents `sqrtArrowFunction` as a function rather than a variable.
*
* @param x the number do calculate the root of.
* @returns the square root if `x` is non-negative or `NaN` if `x` is negative.
*/
export const sqrtArrowFunction = (x: number): number => Math.sqrt(x);
/**
* A simple generic function that concatenates two arrays.
*
* Use [`@typeParam <param
* name>`](https://typedoc.org/guides/doccomments/#%40typeparam-%3Cparam-name%3E-or-%40template-%3Cparam-name%3E)
* to document generic type parameters, e.g.
*
* ```text
* @typeParam T the element type of the arrays
* ```
*
* @typeParam T the element type of the arrays
*/
export function concat<T>(array1: T[], array2: T[]): T[] {
return array1.concat(array2);
}
/**
* A function that takes in an options object and makes an HTTP call.
*/
export function makeHttpCall(options: {
url: string;
/** e.g. GET, POST, PUT, DELETE */
method: string;
/** e.g. `{ 'Authorization': 'Bearer <access token>' }` */
headers: Record<string, string>;
body: string | Blob | FormData;
mode: "cors" | "no-cors" | "same-origin";
}): Promise<Response> {
const { url, method, headers, body, mode } = options;
return fetch(url, { method, headers, body, mode });
}
/**
* The options type for [[`makeHttpCall2`]].
*/
export interface MakeHttpCall2Options {
url: string;
/** e.g. GET, POST, PUT, DELETE */
method: string;
/** e.g. `{ 'Authorization': 'Bearer <access token>' }` */
headers: Record<string, string>;
body: string | Blob | FormData;
mode: "cors" | "no-cors" | "same-origin";
}
/**
* A function that takes in an options object that is defined as a separate
* interface and makes an HTTP call.
*
* **Make sure to export the options type when using this pattern.** Otherwise,
* TypeDoc will not document the options.
*/
export function makeHttpCall2(
options: MakeHttpCall2Options
): Promise<Response> {
const { url, method, headers, body, mode } = options;
return fetch(url, { method, headers, body, mode });
}