5.2.2 • Published 1 year ago

cybersaksham-npm-logs v5.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

cybersaksham-npm-logs

NPM version Downloads Size License

This package generates professional log messages in cli.

Installation

npm install cybersaksham-npm-logs
# Or
yarn add cybersaksham-npm-logs

Usage

Import and call the functions.

const logs = require("cybersaksham-npm-logs");

Error

const logs = require("cybersaksham-npm-logs");

logs.showError({
  code: 400,
  errors: [
    "Not Found - GET https://registry.npmjs.org/error - Not found",
    "",
    "'error@*' is not in this registry.",
    "",
    "Note that you can also install from a",
    "tarball, folder, http url, or git url.",
  ],
  summary: [
    "A complete log of this run can be found in:",
    "\t/home/cybersaksham/.npm/_logs/2022-12-27T17_58_06_509Z-debug-0.log",
  ],
});

Warning

const logs = require("cybersaksham-npm-logs");

logs.showWarning({
  warnings: [
    "You are running `portfolio-generator` 4.0.0, which is behind the latest release (4.1.0).",
    "",
    "We recommend always using the latest version of portfolio-generator if possible.",
  ],
  summary: [
    "The latest instructions for creating a new app can be found here:",
    "https://portfolio-generator.cybersaksham.co.in/docs/getting-started/",
  ],
});

Notice

const logs = require("cybersaksham-npm-logs");

logs.showNotice({
  notices: [
    "Creating file package.json",
    "Creating file index.js",
    "Installing packages: npm install",
    "Setting up...",
  ],
  summary: [
    "The latest instructions for creating a new app can be found here:",
    "https://portfolio-generator.cybersaksham.co.in/docs/getting-started/",
  ],
});

Single Progress

const logs = require("cybersaksham-npm-logs");
const path = require("path");

logs.showProgress({
  source = "https://sabnzbd.org/tests/internetspeed/20MB.bin",
  destination = path.join(__dirname + "/test.bin"),
});

Multi Progress

const logs = require("cybersaksham-npm-logs");
const path = require("path");

let list = [];
for (let i = 0; i < 23; i++) {
  list.push({
    source: "https://sabnzbd.org/tests/internetspeed/20MB.bin",
    destination: path.join(__dirname, `/20mb_${i + 1}.bin`),
  });
}

logs.showMultipleProgress(list, 6);

Test

# Error
npm run test-error
# Warning
npm run test-warn
# Notice
npm run test-notice
# Single Progress
npm run test-download
# Notice
npm run test-multi-download

Parameters

Error (logs.showError)

ParameterTypeDefualtDescription
codeInteger404Error status code
errorsArray List of error statements to show
summaryArray List of summary statements

Warning (logs.showWarning)

ParameterTypeDefualtDescription
warningsArray List of warning statements to show
summaryArray List of summary statements

Notice (logs.showNotice)

ParameterTypeDefualtDescription
noticesArray List of notice statements to show
summaryArray List of summary statements

Single Progress (logs.showProgress)

ParameterTypeDefualtDescription
sourceString"https://sabnzbd.org/tests/internetspeed/20MB.bin"Source URL
destinationStringpath.join(__dirname + "/test.bin")Destination path

Multi Progress (logs.showMultipleProgress)

ParameterTypeDefualtDescription
fileListArray List of files
chunksizeNumber10Size of chunk to download at a time
  • Each file in fileList is an object & contains two fields.
ParameterTypeDefualtDescription
sourceString"https://sabnzbd.org/tests/internetspeed/20MB.bin"Source URL
destinationStringpath.join(__dirname + "/test.bin")Destination path

License

Released under the MIT License.

Contribution

If you want to contribute to the project and make it better, your help is very welcome, create a pull request with your suggested feature / bug fix / enhancements.