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

@ovl/score-calculator

v1.0.0

Published

A Vue component to calculate a score based on answers to questions

Downloads

5

Readme

🧮 Score Calculator

Want to know a score, get it here.

See a version of this component in use with the SwissPrEPared HIV risk calculator.


👩‍💻 Usage

Install the calculator from NPM.

npm install @ovl/score-calculator

Next, import it in the component where you want to use it:

import ScoreCalculator from '@ovl/score-calculator'

Props

Questions

These questions must be objects which have a unique ID, a title, and an array of answers. Let’s take this question as an example:

{
  id: 123456789,
  title: 'How many nights do you sleep in a normal week?',
  answers: [
    { text: '≥10', score: 7 },
    { text: '6–9', score: 4 },
    { text: '0–5', score: 0 }
  ]
}

As you can see, all answers have a score property. That’s rather important, as the diligent score calculation robot making this component work needs scores to compute. As it’s diligent but not sophisticated, the scores need to be given to them.

In it’s former life it has been employed as the calculating soul of an abacus. Unfortunartely, abaci went out of fashion and our score calculating robot became a bit bored. Luckily we found them before something bad happened and they now works happily inside the score calculator.

Got a bit carried away there. Back to the component.

More formally:

An answer is an object of text and score.

answer: Object {
  text: String,
  score: Number
}

A question has a mandatory, unique ID and a title as well as an array of answers which need to implement the answer interface.

question: Object {
  id: String | Number,
  title: String,
  answers: Array [answer]
}

Finally, questions are an array of question types:

questions: Array[question]

buttonText

To change the text content of the button, use the buttonText prop:

buttonText: {
  type: String,
  default: 'Show results'
}

questionsOptional

By default all questions are required before a score is calculated. If some questions are optional, you can change this behaviour through the questionsOptional prop.

questionsOptional: {
  type: Boolean,
  default: false
}

Events

Once a user clicks on the button there two possibilities.

If all questions have been answered – or questionsOptional is set to true – the component emits scoreResult with the accumulated score as its payload.

If not all questions have been answered and questionsOptional is set to false the emitted event is missingQuestions without the missing questions as its payload.

🥼 Development setup

You’ll need to install the project’s dependencies first:

npm install

Compiles and hot-reloads for development

npm run serve

Compiles and minifies for production

npm run build

Run your unit tests

npm run test:unit

Lints and fixes files

npm run lint

Customize configuration

See Configuration Reference.