Get a specific package information through a version with range selection, the search algorithm comes from npm/cli
.
import { gpi, preload } from 'gpi';
gpi('react-dom', '^16.x.x', {
customFetch: window.fetch, // Default value is `window.fetch`
registry: 'https://registry.npmjs.org', // Default value is `https://registry.npmjs.org`
retry(err, pkgName, times, nextRequest) { // Retry callback
if (times < 5) {
console.log(`"${pkgName}" retry times (${times})`);
nextRequest();
} else {
throw err; // Must throw an error
}
},
}).then(res => {
console.log(res);
})
// Preload packge information
preload('react', {
customFetch: window.fetch, // Default value is `window.fetch`
registry: 'https://registry.npmjs.org', // Default value is `https://registry.npmjs.org`
retry(err, pkgName, times, nextRequest) {
if (times < 5) {
console.log(`"${pkgName}" retry times (${times})`);
nextRequest();
} else {
throw err;
}
},
}).then(pkgs => {
console.log(pkgs);
})
<!DOCTYPE html>
<html lang="en">
<body>
<script src="https://unpkg.com/gpi/dist/gpi.umd.js"></script>
<script>
const { gpi, preload } = Gpi;
// ...
</script>
</body>
</html>