Skip to content

Commit 053484d

Browse files
committed
Fix #25
1 parent a76ca91 commit 053484d

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/utils.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ _.mixin(require('underscore.inflections'))
88
// 'true' -> true
99
// '1' -> 1
1010
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+
}
1717
}
18+
return value
1819
}
1920

2021
// Creates incremental id.

test/utils.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,19 @@ describe('utils', function() {
2828

2929
})
3030
})
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+
})
3146
})

0 commit comments

Comments
 (0)