tuijs-util 2.0.3 → 2.0.5
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/LICENSE +21 -21
- package/README.md +28 -28
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/lists/colors-detail.d.ts +3 -0
- package/dist/lib/lists/colors-detail.d.ts.map +1 -0
- package/dist/lib/lists/colors-detail.js +1053 -0
- package/dist/lib/lists/colors-detail.js.map +1 -0
- package/dist/lib/math.d.ts +20 -0
- package/dist/lib/math.d.ts.map +1 -0
- package/dist/lib/math.js +20 -0
- package/dist/lib/math.js.map +1 -0
- package/package.json +26 -26
- package/src/index.ts +11 -10
- package/src/lib/check.ts +254 -254
- package/src/lib/dom.ts +54 -54
- package/src/lib/http.ts +90 -90
- package/src/lib/lists/colors-detail.ts +1053 -0
- package/src/lib/lists/colors.ts +150 -150
- package/src/lib/lists/html-tags.ts +118 -118
- package/src/lib/lists/misc.ts +4 -4
- package/src/lib/lists/subnets.ts +27 -27
- package/src/lib/math.ts +19 -0
- package/src/lib/misc.ts +117 -117
- package/src/lib/parse.ts +23 -23
- package/src/lib/regex.ts +51 -51
- package/tsconfig.json +20 -20
package/src/lib/http.ts
CHANGED
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
import { checkUrl } from './check.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Adds 'http://' if valid URL and 'http://' or 'https://' is missing.
|
|
5
|
-
*/
|
|
6
|
-
export function urlAddHttp(url: string): string | undefined {
|
|
7
|
-
if (url === null || !checkUrl(url)) {
|
|
8
|
-
throw new Error(`Invalid input.`);
|
|
9
|
-
};
|
|
10
|
-
if (url.startsWith("http://") === false && url.startsWith("https://") === false) {
|
|
11
|
-
url = "http://" + url
|
|
12
|
-
}
|
|
13
|
-
return url;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Adds 'https://' if valid URL and 'http://' or 'https://' is missing.
|
|
18
|
-
*/
|
|
19
|
-
export function urlAddHttps(url: string): string | undefined {
|
|
20
|
-
if (url === null || !checkUrl(url)) {
|
|
21
|
-
throw new Error(`Invalid input.`);
|
|
22
|
-
};
|
|
23
|
-
if (url.startsWith("http://") === false && url.startsWith("https://") === false) {
|
|
24
|
-
url = "https://" + url
|
|
25
|
-
}
|
|
26
|
-
return url;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Sends GET request to specified URL
|
|
31
|
-
*/
|
|
32
|
-
export async function reqGet(url: string, signal: AbortSignal | null = null) {
|
|
33
|
-
if (!checkUrl(url)) {
|
|
34
|
-
throw new Error(`Invalid URL`);
|
|
35
|
-
}
|
|
36
|
-
const options: RequestInit = signal ? { method: 'GET', signal } : { method: 'GET' };
|
|
37
|
-
return await fetch(url, options);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Collects JSON data from a given url
|
|
42
|
-
*/
|
|
43
|
-
export async function reqGetJson(url: string, signal: AbortSignal | null = null) {
|
|
44
|
-
const options: RequestInit = signal ? { method: 'GET', signal } : { method: 'GET' };
|
|
45
|
-
const res = await fetch(url, options);
|
|
46
|
-
return await res.json();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Collects text data from a given url
|
|
51
|
-
*/
|
|
52
|
-
export async function reqGetText(url: string, signal: AbortSignal | null = null) {
|
|
53
|
-
const options: RequestInit = signal ? { method: 'GET', signal } : { method: 'GET' };
|
|
54
|
-
const res = await fetch(url, options);
|
|
55
|
-
return await res.text();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Sends POST request to specified URL, which contains JSON data in the body.
|
|
60
|
-
*/
|
|
61
|
-
export async function reqPostJson(url: string, data: object, signal: AbortSignal | null = null) {
|
|
62
|
-
const options = signal ? {
|
|
63
|
-
method: 'POST',
|
|
64
|
-
headers: { 'Content-Type': 'application/json' },
|
|
65
|
-
body: JSON.stringify(data),
|
|
66
|
-
signal
|
|
67
|
-
} : {
|
|
68
|
-
method: 'POST',
|
|
69
|
-
headers: { 'Content-Type': 'application/json' },
|
|
70
|
-
body: JSON.stringify(data)
|
|
71
|
-
};
|
|
72
|
-
const res = await fetch(url, options);
|
|
73
|
-
return res;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Sends POST request to specified URL, which contains FormData in the body.
|
|
78
|
-
*/
|
|
79
|
-
export async function reqPostForm(url: string, data: FormData, signal: AbortSignal | null = null) {
|
|
80
|
-
const options = signal ? {
|
|
81
|
-
method: 'POST',
|
|
82
|
-
body: data,
|
|
83
|
-
signal
|
|
84
|
-
} : {
|
|
85
|
-
method: 'POST',
|
|
86
|
-
body: data
|
|
87
|
-
};
|
|
88
|
-
const res = await fetch(url, options);
|
|
89
|
-
return res;
|
|
90
|
-
}
|
|
1
|
+
import { checkUrl } from './check.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Adds 'http://' if valid URL and 'http://' or 'https://' is missing.
|
|
5
|
+
*/
|
|
6
|
+
export function urlAddHttp(url: string): string | undefined {
|
|
7
|
+
if (url === null || !checkUrl(url)) {
|
|
8
|
+
throw new Error(`Invalid input.`);
|
|
9
|
+
};
|
|
10
|
+
if (url.startsWith("http://") === false && url.startsWith("https://") === false) {
|
|
11
|
+
url = "http://" + url
|
|
12
|
+
}
|
|
13
|
+
return url;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Adds 'https://' if valid URL and 'http://' or 'https://' is missing.
|
|
18
|
+
*/
|
|
19
|
+
export function urlAddHttps(url: string): string | undefined {
|
|
20
|
+
if (url === null || !checkUrl(url)) {
|
|
21
|
+
throw new Error(`Invalid input.`);
|
|
22
|
+
};
|
|
23
|
+
if (url.startsWith("http://") === false && url.startsWith("https://") === false) {
|
|
24
|
+
url = "https://" + url
|
|
25
|
+
}
|
|
26
|
+
return url;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Sends GET request to specified URL
|
|
31
|
+
*/
|
|
32
|
+
export async function reqGet(url: string, signal: AbortSignal | null = null) {
|
|
33
|
+
if (!checkUrl(url)) {
|
|
34
|
+
throw new Error(`Invalid URL`);
|
|
35
|
+
}
|
|
36
|
+
const options: RequestInit = signal ? { method: 'GET', signal } : { method: 'GET' };
|
|
37
|
+
return await fetch(url, options);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Collects JSON data from a given url
|
|
42
|
+
*/
|
|
43
|
+
export async function reqGetJson(url: string, signal: AbortSignal | null = null) {
|
|
44
|
+
const options: RequestInit = signal ? { method: 'GET', signal } : { method: 'GET' };
|
|
45
|
+
const res = await fetch(url, options);
|
|
46
|
+
return await res.json();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Collects text data from a given url
|
|
51
|
+
*/
|
|
52
|
+
export async function reqGetText(url: string, signal: AbortSignal | null = null) {
|
|
53
|
+
const options: RequestInit = signal ? { method: 'GET', signal } : { method: 'GET' };
|
|
54
|
+
const res = await fetch(url, options);
|
|
55
|
+
return await res.text();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Sends POST request to specified URL, which contains JSON data in the body.
|
|
60
|
+
*/
|
|
61
|
+
export async function reqPostJson(url: string, data: object, signal: AbortSignal | null = null) {
|
|
62
|
+
const options = signal ? {
|
|
63
|
+
method: 'POST',
|
|
64
|
+
headers: { 'Content-Type': 'application/json' },
|
|
65
|
+
body: JSON.stringify(data),
|
|
66
|
+
signal
|
|
67
|
+
} : {
|
|
68
|
+
method: 'POST',
|
|
69
|
+
headers: { 'Content-Type': 'application/json' },
|
|
70
|
+
body: JSON.stringify(data)
|
|
71
|
+
};
|
|
72
|
+
const res = await fetch(url, options);
|
|
73
|
+
return res;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Sends POST request to specified URL, which contains FormData in the body.
|
|
78
|
+
*/
|
|
79
|
+
export async function reqPostForm(url: string, data: FormData, signal: AbortSignal | null = null) {
|
|
80
|
+
const options = signal ? {
|
|
81
|
+
method: 'POST',
|
|
82
|
+
body: data,
|
|
83
|
+
signal
|
|
84
|
+
} : {
|
|
85
|
+
method: 'POST',
|
|
86
|
+
body: data
|
|
87
|
+
};
|
|
88
|
+
const res = await fetch(url, options);
|
|
89
|
+
return res;
|
|
90
|
+
}
|