A library to interface with npm for retrieving package information and manipulation.
Go to file
2024-05-29 14:15:03 +02:00
.gitea/workflows fix(core): update 2023-07-25 18:14:51 +02:00
.vscode fix(core): update 2023-07-25 18:14:51 +02:00
test fix(core): update 2023-07-25 18:14:51 +02:00
ts fix(core): update 2023-07-25 18:14:51 +02:00
.gitignore fix(core): update 2020-03-17 00:38:58 +00:00
npmextra.json update tsconfig 2024-04-14 18:03:33 +02:00
package.json update description 2024-05-29 14:15:03 +02:00
pnpm-lock.yaml fix(core): update 2023-07-25 18:14:51 +02:00
qenv.yml fix(core): update 2020-10-02 14:39:46 +00:00
readme.hints.md update tsconfig 2024-04-14 18:03:33 +02:00
readme.md update tsconfig 2024-04-14 18:03:33 +02:00
tsconfig.json update npmextra.json: githost 2024-04-01 21:36:54 +02:00

@push.rocks/smartnpm

interface with npm to retrieve package information

Install

To install @push.rocks/smartnpm, open your terminal and run the following command:

npm install @push.rocks/smartnpm --save

This will add @push.rocks/smartnpm as a dependency to your project and you're ready to start using it.

Usage

To use @push.rocks/smartnpm in your project, you first need to import it in your TypeScript files. @push.rocks/smartnpm provides a powerful interface to interact with npm to retrieve package information, handle package downloads, and more. Below are examples showcasing how to leverage some of its features in real-world scenarios.

Initialize the NpmRegistry

Before you can retrieve any package information or perform actions such as downloading packages, you need to create an instance of NpmRegistry. This acts as your starting point.

import { NpmRegistry } from '@push.rocks/smartnpm';

const npmRegistry = new NpmRegistry();

Optionally, you can provide a custom npm registry URL if you're not using the default npm registry:

const customRegistry = new NpmRegistry({
  npmRegistryUrl: 'https://custom.registry.url'
});

Retrieve Package Information

@push.rocks/smartnpm allows you to easily get detailed information about a package, including its versions, dist tags, and metadata. Here's how you can get information about a specific package:

async function getPackageInfo() {
  const packageName = 'your-package-name';
  const packageInfo = await npmRegistry.getPackageInfo(packageName);
  console.log(packageInfo);
}

getPackageInfo();

Search for Packages

You can search for packages using a variety of filters such as keywords, author, maintainer, etc. Here's an example of searching for packages with specific criteria:

async function searchPackages() {
  const searchResults = await npmRegistry.searchOnNpm({
    keywords: ['webpack-plugin'],
    author: 'webpack'
  });
  console.log(searchResults);
}

searchPackages();

Downloading Packages

@push.rocks/smartnpm provides an easy way to download npm packages and extract them to a specific directory. This could be useful for creating tools that need to programmatically handle packages.

async function downloadPackage() {
  const packageName = 'some-package';
  const targetDirectory = './path/to/targetDir';

  await npmRegistry.savePackageToDisk(packageName, targetDirectory);
  console.log(`${packageName} has been downloaded to ${targetDirectory}`);
}

downloadPackage();

Working with Package Versions and Dist Tags

You can easily retrieve detailed information about specific package versions or distribution tags. This is particularly useful for automation scripts that need to work with specific versions of a package.

async function getPackageVersionDetails() {
  const packageName = 'some-package';
  const version = '1.0.0'; // You can also use dist tags like 'latest'

  const packageInfo = await npmRegistry.getPackageInfo(packageName);
  const versionInfo = packageInfo.allVersions.find(v => v.version === version);
  console.log(versionInfo);
}

getPackageVersionDetails();

These examples only scratch the surface of what you can achieve with @push.rocks/smartnpm. By integrating this library, you have a powerful tool at your disposal for interacting with npm in a programmatic way, enabling a wide range of possibilities for automation, CI/CD, and tooling around npm packages.

This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the license file within this repository.

Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.

Trademarks

This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.

Company Information

Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany

For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.

By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.