Strings accept numbers too

This commit is contained in:
Ben Ogle
2014-09-25 17:24:58 -07:00
parent 2c1fa19e27
commit ef19e925e9
2 changed files with 21 additions and 8 deletions

View File

@@ -390,7 +390,8 @@ class Config
# This value is stored in Atom's internal configuration file.
#
# * `keyPath` The {String} name of the key.
# * `value` The value of the setting.
# * `value` The value of the setting. Passing `undefined` will revert the
# setting to the default value.
#
# Returns a {Boolean}
# * `true` if the value was set.
@@ -672,8 +673,11 @@ Config.addSchemaValidators
'string':
coercion: (keyPath, value, schema) ->
throw new Error("Validation failed at #{keyPath}, #{JSON.stringify(value)} must be a string") if typeof value isnt 'string'
value
switch typeof value
when 'number', 'string'
value.toString()
else
throw new Error("Validation failed at #{keyPath}, #{JSON.stringify(value)} must be a string or number")
'null':
# null sort of isnt supported. It will just unset in this case