mirror of
https://github.com/typicode/json-server.git
synced 2025-07-28 04:32:24 +08:00
Fix type conversion
This commit is contained in:
@ -8,7 +8,7 @@ _.mixin(_inflections)
|
||||
// '1' -> 1
|
||||
function toNative(value) {
|
||||
if (typeof value === 'string') {
|
||||
if (value === '') {
|
||||
if (value === '' || value.trim() !== value) {
|
||||
return value
|
||||
} else if (value === 'true' || value === 'false') {
|
||||
return value === 'true'
|
||||
|
@ -37,6 +37,9 @@ describe('utils', function() {
|
||||
assert.strictEqual(utils.toNative('true'), true)
|
||||
// should not convert
|
||||
assert.strictEqual(utils.toNative(''), '')
|
||||
assert.strictEqual(utils.toNative('\t\n'), '\t\n')
|
||||
assert.strictEqual(utils.toNative('1 '), '1 ')
|
||||
assert.strictEqual(utils.toNative(' 1'), ' 1')
|
||||
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