Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
clementlevasseur committed Dec 2, 2016
1 parent 773a921 commit fd92f1b
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
build
Gruntfile.js
Gruntfile.js
46 changes: 22 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,40 @@ or clone:

## Getting Started

Conversion function returns an object that contain the parsed and NORMALIZED value/unit AND some function described bellow :

```javascript
tinu.distance(12); // → {value: 12, unit: "cm", ...}
tinu.distance(12, "mm"); // → {value: 12, unit: "mm", ...}
tinu.distance(12, "in"); // → {value: 12, unit: "in", ...}
tinu.distance(12, "inch"); // → {value: 12, unit: "in", ...}
tinu.distance("12m"); // → {value: 12, unit: "m", ...}
tinu.distance("12 m"); // → {value: 12, unit: "m", ...}
tinu.distance("12.00m"); // → {value: 12, unit: "m", ...}

unitConvert.area(80, "m2"); // → {value: 80, unit: "m2", ...}
Conversion function returns an object that contain the parsed and NORMALIZED value/unit AND some function described bellow :

```javascript
Tinu.distance(12); // → {value: 12, unit: "cm", ...}
Tinu.distance(12, "mm"); // → {value: 12, unit: "mm", ...}
Tinu.distance(12, "in"); // → {value: 12, unit: "in", ...}
Tinu.distance("12m"); // → {value: 12, unit: "m", ...}
Tinu.distance("12 m"); // → {value: 12, unit: "m", ...}
Tinu.distance("12.00m"); // → {value: 12, unit: "m", ...}

Tinu.area(80, "m2"); // → {value: 80, unit: "m2", ...}
```

The .to() method converts to the same object but in the requested unit.

```javascript
tinu.distance(12).to("m"); // → {value: 0.012, "m", ...}
tinu.distance(12).to("meter"); // → {value: 0.012, "m", ...}
tinu.distance(12).to("m").to("mm"); // → {value: 120, "mm", ...}
tinu.distance(12).to(); // → converts to the default target unit: {value: 0.012, "m", ...}
```javascript
Tinu.distance(12).to("m"); // → {value: 0.012, "m", ...}
Tinu.distance(12).to("m").to("mm"); // → {value: 120, "mm", ...}
Tinu.distance(12).to(); // → converts to the default target unit: {value: 0.012, "m", ...}
```

The .toNumber(unit=null) method converts to a Number in the requested unit

```javascript
tinu.distance(12).toNumber("m"); // → 0.012
tinu.distance(12).toNumber(); // → converts to the default target unit: 0.012
```javascript
Tinu.distance(12).toNumber("m"); // → 0.012
Tinu.distance(12).toNumber(); // → converts to the default target unit: 0.012
```

The .toString(unit=null, numericScale=null) method converts to a String in the requested unit, that includes the unit

```javascript
tinu.distance(12, "cm").toString("m"); // → "0.012 m"
tinu.distance(12, "cm").toString("m", 2); // → "0.01 m"
tinu.distance(12, "cm").toString(); // → converts to the default target unit: "0.012 m"
```javascript
Tinu.distance(12, "cm").toString("m"); // → "0.012 m"
Tinu.distance(12, "cm").toString("m", 2); // → "0.01 m"
Tinu.distance(12, "cm").toString(); // → converts to the default target unit: "0.012 m"
```

Please help yourself to add type and other unit if needed !
37 changes: 33 additions & 4 deletions build/tinu.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fd92f1b

Please sign in to comment.