forked from npmx-dev/npmx.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusePackageAnalysis.ts
More file actions
30 lines (28 loc) · 855 Bytes
/
usePackageAnalysis.ts
File metadata and controls
30 lines (28 loc) · 855 Bytes
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
import type { ModuleFormat, TypesStatus, CreatePackageInfo } from '#shared/utils/package-analysis'
import type { ChangelogInfo } from '#shared/types'
export interface PackageAnalysisResponse {
package: string
version: string
moduleFormat: ModuleFormat
types: TypesStatus
engines?: {
node?: string
npm?: string
}
createPackage?: CreatePackageInfo
changelog?: ChangelogInfo
}
/**
* Composable for fetching package analysis data (module format, types info, etc.)
*/
export function usePackageAnalysis(
packageName: MaybeRefOrGetter<string>,
version?: MaybeRefOrGetter<string | null | undefined>,
) {
return useLazyFetch<PackageAnalysisResponse>(() => {
const name = toValue(packageName)
const ver = toValue(version)
const base = `/api/registry/analysis/${name}`
return ver ? `${base}/v/${ver}` : base
})
}