Skip to content
This repository has been archived by the owner on Jun 10, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3 from OussamaRomdhane/0.3.0
Browse files Browse the repository at this point in the history
0.3.0
  • Loading branch information
Oussama Romdhane authored Aug 20, 2016
2 parents c4f05cf + ab489a7 commit b165ea3
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 1 deletion.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ For now it supports:

- Length (distance)
- Mass (weight)
- Area

### Installation:

Expand Down Expand Up @@ -82,3 +83,18 @@ ton (long) | ltn
ton (short) | stn
ton-metric | t
tonne (U.S. metric ton) | t

Area

Unit | Abbreviation in easy-converter
----------------- | :----------------------------:
square inch | in2
square foot | ft2
square yard | yd2
square mile | mi2
acre | ac
hectare | ha
square millimeter | mm2
square centimeter | cm2
square meter | m2
square kilometer | km2
4 changes: 4 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ var converters = {
'g', 'lhwt', 'shwt', 'kg', 'Mg', 'mg', 'aoz',
'toz', 'dwt', 'alb', 'lb', 'tlb', 'slug',
'st', 'lAT', 'sAT', 'ltn', 'stn', 't'
],
'area': [
'in2', 'ft2', 'yd2', 'mi2', 'ac', 'ha',
'mm2', 'cm2', 'm2', 'km2'
]
};

Expand Down
12 changes: 12 additions & 0 deletions lib/ratios/area.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
"in2": 0.00064516,
"ft2": 0.09290304,
"yd2": 0.83612736,
"mi2": 2589988.110336,
"ac": 4046.8564224,
"ha": 10000,
"mm2": 0.000001,
"cm2": 0.0001,
"m2": 1,
"km2": 1000000
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "easy-converter",
"version": "0.2.0",
"version": "0.3.0",
"description": "A unit converter for Javascript",
"main": "lib",
"scripts": {
Expand Down
57 changes: 57 additions & 0 deletions tests/area.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
var assert = require('chai').assert;
var easyconverter = require('../lib');

var EPSILON = require('./epsilon');

var c = new easyconverter({});

describe('Area converter', function() {
// Check inch² to meter² conversion (conversion with reference unit)
describe('3 inch² to meter²', function() {
it('should return 0.00193548', function() {
assert.closeTo(c.convert(3, 'in2').to('m2'), 0.00193548, EPSILON);
});
});
// Check meter² to inch² conversion (reverse conversion with reference unit)
describe('0.00193548 meter² to inch²', function() {
it('should return 3', function() {
assert.closeTo(c.convert(0.00193548, 'm2').to('in2'), 3, EPSILON);
});
});
// Check kilometer² to mile² conversion (conversion no reference unit)
describe('28.9 kilometer² to mile²', function() {
it('should return 11.158352381877', function() {
assert.closeTo(c.convert(28.9, 'km2').to('mi2'), 11.158352381877, EPSILON);
});
});
// Check mile² to kilometer² conversion (reverse conversion no reference unit)
describe('15 mile² to kilometer²', function() {
it('should return 38.84982165504', function() {
assert.closeTo(c.convert(15, 'mi2').to('km2'), 38.84982165504, EPSILON);
});
});
// Check centimeter² to centimeter² conversion (same unit conversion)
describe('7 centimeter² to centimeter²', function() {
it('should return 7', function() {
assert.closeTo(c.convert(7, 'cm2').to('cm2'), 7, EPSILON);
});
});
// Check meter² to meter² conversion (same unit is also the reference unit)
describe('3 meter² to meter²', function() {
it('should return 3', function() {
assert.closeTo(c.convert(3, 'm2').to('m2'), 3, EPSILON);
});
});
// Check zero value conversion
describe('0 meter² to centimeter²', function() {
it('should return 0', function() {
assert.closeTo(c.convert(0, 'm2').to('cm2'), 0, EPSILON);
});
});
// Check zero value conversion (same unit)
describe('0 meter² to meter²', function() {
it('should return 0', function() {
assert.closeTo(c.convert(0, 'm2').to('m2'), 0, EPSILON);
});
});
});

0 comments on commit b165ea3

Please sign in to comment.