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

@violacaroline/wizard

v3.0.15

Published

This package will make it easy to do some of the most common unit conversions

Downloads

41

Readme

Wizard

What is Wizard?

Disclaimer: This is a student project created according to specifics by Linneaus University, Sweden.

Use the Wizard to convert some of the most common units for wind (km/h, m/s, ft/s, mph, knots), temperature (celsius, fahrenheit), distance (inch, foot, yard, mile), weight (ounce, pound) and volume (pints, gallons).

The Wizard has 5 available methods taking an options object as an argument and returning the converted value from the specified units/values in the options.

  • convertWind(options)
  • convertTemperature(options)
  • convertDistance(options)
  • convertWeight(options)
  • convertVolume(options)

The Wizard is not complete, meaning, it does NOT convert back and forth between all units mentioned - some only converts one way. Details per unit follows below.

How do you install?

Run npm i @violacaroline/wizard

How do you use?

import Wizard from '@violacaroline/wizard'

Errors

The library throws error objects.

Generic errors covering empty/invalid option object or validation of numbers/positive numbers are of the basic javascript Error type containing a user friendly description of the problem in the error.message property.

Specific unit errors are thrown when someone enters an invalid unit type for the kind of conversion that is desired (wind, temperature, distance, weight, volume). The error contains a user friendly description of the problem through error.getErrorInfo() List of unit errors:

  • WindError
  • TemperatureError
  • DistanceError
  • WeightError
  • VolumeError

Wrapping your wizard conversion method in a try catch block will let you catch the error and display/handle it as you wish. See example below.

import Wizard from '@violacaroline/wizard'

const wizard = new Wizard()

const options = {
  fromUnit: 'kmh',
  toUnit: 'mph',
  value: 100
}

try {
  const convertedValue = wizard.convertWind(options)

  console.log('The converted value', convertedValue)

} catch {
  if (error instanceof Error) {
    console.log('This is a generic error: ', error.message)
  } else {
    console.log('This is a unit specific error: ', error.getErrorInfo())
  }
}

Converting wind

The Wizard can convert wind speeds back AND forth between, ONLY, the following wind speed units: kmh, ms, fts, mph, knots.

You create an options object containing the following properties: fromUnit, toUnit and value.

  • fromUnit - Represents the unit you wish to convert FROM
  • toUnit - Represents the unit you wish to convert TO
  • value - Represents the value you wish to convert

Code example:

import Wizard from '@violacaroline/wizard'

const wizard = new Wizard()

const options = {
  fromUnit: 'kmh',
  toUnit: 'mph',
  value: 100
}

const convertedValue = wizard.convertWind(options)

console.log('The converted value', convertedValue)

Converting temperature

The Wizard can convert temperatures back AND forth between, ONLY, the following temperature units: celsius, fahrenheit.

You create an options object containing the following properties: fromUnit and value.

  • fromUnit - Represents the unit you wish to convert FROM
  • value - Represents the value you wish to convert

Code example:

import Wizard from '@violacaroline/wizard'

const wizard = new Wizard()

const options = {
  fromUnit: 'fahrenheit',
  value: 100
}

const convertedValue = wizard.convertTemperature(options)

console.log('The converted value', convertedValue)

Converting distance

The Wizard can convert distance FROM, ONLY, the following distance units: inches, feet, yards, miles.

For inches and feet, the wizard can ONLY convert TO the following distance units: centimeters, meters.

For yards and miles, the wizard can ONLY convert TO the following distance units: meters, kilometers.

You create an options object containing the following properties: fromUnit, toUnit and value.

  • fromUnit - Represents the unit you wish to convert FROM
  • toUnit - Represents the unit you wish to convert TO
  • value - Represents the value you wish to convert

Code example:

import Wizard from '@violacaroline/wizard'

const wizard = new Wizard()

const options = {
  fromUnit: 'feet',
  toUnit: 'centimeters',
  value: 100
}

const convertedValue = wizard.convertDistance(options)

console.log('The converted value', convertedValue)
import Wizard from '@violacaroline/wizard'

const wizard = new Wizard()

const options = {
  fromUnit: 'yards',
  toUnit: 'kilometers',
  value: 100
}

const convertedValue = wizard.convertDistance(options)

console.log('The converted value', convertedValue)

Converting weight

The Wizard can convert weight FROM, ONLY, the following weight units: ounces, pounds.

The Wizard can convert weight TO, ONLY, the following weight units: grams, kilograms.

You create an options object containing the following properties: fromUnit, toUnit and value.

  • fromUnit - Represents the unit you wish to convert FROM
  • toUnit - Represents the unit you wish to convert TO
  • value - Represents the value you wish to convert

Code example:

import Wizard from '@violacaroline/wizard'

const wizard = new Wizard()

const options = {
  fromUnit: 'pounds',
  toUnit: 'kilograms',
  value: 100
}

const convertedValue = wizard.convertWeight(options)

console.log('The converted value', convertedValue)

Converting volume

The Wizard can convert volumes FROM, ONLY, the following volume units: pints, gallons.

The Wizard can convert volumes TO, ONLY, the following volume units: litres. Hence, a toUnit is not specified.

You create an options object containing the following properties: fromUnit and value.

  • fromUnit - Represents the unit you wish to convert FROM
  • value - Represents the value you wish to convert

Code example:

import Wizard from '@violacaroline/wizard'

const wizard = new Wizard()

const options = {
  fromUnit: 'gallons',
  value: 100
}

const convertedValue = wizard.convertVolume(options)

console.log('The converted value', convertedValue)

Version

This is version 3.0.15 of this package.

Test Report

A test report is available at: https://github.com/AndreaViolaCaroline/1dv610-assignment-L1/blob/main/testrapport.md