-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.ts
63 lines (57 loc) · 1.46 KB
/
package.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
import { api } from "./utils.ts";
interface Package {
exists: boolean;
name?: string;
description?: string;
}
export const getNpmPackage = async (
name: string
): Promise<{ data: Package; error: any }> => {
const url = `https://api.npms.io/v2/search?q=${name}`;
const { data, error } = await api(url);
if (data) {
if (data.results.length >= 1) {
const result = data.results[0];
if (result.package.name.toLowerCase() === name.toLowerCase()) {
return {
data: {
exists: true,
name: result.package.name,
description: result.package.description,
},
error: undefined,
};
}
} else {
return {
data: { exists: false },
error: undefined,
};
}
}
return { data, error };
};
export const getDenoPackage = async (
name: string
): Promise<{ data: Package; error: any }> => {
const url = `https://api.deno.land/modules?query=${name}`;
const { data, error } = await api(url);
if (data) {
if (data.data.results.length >= 1) {
const result = data.data.results[0];
if (result.name.toLowerCase() === name.toLowerCase()) {
return {
data: {
exists: true,
name: result.name,
description: result.description,
},
error: undefined,
};
}
} else {
return { data: { exists: false }, error: undefined };
}
}
return { data, error };
};