archetype-js
Advanced tools
Comparing version 0.1.4 to 0.1.5
exports.Any = require('./src').Any; | ||
exports.Schema = require('./src').Schema; | ||
exports.to = require('./src/unmarshal/util').handleCast; | ||
exports.to = require('./src/unmarshal/util').to; |
{ | ||
"name": "archetype-js", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"author": "Valeri Karpov <val@boosterfuels.com>", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -15,11 +15,15 @@ 'use strict'; | ||
exports.handleCast = function(obj, key, type) { | ||
exports.to = function(v, type) { | ||
if (SPECIAL_CASES.has(type)) { | ||
obj[key] = SPECIAL_CASES.get(type)(obj[key]); | ||
return; | ||
return SPECIAL_CASES.get(type)(v); | ||
} | ||
if (!(obj[key] instanceof type)) { | ||
obj[key] = new type(obj[key]); | ||
if (!(v instanceof type)) { | ||
return new type(v); | ||
} | ||
return v; | ||
} | ||
exports.handleCast = function(obj, key, type) { | ||
obj[key] = exports.to(obj[key], type); | ||
}; | ||
@@ -26,0 +30,0 @@ |
30066
631