imtaotao / gpi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gpi

NPM version

Get a specific package information through a version with range selection, the search algorithm comes from npm/cli.

Online test platform

NPM

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);
})

CDN

<!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>

About


Languages

Language:TypeScript 80.9%Language:JavaScript 11.1%Language:HTML 8.0%