Skip to content

Commit

Permalink
asNumber: return undefined when value is empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
sjhewitt committed Nov 2, 2016
1 parent 9590c42 commit 8f1f66d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ export function mergeObjects(obj1, obj2, concatArrays = false) {
}

export function asNumber(value) {
if (value === "") {
return undefined;
}
if (/\.$/.test(value)) {
// "3." can't really be considered a number even if it parses in js. The
// user is most likely entering a float.
Expand Down
4 changes: 4 additions & 0 deletions test/utils_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ describe("utils", () => {
it("should allow numbers with a 0 in the first decimal place", () => {
expect(asNumber("3.07")).eql(3.07);
});

it("should return undefined if the input is empty", () => {
expect(asNumber("")).eql(undefined);
});
});

describe("isMultiSelect()", () => {
Expand Down

0 comments on commit 8f1f66d

Please sign in to comment.