1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | const NAME = Symbol.toStringTag;
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | export const isURLSearchParameters = object => {
|
16 | return (
|
17 | typeof object === 'object' &&
|
18 | typeof object.append === 'function' &&
|
19 | typeof object.delete === 'function' &&
|
20 | typeof object.get === 'function' &&
|
21 | typeof object.getAll === 'function' &&
|
22 | typeof object.has === 'function' &&
|
23 | typeof object.set === 'function' &&
|
24 | typeof object.sort === 'function' &&
|
25 | object[NAME] === 'URLSearchParams'
|
26 | );
|
27 | };
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | export const isBlob = object => {
|
35 | return (
|
36 | object &&
|
37 | typeof object === 'object' &&
|
38 | typeof object.arrayBuffer === 'function' &&
|
39 | typeof object.type === 'string' &&
|
40 | typeof object.stream === 'function' &&
|
41 | typeof object.constructor === 'function' &&
|
42 | /^(Blob|File)$/.test(object[NAME])
|
43 | );
|
44 | };
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | export const isAbortSignal = object => {
|
52 | return (
|
53 | typeof object === 'object' && (
|
54 | object[NAME] === 'AbortSignal' ||
|
55 | object[NAME] === 'EventTarget'
|
56 | )
|
57 | );
|
58 | };
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | export const isDomainOrSubdomain = (destination, original) => {
|
69 | const orig = new URL(original).hostname;
|
70 | const dest = new URL(destination).hostname;
|
71 |
|
72 | return orig === dest || orig.endsWith(`.${dest}`);
|
73 | };
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | export const isSameProtocol = (destination, original) => {
|
83 | const orig = new URL(original).protocol;
|
84 | const dest = new URL(destination).protocol;
|
85 |
|
86 | return orig === dest;
|
87 | };
|