This repository was archived by the owner on Feb 20, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ import round from './round'
37
37
import checkPalindrome from './checkPalindrome'
38
38
import isFunction from './is-function'
39
39
import isOdd from './is-odd'
40
+ import isNumeric from './is-numeric'
40
41
41
42
export {
42
43
isOdd ,
@@ -78,5 +79,6 @@ export {
78
79
checkPalindrome ,
79
80
isFunction ,
80
81
subtraction ,
82
+ isNumeric ,
81
83
}
82
84
Original file line number Diff line number Diff line change
1
+ export default isNumeric
2
+
3
+ /**
4
+ * Original Source:
5
+ * https://stackoverflow.com/questions/9716468/is-there-any-function-like-isnumeric-in-javascript-to-validate-numbers
6
+ *
7
+ * This method will check whether an expression can be evaluated as a number or not.
8
+ *
9
+ * @param {Object } n - number to check
10
+ * @return {Boolean } - True if n is numeric, false if not
11
+ */
12
+ function isNumeric ( n ) {
13
+ return ! isNaN ( parseFloat ( n ) ) && isFinite ( n )
14
+ }
15
+
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Created by Ibrahim on 07/08/2017.
3
+ */
4
+ import test from 'ava'
5
+ import { isNumeric } from '../src'
6
+
7
+ test ( 'checks if expression is number and returns true' , t => {
8
+ const n = "5" ;
9
+ const expected = true ;
10
+ const actual = isNumeric ( n ) ;
11
+ t . deepEqual ( actual , expected )
12
+ } ) ;
13
+
14
+ test ( 'checks if expression is number and returns false' , t => {
15
+ const n = "hello" ;
16
+ const expected = false ;
17
+ const actual = isNumeric ( n ) ;
18
+ t . deepEqual ( actual , expected )
19
+ } ) ;
You can’t perform that action at this time.
0 commit comments