Class NpmRegistryClient

A client for the npm package download API.

The client allows to retrieve the download count for a given day, week, month, or a relative period of time (e.g. last 7 days).

Example

// get the download count on 2020-01-01
client.getDay({
packages: [
'@aws-lambda-powertools/logger',
],
date: '2020-01-01',
});

Example

// week 1 of the current year
client.getWeek({
packages: [
'@aws-lambda-powertools/logger',
],
week: 'W1',
});
// week 1 of 2020
client.getWeek({
packages: [
'@aws-lambda-powertools/logger',
],
week: '2020W1',
});
// week that includes 2020-01-01
client.getWeek({
packages: [
'@aws-lambda-powertools/logger',
],
week: '2020-01-01',
});
// week that includes 2020-01-01, starting on Sunday
client.getWeek({
packages: [
'@aws-lambda-powertools/logger',
],
week: '2020-01-01',
startOfWeek: 'sunday',
});

You can also use the client to get the daily download count for a given package in a period of time.

See

API Documentation

Hierarchy

  • NpmRegistryClient

Implements

Constructors

Methods

  • Get the download count for the given packages between the given dates.

    Parameters

    Returns Promise<NpmAPIPointResponse>

    The download count for the given packages between the given dates.

    Example

    client.getBetweenDates({
    packages: [
    '@aws-lambda-powertools/logger',
    ],
    startDate: '2020-01-01',
    endDate: '2020-01-15',
    });

    The response will be an array of objects, one for each package, with the following shape:

    Example

    {
    package: '@aws-lambda-powertools/logger',
    downloads: 1234,
    start: '2020-01-01',
    end: '2020-01-15',
    }
  • Get the daily downlods for the given packages during the last 30 available days.

    Parameters

    Returns Promise<NpmAPIRangeResponse>

    The daily download count for the given packages during the last 30 available days.

    Example

    client.getDailyDownloadsForLastMonth({
    packages: [
    '@aws-lambda-powertools/logger',
    ],
    });

    The response will be an array of objects, one for each package, with the following shape:

    Example

    {
    start: '2020-01-01',
    end: '2020-01-31',
    package: '@aws-lambda-powertools/logger',
    downloads: [
    {
    downloads: 1234,
    day: '2020-01-01',
    },
    // ... other days
    {
    downloads: 1234,
    day: '2020-01-08',
    },
    ]
    }
  • Get the daily downlods for the given packages during the last 7 available days.

    Parameters

    Returns Promise<NpmAPIRangeResponse>

    The daily download count for the given packages during the last 7 available days.

    Example

    client.getDailyDownloadsForLastWeek({
    packages: [
    '@aws-lambda-powertools/logger',
    ],
    });

    The response will be an array of objects, one for each package, with the following shape:

    Example

    {
    start: '2020-01-01',
    end: '2020-01-08',
    package: '@aws-lambda-powertools/logger',
    downloads: [
    {
    downloads: 1234,
    day: '2020-01-01',
    },
    // ... other days
    {
    downloads: 1234,
    day: '2020-01-08',
    },
    ]
    }
  • Get the daily downlods for the given packages on a given month.

    You can use a month number (i.e. 01-12), an ISO week (i.e. 2023-01).

    Parameters

    Returns Promise<NpmAPIRangeResponse>

    The daily download count for the given packages on the given month.

    Example

    // month 1 of the current year
    client.getDailyDownloadsForWeek({
    packages: [
    '@aws-lambda-powertools/logger',
    ],
    week: '01',
    });
    // month 1 of 2020
    client.getDailyDownloadsForWeek({
    packages: [
    '@aws-lambda-powertools/logger',
    ],
    week: '2020-01',
    });

    In all cases, the response will be an array of objects, one for each package, with the following shape:

    Example

    {
    start: '2020-01-01',
    end: '2020-01-31',
    package: '@aws-lambda-powertools/logger',
    downloads: [
    {
    downloads: 1234,
    day: '2020-01-01',
    },
    // ... other days
    {
    downloads: 1234,
    day: '2020-01-31',
    },
    ]
    }
  • Get the daily downlods for the given packages on a given week.

    You can use a week number (i.e. W01-W52), an ISO week (i.e. 2023W01) or a date (i.e. 2020-01-01). In the latter case, the week will be calculated based on the date.

    By default, the week will start on Monday and end on Sunday, but you can change this by passing the startOfWeek option.

    Parameters

    Returns Promise<NpmAPIRangeResponse>

    The daily download count for the given packages on the given week.

    Example

    // week 1 of the current year
    client.getDailyDownloadsForWeek({
    packages: [
    '@aws-lambda-powertools/logger',
    ],
    week: 'W01',
    });
    // week 1 of 2020
    client.getDailyDownloadsForWeek({
    packages: [
    '@aws-lambda-powertools/logger',
    ],
    week: '2020W01',
    });
    // week that includes 2020-01-01
    client.getDailyDownloadsForWeek({
    packages: [
    '@aws-lambda-powertools/logger',
    ],
    week: '2020-01-01',
    });
    // week that includes 2020-01-01, starting on Sunday
    client.getDailyDownloadsForWeek({
    packages: [
    '@aws-lambda-powertools/logger',
    ],
    week: '2020-01-01',
    startOfWeek: 'sunday',
    });

    In all cases, the response will be an array of objects, one for each package, with the following shape:

    Example

    {
    start: '2020-01-01',
    end: '2020-01-08',
    package: '@aws-lambda-powertools/logger',
    downloads: [
    {
    downloads: 1234,
    day: '2020-01-01',
    },
    // ... other days
    {
    downloads: 1234,
    day: '2020-01-08',
    },
    ]
    }
  • Get the download count for the given packages on a given date.

    Parameters

    Returns Promise<NpmAPIPointResponse>

    The download count for the given packages on the given date.

    Example

    client.getDay({
    packages: [
    '@aws-lambda-powertools/logger',
    ],
    date: '2020-01-01',
    });

    The response will be an array of objects, one for each package, with the following shape:

    Example

    {
    downloads: 1234,
    start: '2020-01-01',
    end: '2020-01-01',
    package: '@aws-lambda-powertools/logger',
    }
  • Get the download count for the last available day.

    In practice, this will usually be "yesterday" (in GMT) but if stats for that day are not available, it will be the day before.

    Parameters

    Returns Promise<NpmAPIPointResponse>

    The download count for the given packages on the last available day.

    Example

    client.getLastDay({
    packages: [
    '@aws-lambda-powertools/logger',
    ],
    });

    The response will be an array of objects, one for each package, with the following shape:

    Example

    {
    start: '2020-01-01',
    end: '2020-01-01',
    package: '@aws-lambda-powertools/logger',
    downloads: 1234
    }
  • Get the download count for the last 30 available days.

    Depending on the time of day, this may include the current day or start on the day before (in GMT).

    Parameters

    Returns Promise<NpmAPIPointResponse>

    The download count for the given packages on the last 30 available days.

    Example

    client.getLastMonth({
    packages: [
    '@aws-lambda-powertools/logger',
    ],
    });

    The response will be an array of objects, one for each package, with the following shape:

    Example

    {
    start: '2020-01-01',
    end: '2020-01-01',
    package: '@aws-lambda-powertools/logger',
    downloads: 1234
    }
  • Get the download count for the last 7 available days.

    Depending on the time of day, this may start on the current day or the day before (in GMT).

    Parameters

    Returns Promise<NpmAPIPointResponse>

    The download count for the given packages on the last 7 available days.

    Example

    client.getLastWeek({
    packages: [
    '@aws-lambda-powertools/logger',
    ],
    });

    The response will be an array of objects, one for each package, with the following shape:

    Example

    {
    start: '2020-01-01',
    end: '2020-01-01',
    package: '@aws-lambda-powertools/logger',
    downloads: 1234
    }
  • Get the download count for the given packages on the given month.

    You can use a month number (i.e. 01-12), an ISO week (i.e. 2023-01).

    Parameters

    Returns Promise<NpmAPIPointResponse>

    The download count for the given packages on the given month.

    Example

    // month 1 of the current year
    client.getMonth({
    packages: [
    '@aws-lambda-powertools/logger',
    ],
    month: '01',
    });
    // month 1 of 2020
    client.getMonth({
    packages: [
    '@aws-lambda-powertools/logger',
    ],
    month: '2020-01',
    });

    In all cases, the response will be an array of objects, one for each package, with the following shape:

    Example

    {
    downloads: 1234;
    start: '2020-01-01';
    end: '2020-01-31';
    package: '@aws-lambda-powertools/logger';
    }
  • Get the download count for the given packages on a given week.

    You can use a week number (i.e. W01-W52), an ISO week (i.e. 2023W01) or a date (i.e. 2020-01-01). In the latter case, the week will be calculated based on the date.

    By default, the week will start on Monday and end on Sunday, but you can change this by passing the startOfWeek option.

    Parameters

    Returns Promise<NpmAPIPointResponse>

    The download count for the given packages on the given week.

    Example

    // week 1 of the current year
    client.getWeek({
    packages: [
    '@aws-lambda-powertools/logger',
    ],
    week: 'W1',
    });
    // week 1 of 2020
    client.getWeek({
    packages: [
    '@aws-lambda-powertools/logger',
    ],
    week: '2020W1',
    });
    // week that includes 2020-01-01
    client.getWeek({
    packages: [
    '@aws-lambda-powertools/logger',
    ],
    week: '2020-01-01',
    });
    // week that includes 2020-01-01, starting on Sunday
    client.getWeek({
    packages: [
    '@aws-lambda-powertools/logger',
    ],
    week: '2020-01-01',
    startOfWeek: 'sunday',
    });

    In all cases, the response will be an array of objects, one for each package, with the following shape:

    Example

    {
    downloads: 1234,
    start: '2020-01-01',
    end: '2020-01-07',
    package: '@aws-lambda-powertools/logger',
    }

Generated using TypeDoc