fetch-npm-package
TypeScript icon, indicating that this package has built-in type declarations

1.0.17 • Public • Published

fetch-npm-package

NPM version

Use js to download and unzip the npm package. only supports use in the browser.

Online

Usage

Options are optional.

import { fetchFiles, fetchPackage, findTarget } from 'fetch-npm-package';

// All file are flattened
const files = await fetchFiles('react', {
  version: 'latest', // default is `latest`
  registry: 'https://registry.npmjs.org' // default is `https://registry.npmjs.org`
});
console.log(files);

// Aggregate as a folder
const folder = await fetchPackage('react');
console.log(folder);

By tarball request.

const files = await fetchFiles.tarball('https://registry.npmjs.org/react/-/react-18.1.0.tgz');
console.log(files);

const folder = await fetchPackage.tarball('https://registry.npmjs.org/react/-/react-18.1.0.tgz');
console.log(folder);

Find package file.

const folder = await fetchPackage('react');
console.log(folder);

const target = findTargetFile(folder, 'cjs/react-jsx-dev-runtime.development.js');
console.log(target.code);

CDN

<!DOCTYPE html>
<html lang='en'>
<body>
  <script src='https://unpkg.com/fetch-npm-package/dist/fetch.umd.js'></script>
  <script>
    const { fetchFiles, fetchPackage, findTarget } = FetchNpmPackage;
    // ...
  </script>
</body>
</html>

Extended use

If you want to find a file more precisely based on package.json, you can use node-package-exports.

Package Sidebar

Install

npm i fetch-npm-package

Weekly Downloads

3

Version

1.0.17

License

MIT

Unpacked Size

288 kB

Total Files

9

Last publish

Collaborators

  • rustle