Skip to content

Commit

Permalink
Fix #25
Browse files Browse the repository at this point in the history
  • Loading branch information
typicode committed Sep 17, 2014
1 parent a76ca91 commit 053484d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ _.mixin(require('underscore.inflections'))
// 'true' -> true
// '1' -> 1
function toNative(value) {
if (value === 'true' || value === 'false') {
return value === 'true'
} else if (!isNaN(+value)) {
return +value
} else {
return value
if (typeof value === 'string') {
if (value === 'true' || value === 'false') {
return value === 'true'
} else if (!isNaN(+value)) {
return +value
}
}
return value
}

// Creates incremental id.
Expand Down
15 changes: 15 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,19 @@ describe('utils', function() {

})
})

describe('toNative', function() {

it('should convert string to native type', function() {

assert.strictEqual(utils.toNative('1'), 1)
assert.strictEqual(utils.toNative('true'), true)

assert.strictEqual(utils.toNative('string'), 'string')
assert.strictEqual(utils.toNative(1), 1)
assert.strictEqual(utils.toNative(true), true)

})

})
})

0 comments on commit 053484d

Please sign in to comment.