Skip to content

Commit

Permalink
Merge pull request #60 from limrv/accept-blank-init
Browse files Browse the repository at this point in the history
Accept empty string as initialization value
  • Loading branch information
gentooboontoo committed Apr 13, 2016
2 parents dc3b5d7 + dad85e1 commit b5fdafb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
10 changes: 3 additions & 7 deletions spec/quantitiesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,9 @@ describe("js-quantities", function() {
expect(function() { Qty("mmm"); }).toThrow("Unit not recognized");
});

it("should throw error when passing an empty string", function() {
expect(
function() { Qty(""); }
).toThrow("Unit not recognized");
expect(
function() { Qty(" "); }
).toThrow("Unit not recognized");
it("should accept empty string as unitless 1", function() {
expect(Qty("").same(Qty("1"))).toBe(true);
expect(Qty(" ").same(Qty("1"))).toBe(true);
});

it("should throw error when passing a null value", function() {
Expand Down
3 changes: 0 additions & 3 deletions src/quantities.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,6 @@ SOFTWARE.
val = val.toString();
}
val = val.trim();
if (val.length === 0) {
throw new QtyError("Unit not recognized");
}

var result = QTY_STRING_REGEX.exec(val);
if (!result) {
Expand Down

0 comments on commit b5fdafb

Please sign in to comment.