All Projects → appalaszynski → Length.js

appalaszynski / Length.js

Licence: mit
📏 JavaScript library for length units conversion.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Length.js

Unitsnet
Makes life working with units of measurement just a little bit better.
Stars: ✭ 641 (+119.52%)
Mutual labels:  measure, units, measurements, units-of-measure, converter, conversion
Rando.js
The world's easiest, most powerful random function.
Stars: ✭ 659 (+125.68%)
Mutual labels:  open-source, library, npm, npm-package, javascript-library
Js Quantities
JavaScript library for quantity calculation and unit conversion
Stars: ✭ 335 (+14.73%)
Mutual labels:  parser, measure, units, conversion, convert
Rink Rs
Unit conversion tool and library written in rust
Stars: ✭ 242 (-17.12%)
Mutual labels:  units, measurements, units-of-measure, conversion
Convert Units
An elegant way to convert quantities between different units.
Stars: ✭ 480 (+64.38%)
Mutual labels:  measure, units, conversion, convert
xbytes
Parse bytes to human readable sizes (4747) → ('4.75 KB') and vice versa.
Stars: ✭ 17 (-94.18%)
Mutual labels:  converter, utility, convert
Minimal Feedback
🗳 minimal-feedback is a blazingly fast and highly customizable component to get user feedback.
Stars: ✭ 78 (-73.29%)
Mutual labels:  open-source, npm, npm-package
Cash Cli
💰💰 Convert currency rates directly from your terminal!
Stars: ✭ 168 (-42.47%)
Mutual labels:  open-source, npm, npm-package
Sdk
Library for using Grafana' structures in Go programs and client for Grafana REST API.
Stars: ✭ 193 (-33.9%)
Mutual labels:  parser, library, metrics
Units
A compile-time enabled Modern C++ library that provides compile-time dimensional analysis and unit/quantity manipulation.
Stars: ✭ 365 (+25%)
Mutual labels:  library, units, units-of-measure
To Milliseconds
Convert an object of time properties to milliseconds: `{seconds: 2}` → `2000`
Stars: ✭ 136 (-53.42%)
Mutual labels:  parser, converter, npm-package
Remarshal
Convert between CBOR, JSON, MessagePack, TOML, and YAML
Stars: ✭ 421 (+44.18%)
Mutual labels:  utility, converter, conversion
Angular Tree Component
A simple yet powerful tree component for Angular (>=2)
Stars: ✭ 1,031 (+253.08%)
Mutual labels:  open-source, library, javascript-library
Membrain
🧠 Type-safe memory units
Stars: ✭ 53 (-81.85%)
Mutual labels:  library, measure, units
fp-units
An FP-oriented library to easily convert CSS units.
Stars: ✭ 18 (-93.84%)
Mutual labels:  converter, conversion, units
Gelatin
Transform text files to XML, JSON, or YAML
Stars: ✭ 150 (-48.63%)
Mutual labels:  parser, converter, convert
cpc
Text calculator with support for units and conversion
Stars: ✭ 89 (-69.52%)
Mutual labels:  converter, conversion, units
Ngx Smart Modal
Modal/Dialog component crafted for Angular
Stars: ✭ 256 (-12.33%)
Mutual labels:  library, npm, npm-package
html-to-react
A lightweight library that converts raw HTML to a React DOM structure.
Stars: ✭ 696 (+138.36%)
Mutual labels:  conversion, npm-package, javascript-library
Indriya
JSR 385 - Reference Implementation
Stars: ✭ 74 (-74.66%)
Mutual labels:  measure, units, units-of-measure

Length.js

JavaScript Library for Length Units Conversion

Version License Build Status Coverage Status



Table of Contents


Installation

Length.js was designed to work both in the browser and in Node.js.

Browser

<script src="length.js"></script>

Length.js is available on unpkg CDN in compressed and uncompressed version.

Node.js

$ npm install length.js
var length = require('length.js');
// or using ES6 import
import length from 'length.js';

Usage

Length.js creates an object which contains value and unit. To get this object, simply call length() with two supported arguments. Then you can call available methods.

The Length prototype is exposed through length.fn (if you want to add your own functions).


length(value, unit)

Creates an object which contains value and unit.

Arguments

  • value (Number): Number of units.

  • unit (String): Unit type.

    Available unit types:

    • pm: picometre: (1 / 1 000 000 000 000) m,
    • nm: nanometre: (1 / 1 000 000 000) m,
    • um: micrometre: (1 / 1 000 000) m,
    • mm: millimetre: (1 / 1 000) m,
    • cm: centimetre: (1 / 100) m,
    • dm: decimetre: (1 / 10) m,
    • m: metre,
    • dam: decametre: 10 m,
    • hm: hectoametre: 100 m,
    • km: kilometre: 1 000 m,
    • nmi: nautical mile: 1 852 m,
    • ft: foot: 0.3048 m,
    • in: inch: 0.0254 m,
    • yd: yard: 0.9144 m,
    • fm: fathom: 1.8288 m,
    • mi: mile: 1 609.344 m,
    • ld: lunar distance: 384 402 000 m,
    • au: astronomical unit: 149 597 870 700 m,
    • ly: light year: 9 460 730 472 580 800 m,
    • pc: parsec: ((648 000 / π) * 149 597 870 700) m.

Returns

  • (Object): New Length object.

Example

length(12, 'cm');
// => { value: 12, unit: 'cm' }

Methods

.to(unit)

Arguments

  • unit (String): Unit type.

Returns

  • (Object): New Length object with value converted to passed unit.

Example

length(100, 'cm').to('m');
// => { value: 1, unit: 'm' }

.add(value, [unit])

Arguments

  • value (Number): The number to increment value.
  • [unit] (String): Unit type in which the value was given.

Returns

  • (Object): New Length object with incremented value.

Example

length(100, 'cm').add(2);
// => { value: 102, unit: 'cm' }
length(100, 'cm').add(2, 'dm');
// => { value: 120, unit: 'cm' }

.toPrecision([digits])

Arguments

  • [digits] (Number): The number of digits to appear after the decimal point.

Returns

  • (Object): New Length object with fixed value.

Example

length(100, 'cm').toPrecision();
// => { value: 100, unit: 'cm' }
length(100, 'cm').toPrecision(2);
// => { value: 100, unit: 'cm' }
length(0.97982, 'cm').toPrecision(2);
// => { value: 0.98, unit: 'cm' }

.getValue()

Returns

  • (Number): Current value.

Example

length(100, 'cm').getValue();
// => 100

.getUnit()

Returns

  • (String): Current unit type.

Example

length(100, 'cm').getUnit();
// => cm

.getString(), .toString()

Returns

  • (String): String containing value and unit type.

Example

length(100, 'cm').getString();
length(100, 'cm').toString();
// => 100cm
console.log(length(10, 'm') + '');
// => 10m

Contributing

All contributions and suggestions are welcome! For suggested improvements, please create an issue. For direct contributions, please fork the repository, create your feature branch, commit your changes, push commits to the branch and create a new pull request.


License

The code is open source and available under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].