mirror of
https://github.com/typicode/json-server.git
synced 2025-07-28 12:43:18 +08:00
Fix empty string conversion
This commit is contained in:
@ -8,7 +8,9 @@ _.mixin(_inflections)
|
||||
// '1' -> 1
|
||||
function toNative(value) {
|
||||
if (typeof value === 'string') {
|
||||
if (value === 'true' || value === 'false') {
|
||||
if (value === '') {
|
||||
return value
|
||||
} else if (value === 'true' || value === 'false') {
|
||||
return value === 'true'
|
||||
} else if (!isNaN(+value)) {
|
||||
return +value
|
||||
|
@ -32,14 +32,14 @@ describe('utils', function() {
|
||||
describe('toNative', function() {
|
||||
|
||||
it('should convert string to native type', function() {
|
||||
|
||||
// should convert
|
||||
assert.strictEqual(utils.toNative('1'), 1)
|
||||
assert.strictEqual(utils.toNative('true'), true)
|
||||
|
||||
// should not convert
|
||||
assert.strictEqual(utils.toNative(''), '')
|
||||
assert.strictEqual(utils.toNative('string'), 'string')
|
||||
assert.strictEqual(utils.toNative(1), 1)
|
||||
assert.strictEqual(utils.toNative(true), true)
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
Reference in New Issue
Block a user