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-pick-versions

v0.1.14

Published

This project provides a simple utility for selecting and organizing a limited number of versions of an npm package. It retrieves the latest versions of a specified npm package and allows you to generate version ranges based on patch, minor, and major upda

Downloads

111

Readme

@fnet/npm-pick-versions

This project provides a simple utility for selecting and organizing a limited number of versions of an npm package. It retrieves the latest versions of a specified npm package and allows you to generate version ranges based on patch, minor, and major updates. This can be particularly useful for developers who need to manage dependencies with specific version restrictions.

How It Works

The utility operates by first retrieving a list of versions for a given npm package using @fnet/npm-list-versions. It then selects a specified number of recent versions and constructs version ranges that can be used to define compatible dependency versions. The ranges are categorized into patch, minor, and major groups, offering flexible options for dependency management.

Key Features

  • Fetches the latest versions of a specified npm package.
  • Allows specification of how many recent versions to consider.
  • Generates version ranges for patch, minor, and major updates.
  • Simplifies version management for npm package dependencies.

Conclusion

The @fnet/npm-pick-versions tool is useful for developers needing to maintain npm package dependencies efficiently by providing structured version range information. It helps in managing which versions of a package can be used, ensuring compatibility and stability in projects without the overhead of manually tracking each version update.

Developer Guide for @fnet/npm-pick-versions

Overview

The @fnet/npm-pick-versions library is designed to help developers manage and select specific versions of npm packages based on semantic versioning. It enables users to efficiently retrieve lists of package versions and construct version ranges based on major, minor, or patch updates. This utility is particularly useful for projects that need to ensure compatibility with specific package versions.

Installation

To install the @fnet/npm-pick-versions library, you can use npm or yarn:

npm install @fnet/npm-pick-versions

or

yarn add @fnet/npm-pick-versions

Usage

Here's how you can use the library to fetch and organize npm package versions:

  1. Import the Default Function: The main function exported by the library is an asynchronous function that retrieves versions for a given package name.

  2. Provide Parameters: Pass an object with the package name and optionally specify the number of versions to retrieve.

  3. Access Version Ranges: The function returns an object that includes arrays for individual versions and string representations of patch, minor, and major version ranges.

Example Code

import pickVersions from '@fnet/npm-pick-versions';

const fetchPackageVersions = async () => {
    // Fetch the most recent 3 versions of a package, grouped by major version
    const versionData = await pickVersions({
        name: 'express',
        count: 3
    });

    console.log('Latest Versions:', versionData.versions);
    console.log('Patch Version Range:', versionData.patchRange);
    console.log('Minor Version Range:', versionData.minorRange);
    console.log('Major Version Range:', versionData.majorRange);
};

fetchPackageVersions();

Examples

Here are some practical examples for using the @fnet/npm-pick-versions library:

Example 1: Fetching Latest Versions and Ranges

(async () => {
    const { versions, patchRange, minorRange, majorRange } = await pickVersions({
        name: 'lodash',
        count: 2
    });

    console.log('Versions:', versions);
    console.log('Patch Range:', patchRange);
    console.log('Minor Range:', minorRange);
    console.log('Major Range:', majorRange);
})();

Example 2: Custom Count of Versions

import pickVersions from '@fnet/npm-pick-versions';

pickVersions({ name: 'react', count: 5 })
    .then(({ versions, patchRange }) => {
        console.log('Top 5 Versions:', versions);
        console.log('Patch Range for Compatibility:', patchRange);
    })
    .catch(error => {
        console.error('Error fetching versions:', error);
    });

Acknowledgement

This library utilizes semantic versioning principles to assist developers in managing package dependencies effectively. It integrates with npm to provide accurate versioning data, making it a reliable tool for maintaining package consistency.

Input Schema

$schema: https://json-schema.org/draft/2020-12/schema
type: object
properties:
  name:
    type: string
    description: The name of the npm package.
  count:
    type: integer
    description: The number of versions to retrieve, defaults to 2.
    default: 2
required:
  - name