kopia lustrzana https://github.com/badgen/badgen.net
live-fns: (npm) jsdelivr => unpkg
For better catch up with latest npm package release.pull/166/head
rodzic
a4684a358d
commit
a1bb0ce826
|
@ -37,19 +37,31 @@ module.exports = async (topic, ...args) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const pkg = async (topic, args) => {
|
/**
|
||||||
let pkg = args[0]
|
* Parse npm name args
|
||||||
let tag = 'latest'
|
*
|
||||||
const isScoped = args[0].charAt(0) === '@'
|
* ['@babel', 'core', 'latest']
|
||||||
|
* ['@babel', 'core']
|
||||||
if (isScoped) {
|
* ['react', 'next']
|
||||||
pkg = `${args[0]}/${args[1]}`
|
* ['react']
|
||||||
tag = args[2] || tag
|
*/
|
||||||
|
const parseNpmName = (args) => {
|
||||||
|
if (args[0].charAt(0) === '@') {
|
||||||
|
return {
|
||||||
|
pkg: `${args[0]}/${args[1]}`,
|
||||||
|
tag: args[2]
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
tag = args[1] || tag
|
return {
|
||||||
|
pkg: args[0],
|
||||||
|
tag: args[1]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const endpoint = `https://cdn.jsdelivr.net/npm/${pkg}@${tag}/package.json`
|
const pkg = async (topic, args) => {
|
||||||
|
const { pkg, tag = 'latest' } = parseNpmName(args)
|
||||||
|
const endpoint = `https://unpkg.com/${pkg}@${tag}/package.json`
|
||||||
const meta = await got(endpoint).then(res => res.body)
|
const meta = await got(endpoint).then(res => res.body)
|
||||||
|
|
||||||
switch (topic) {
|
switch (topic) {
|
||||||
|
|
Ładowanie…
Reference in New Issue