-
Notifications
You must be signed in to change notification settings - Fork 0
Home
David Vegh edited this page Apr 30, 2022
·
10 revisions
write-npmstat makes it easy to collect, filter and save npm statistics to csv files.
Visit our documentation site for code reference.
In these examples we initilaize a WriteNpmStat
class in order to collect statistics about npm-stat-api
npm package.
Parameters:
-
packageName
: name of the target npm package -
outDir
: path of the directory where the gathered data will be saved into csv files
Because outDir
is null
the gathered statistics will be only printed to the console.
const WriteNpmStat = require("write-npmstat").default;
const targetPackage = "npm-stat-api";
const writenpmstat = new WriteNpmStat(targetPackage);
Because outDir
is not null
the gathered statistics will be saved into csv files too.
const WriteNpmStat = require("write-npmstat").default;
const targetPackage = "npm-stat-api";
const csvDir = "stats/npm-stat-api";
const writenpmstat = new WriteNpmStat(targetPackage, csvDir);
Properties:
-
outDir
: path of the directory where the gathered data will be saved into csv files -
datePeriod
: grouping of the statistics -
writePackageName
: flag used to write the name of the package into a csv column -
mergeStoredData
: flag used to merge actual npm statistics with previously stored
outDir
can be changed or set at anytime.
const WriteNpmStat = require("write-npmstat").default;
const targetPackage = "npm-stat-api";
const writenpmstat = new WriteNpmStat(targetPackage);
writenpmstat.outDir = "stats/npm-stat-api";
const WriteNpmStat = require("write-npmstat").default;
const targetPackage = "npm-stat-api";
const writenpmstat = new WriteNpmStat(targetPackage);
writenpmstat.datePeriod = "month";
const WriteNpmStat = require("write-npmstat").default;
const targetPackage = "npm-stat-api";
const writenpmstat = new WriteNpmStat(targetPackage);
writenpmstat.writePackageName = true;
const WriteNpmStat = require("write-npmstat").default;
const targetPackage = "npm-stat-api";
const writenpmstat = new WriteNpmStat(targetPackage);
writenpmstat.mergeStoredData = false;
Parameters:
-
startDate
: start date of the statistics -
endDate
: end date of the statistics
const WriteNpmStat = require("write-npmstat").default;
const targetPackage = "npm-stat-api";
const writenpmstat = new WriteNpmStat(targetPackage);
writenpmstat.getNpmStat("2022-03", "2022-04-10").then(stats => {
console.log(stats);
});
const WriteNpmStat = require("write-npmstat").default;
const targetPackage = "npm-stat-api";
const writenpmstat = new WriteNpmStat(targetPackage);
writenpmstat.getLastWeekNpmStat().then(stats => {
console.log(stats);
});
Parameters:
-
startDate
: start date of the statistics -
endDate
: end date of the statistics -
postfix
: postfix of the csv file
const WriteNpmStat = require("write-npmstat").default;
const targetPackage = "npm-stat-api";
const csvDir = "stats/npm-stat-api";
const writenpmstat = new WriteNpmStat(targetPackage, csvDir);
writenpmstat.datePeriod = "month";
writenpmstat.writeNpmStat("2022", "2022-03");
Parameters:
-
postfix
: postfix of the csv file
const WriteNpmStat = require("write-npmstat").default;
const targetPackage = "npm-stat-api";
const csvDir = "stats/npm-stat-api";
const writenpmstat = new WriteLastWeekNpmStat(targetPackage, csvDir);
writenpmstat.writeLastWeekNpmStat();