opusdev/vector-similarity-api
1
1import https from 'https';2 3const getDistVersion = async (packageName: string, distTag: string) => {4 const url = `https://registry.npmjs.org/-/package/${packageName}/dist-tags`;5 6 return new Promise<string>((resolve, reject) => {7 https8 .get(url, (res) => {9 let body = '';10 11 res.on('data', (chunk) => (body += chunk));12 res.on('end', () => {13 try {14 const json = JSON.parse(body);15 const version = json[distTag];16 if (!version) {17 reject(new Error('Error getting version'));18 }19 resolve(version);20 } catch {21 reject(new Error('Could not parse version response'));22 }23 });24 })25 .on('error', (err) => reject(err));26 });27};28 29export default getDistVersion;30 