mirror of
https://github.com/typicode/json-server.git
synced 2025-07-29 13:14:12 +08:00
Refactor CLI and add tests
This commit is contained in:
22
src/server/utils.js
Normal file
22
src/server/utils.js
Normal file
@ -0,0 +1,22 @@
|
||||
module.exports = {
|
||||
toNative: toNative
|
||||
}
|
||||
|
||||
// Turns string to native.
|
||||
// Example:
|
||||
// 'true' -> true
|
||||
// '1' -> 1
|
||||
function toNative (value) {
|
||||
if (typeof value === 'string') {
|
||||
if (value === ''
|
||||
|| value.trim() !== value
|
||||
|| (value.length > 1 && value[0] === '0')) {
|
||||
return value
|
||||
} else if (value === 'true' || value === 'false') {
|
||||
return value === 'true'
|
||||
} else if (!isNaN(+value)) {
|
||||
return +value
|
||||
}
|
||||
}
|
||||
return value
|
||||
}
|
Reference in New Issue
Block a user