Berkmann18 / lh-avg

LightHouse average calculator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

lh-avg

LightHouse Average calculator

NPM

Node.js CI

All Contributors

license downloads codecov Known Vulnerabilities Responsible Disclosure Policy Commitizen friendly GitHub code size in bytes BCH compliance Codacy Badge semantic-release

Install

npm i --save lh-avg

Usage

CLI

Usage: cli [options] <scoreStrings...>

LightHouse average calculator

Options:
  -V, --version          output the version number
  -p, --percentage       Return the result(s) in percentage form
  -f, --format <format>  Return the result(s) in a specific format (json, csv, md, html), default: text
  -s, --split            Split the string by metric
  -d, --diff             Shows the difference between the first row and subsequent ones
  -n, --names <names>    Add names to each results
  -c, --config <config>  Use the configuration from the specified path
  -m, --multi <multi>    Show multiple results (EXPERIMENTAL, please the config option for this)
  -h, --help             display help for command

Configuration

The CLI will look for configuration files following the cosmiconfig approach:

  1. lh-avg property in package.json
  2. .lh-avgrc (using JSON or YAML syntax)
  3. .lh-avgrc.json
  4. .lh-avgrc.yaml/.lh-avgrc.yml/.lh-avgrc.js
  5. lh-avg.config.js

It will first read the configuration (if it finds one) then look at the CLI options (which overrides the relevant configuration options).

Note: If it encounters a broken/invalid JSON configuration file, it will try to fix it and save the changes to the file itself. It won't be able to do the same for YAML files!

Example

{
  "format": "md",
  "split": true,
  "percentage": true,
  "inputs": [
    "86/100/79/100/(1, 1, 6)",
    "90/100/79/100/(1, 2, 6)"
  ],
  "diff": true,
  "names": ["`master`", "`pr`"],
  "multi": {}
}

Imports

import average from 'lh-avg';
// Or
const average = require('lh-avg').default;

Example

import average from 'lh-avg';

const lightHouseScores = ['14 / 100 / 98 / 100 / (1, 0, 6)'];

console.log(average(lightHouseScores));
/* {
  perf: 0.14,
  a11y: 1,
  bp: 0.98,
  seo: 1,
  pwa: { fnr: 0.3333333333333333, ins: 0, po: 0.8571428571428571 },
  average: 0.6157823129251702
} */

console.log(average(lightHouseScores, { asPercentage: true }));
/* {
  perf: '14%',
  a11y: '100%',
  bp: '98%',
  seo: '100%',
  pwa: { fnr: '33.33%', ins: '0%', po: '85.71%' },
  average: '61.58%'
} */

For more documentation, please check ./doc/index.html.

Contributing

Please consult CONTRIBUTING for guidelines on contributing to this project.

Author

lh-avg Β© Berkmann18, Released under the Apache-2.0 License.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Maximilian Berkmann

πŸ’» πŸ“– πŸ’‘ πŸ€” πŸš‡ 🚧 πŸ“¦ ⚠️

This project follows the all-contributors specification. Contributions of any kind welcome!

About

LightHouse average calculator

License:Apache License 2.0


Languages

Language:JavaScript 69.7%Language:TypeScript 29.7%Language:Shell 0.6%