-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnpm.ts
33 lines (29 loc) · 846 Bytes
/
npm.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
import { $fetch } from 'ohmyfetch'
// https://github.com/npm/registry/blob/master/docs/download-counts.md
export async function getWeeklyDownloadCountBy(npmName: string) {
if (!npmName)
throw new Error('empty npmName')
const url = `https://api.npmjs.org/downloads/point/last-week/${npmName}`
const { downloads } = await $fetch(url)
return downloads
}
// https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md
export interface PackageMetadata {
time: {
modified: string
}
homepage?: string
repository: {
url: string
type?: string
directory?: string
}
bugs?: {
url: string
}
}
export async function reqPackageMetadata(npmName: string) {
if (!npmName)
throw new Error('empty npmName')
return await $fetch(`https://registry.npmjs.org/${npmName}`) as PackageMetadata
}