Skip to content

Commit

Permalink
Fixes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Pugliese committed Dec 29, 2015
1 parent 87bd606 commit 8998d18
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function returnCol(row, map){
if(map[item].percision){
percision = map[item].percision;
}
parsed_row[map[item].name] = parseFloat(value.splice(map[item].width - percision, 0, "."));
parsed_row[map[item].name] = parseFloat(value.splice(map[item].width - percision, 0, ".")).toFixed(percision);
break;
case "int":
parsed_row[map[item].name] = parseInt(value);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fixy",
"version": "0.3.2",
"version": "0.3.3",
"description": "A Fixed Width Input Parser",
"main": "index.js",
"directories": {
Expand Down
48 changes: 47 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,53 @@ describe("Fixy Tests", function() {
Initial: "SJP",
DateEntered: "2012-12-31",
IsBad: false,
Rating: 9.2
Rating: 9.20
}]);
});
it("should return fixed-width-input as array(object)", function () {
var test = fixy.parse({
map:[{
name: "Age",
width: 2,
start: 1,
type: "int"
},{
name: "Initial",
width: 3,
start: 3,
type: "string"
},{
name: "DateEntered",
width: 8,
start: 6,
type: "date",
inputformat: "YYYYMMDD",
outputformat: "YYYY-MM-DD"
},{
name: "IsBad",
width: 1,
start: 14,
type: "bool",
tVal: "Y",
fVal: "N"
},{
name: "Rating",
width: 3,
start: 15,
type: "float",
percision: 2
}],
options:{
fullwidth: 17,
skiplines: null
}
}, "30SJP20121231N900");
assert.deepEqual(test, [{
Age: 30,
Initial: "SJP",
DateEntered: "2012-12-31",
IsBad: false,
Rating: 9.00
}]);
});
it("should return fixed-width-input as csv-string (no inner commas)", function () {
Expand Down

0 comments on commit 8998d18

Please sign in to comment.