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

vue-units

v1.0.4

Published

Handy unit conversion filters for your Vue.js project

Downloads

674

Readme

vue-units

A plugin for adding handy conversion filters to your Vue.js project. Based on the convert-units package made by @ben-ng.

Installation

Install vue-units with NPM from the vue-units NPM repository by running the following command:

npm install vue-units --save

If you prefer to use Yarn, you can install it with the following command instead:

yarn add vue-units

Add it to your vue instance:

import Vue from 'vue';
import VueUnits from 'vue-units';

Vue.use(VueUnits)

If you don't use ES6, you can also include it as a script locally:

<script src="https://unpkg.com/vue-units@^1.0/vue-units.js"></script>

Usage

Filters

unit()

The filter unit(from, to, includeUnit) is added to your Vue instance, which makes it easy to convert between a set of units in your templates:

<template>
  <div id="app">
    <p>{{1500 | unit('m', 'km', true)}}</p>
  </div>
</template>

The above code will result in the following output:

1.5 km

If includeUnit is false, only the converted value will be returned:

1.5

To see a list of available conversion units, please refer to the official repository for convert-units.

Prototype

You can access the instance of convert-units anywhere in your Vue templates, which gives you access to the additional functions that the convert-units package provides:

this.$units(12000).from('mm').to('m');
// 12 Metres

this.$units(12000).from('mm').toBest();
// 12 Meters (the smallest unit with a value above 1)

this.$units(12000).from('mm').toBest({ exclude: ['m'] })
// 1200 Centimeters (the smallest unit excluding meters)

this.$units(12000).from('mm').toBest({ cutOffNumber: 10 });
// 900 Centimeters (the smallest unit with a value equal to or above 10)

this.$units(12000)from('mm').toBest({ cutOffNumber: 10 })
// 10 Meters (the smallest unit with a value equal to or above 10)

this.$units(12000).from('m').possibilities();
// ["mm", "cm", "m", "km", "in", "yd", "ft-us", "ft", "mi"]

this.$units().measures();
// [ 'length', 'mass', 'volume' ]

For additional methods, please refer to the official repository for convert-units.

Example:

<script>
export default {
  props: {
      distance: {
          type: Number,
          default: 123456789
      }
  },
  computed: {
      shortDistance() {
          const obj = this.$units(this.distance).from('cm2').toBest({
              exclude: ['m2']
          });
          return `${obj.val} ${obj.unit}`;
      }
  }
}
</script>

License

Copyright 2018 Emil Rosenius Pedersen

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.