mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Handle minimum and maximum keywords on number types
This commit is contained in:
@@ -404,12 +404,26 @@ Config.addTypeFilters
|
||||
throw new Error() if isNaN(value)
|
||||
value
|
||||
|
||||
minMaxCoercion: (value, schema) ->
|
||||
if schema.minimum? and typeof schema.minimum is 'number'
|
||||
value = Math.max(value, schema.minimum)
|
||||
if schema.maximum? and typeof schema.maximum is 'number'
|
||||
value = Math.min(value, schema.maximum)
|
||||
value
|
||||
|
||||
'number':
|
||||
coercion: (value, schema) ->
|
||||
value = parseFloat(value)
|
||||
throw new Error() if isNaN(value)
|
||||
value
|
||||
|
||||
minMaxCoercion: (value, schema) ->
|
||||
if schema.minimum? and typeof schema.minimum is 'number'
|
||||
value = Math.max(value, schema.minimum)
|
||||
if schema.maximum? and typeof schema.maximum is 'number'
|
||||
value = Math.min(value, schema.maximum)
|
||||
value
|
||||
|
||||
'boolean':
|
||||
coercion: (value, schema) ->
|
||||
switch typeof value
|
||||
@@ -419,7 +433,7 @@ Config.addTypeFilters
|
||||
!!value
|
||||
|
||||
'string':
|
||||
typeCheck: (value, schema) ->
|
||||
coercion: (value, schema) ->
|
||||
throw new Error() if typeof value isnt 'string'
|
||||
value
|
||||
|
||||
|
||||
Reference in New Issue
Block a user