Skip to content

Commit d97fb49

Browse files
author
Marco Cesarato
committed
refactor: move isnumeric method to utils
1 parent be421c0 commit d97fb49

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

index.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, {Component} from "react";
22
import {Text, TextInput, TouchableHighlight, View} from "react-native";
33
import PropTypes from "prop-types";
44
import {Style} from "./style";
5-
import {isEmpty, isStringEmpty, debounce} from "./utils";
5+
import {debounce, isNumeric, isEmpty, isStringEmpty} from "./utils";
66

77
/**
88
* Default Color
@@ -123,7 +123,7 @@ class InputSpinner extends Component {
123123
const res = await this.props.onChange(num);
124124
if (res === false) {
125125
return;
126-
} else if (this.isNumeric(res)) {
126+
} else if (isNumeric(res)) {
127127
num = this.parseNum(res);
128128
}
129129
}
@@ -285,7 +285,7 @@ class InputSpinner extends Component {
285285
const res = await this.props.onIncrease(increased_num);
286286
if (res === false) {
287287
return;
288-
} else if (this.isNumeric(res)) {
288+
} else if (isNumeric(res)) {
289289
num = this.parseNum(res);
290290
}
291291
}
@@ -313,7 +313,7 @@ class InputSpinner extends Component {
313313
const res = await this.props.onDecrease(decreased_num);
314314
if (res === false) {
315315
return;
316-
} else if (this.isNumeric(res)) {
316+
} else if (isNumeric(res)) {
317317
num = this.parseNum(res);
318318
}
319319
}
@@ -327,20 +327,6 @@ class InputSpinner extends Component {
327327
this.onChange(num);
328328
}
329329

330-
/**
331-
* Detect if is a numeric value
332-
* @param num
333-
* @returns {boolean}
334-
*/
335-
isNumeric(num) {
336-
return (
337-
num !== null &&
338-
num !== false &&
339-
!isNaN(parseFloat(num)) &&
340-
!isNaN(num - 0)
341-
);
342-
}
343-
344330
/**
345331
* On Submit keyboard
346332
* @returns {*}

utils.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,18 @@ export const debounce = (callback, wait, context = null) => {
5555
timeout = setTimeout(() => callback.apply(context, args), wait);
5656
};
5757
};
58+
59+
/**
60+
* Detect if is a numeric value
61+
* @param num
62+
* @returns {boolean}
63+
*/
64+
export const isNumeric = (num) => {
65+
return (
66+
num !== "" &&
67+
num !== null &&
68+
num !== false &&
69+
!isNaN(parseFloat(num)) &&
70+
!isNaN(num - 0)
71+
);
72+
};

0 commit comments

Comments
 (0)