npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fnet/npm-package-extract

v0.1.13

Published

## Introduction

Downloads

293

Readme

@fnet/npm-package-extract

Introduction

The @fnet/npm-package-extract is a simple utility designed to fetch and extract npm packages directly from the npm registry. It allows users to download any version of a specified npm package, extract its content, and optionally install its dependencies. This tool can be useful for developers who need offline access to package contents or want to explore the package structure without the need to use it directly in their project immediately.

How It Works

The utility works by first fetching the metadata of a specified npm package from the npm registry. It checks for the available versions and either selects the latest or a specific version as requested by the user. Once identified, it downloads the corresponding tarball file of the package, extracts it to a specified directory, and optionally renames the extracted directory to a more descriptive name. Users can also choose to keep or remove the downloaded tarball and install package dependencies if desired.

Key Features

  • Fetches metadata and tarballs directly from the npm registry.
  • Supports downloading a specific version or the latest version of a package.
  • Extracts the package contents to a specified directory.
  • Allows for optional renaming of extracted contents for clarity.
  • Provides options to retain the original tarball file.
  • Can automatically install package dependencies excluding dev dependencies.

Conclusion

The @fnet/npm-package-extract tool provides a straightforward method for extracting and managing npm packages locally. It's a handy utility for developers who need more control over package assets on their file system or require its structure offline. Its functionality is simple to use, allowing users to seamlessly integrate it into their workflows without much hassle.

@fnet/npm-package-extract Developer Guide

Overview

@fnet/npm-package-extract is a utility library designed to simplify the process of downloading and extracting npm packages. Developers can use this library to programmatically fetch specific versions of npm packages, extract their contents, and optionally install their dependencies. This can be particularly useful for managing package contents outside the typical npm workflow, such as in scenarios where package exploration or customized installations are needed.

Installation

The library can be installed via npm or yarn. Use the following commands:

Using npm:

npm install @fnet/npm-package-extract

Using yarn:

yarn add @fnet/npm-package-extract

Usage

The library exports a single default function, which facilitates the fetching and extraction process. Below is a basic guide on how to implement it:

import npmPackageExtract from '@fnet/npm-package-extract';

(async () => {
  try {
    const result = await npmPackageExtract({
      name: 'express', // Name of the package
      ver: '4.17.1',   // Specific version, or 'latest'
      keep: false,     // Determines whether to keep the tarball
      output: './downloads',  // Output directory for the extracted contents
      install: true,   // If true, installs dependencies in the extracted directory
      rename: true     // Renames the extracted directory
    });

    console.log(`Package extracted to: ${result.output}`);
  } catch (error) {
    console.error('Extraction failed:', error);
  }
})();

Examples

Example 1: Basic Extraction

This example demonstrates a straightforward extraction of an npm package:

import npmPackageExtract from '@fnet/npm-package-extract';

npmPackageExtract({
  name: 'lodash',
  ver: 'latest',
  keep: false,
  output: './lodash-package'
}).then(result => {
  console.log(`Lodash extracted to: ${result.output}`);
}).catch(console.error);

Example 2: Extract and Install Dependencies

This example shows how to extract a package and install its dependencies:

import npmPackageExtract from '@fnet/npm-package-extract';

npmPackageExtract({
  name: 'react',
  ver: '^17.0.0',
  install: true,  // Installs package dependencies
  output: './react-package'
}).then(result => {
  console.log(`React extracted and dependencies installed at: ${result.output}`);
}).catch(console.error);

Acknowledgement

We acknowledge the node-fetch, tar, semver, and shelljs libraries for enabling core functionalities such as making HTTP requests, handling file extractions, semantic versioning, and shell command execution. These utilities underlie the robust operations of the @fnet/npm-package-extract library.

Input Schema

$schema: https://json-schema.org/draft/2020-12/schema
type: object
properties:
  name:
    type: string
    description: The name of the npm package.
  ver:
    type: string
    description: The version of the package to download, or 'latest'.
    default: latest
  keep:
    type: boolean
    description: Whether to keep the downloaded tarball file after extraction.
    default: false
  output:
    type: string
    description: Output directory where the package will be extracted.
  install:
    type: boolean
    description: Whether to run npm install after extraction.
    default: false
  rename:
    type: boolean
    description: Whether to rename the extracted directory.
    default: true
required:
  - name