File tree Expand file tree Collapse file tree 2 files changed +22
-6
lines changed Expand file tree Collapse file tree 2 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -8,13 +8,14 @@ _.mixin(require('underscore.inflections'))
8
8
// 'true' -> true
9
9
// '1' -> 1
10
10
function toNative ( value ) {
11
- if ( value === 'true' || value === 'false ' ) {
12
- return value === 'true'
13
- } else if ( ! isNaN ( + value ) ) {
14
- return + value
15
- } else {
16
- return value
11
+ if ( typeof value === 'string ' ) {
12
+ if ( value === 'true' || value === 'false' ) {
13
+ return value === 'true'
14
+ } else if ( ! isNaN ( + value ) ) {
15
+ return + value
16
+ }
17
17
}
18
+ return value
18
19
}
19
20
20
21
// Creates incremental id.
Original file line number Diff line number Diff line change @@ -28,4 +28,19 @@ describe('utils', function() {
28
28
29
29
} )
30
30
} )
31
+
32
+ describe ( 'toNative' , function ( ) {
33
+
34
+ it ( 'should convert string to native type' , function ( ) {
35
+
36
+ assert . strictEqual ( utils . toNative ( '1' ) , 1 )
37
+ assert . strictEqual ( utils . toNative ( 'true' ) , true )
38
+
39
+ assert . strictEqual ( utils . toNative ( 'string' ) , 'string' )
40
+ assert . strictEqual ( utils . toNative ( 1 ) , 1 )
41
+ assert . strictEqual ( utils . toNative ( true ) , true )
42
+
43
+ } )
44
+
45
+ } )
31
46
} )
You can’t perform that action at this time.
0 commit comments