@colyseus/schema
Advanced tools
Comparing version 0.4.11 to 0.4.12
@@ -47,3 +47,3 @@ "use strict"; | ||
case "string": | ||
encode.assertType(value, "string"); | ||
encode.assertType(value, "string", true); | ||
break; | ||
@@ -50,0 +50,0 @@ } |
@@ -24,3 +24,3 @@ /** | ||
export declare function utf8Write(view: any, offset: any, str: any): void; | ||
export declare function assertType(value: any, type: any): void; | ||
export declare function assertType(value: any, type: string, allowNull?: boolean): void; | ||
export declare function int8(bytes: any, value: any): void; | ||
@@ -27,0 +27,0 @@ export declare function uint8(bytes: any, value: any): void; |
@@ -45,9 +45,3 @@ "use strict"; | ||
function EncodeSchemaError() { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var _this = _super.apply(this, args) || this; | ||
Error.captureStackTrace(_this, EncodeSchemaError); | ||
return _this; | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
@@ -103,4 +97,5 @@ return EncodeSchemaError; | ||
exports.utf8Write = utf8Write; | ||
function assertType(value, type) { | ||
if (typeof (value) !== type) { | ||
function assertType(value, type, allowNull) { | ||
if (allowNull === void 0) { allowNull = false; } | ||
if (typeof (value) !== type && (!allowNull || (allowNull && value !== null))) { | ||
throw new EncodeSchemaError("a '" + type + "' was expected, but a '" + JSON.stringify(value) + "' was provided."); | ||
@@ -107,0 +102,0 @@ } |
{ | ||
"name": "@colyseus/schema", | ||
"version": "0.4.11", | ||
"version": "0.4.12", | ||
"description": "Schema-based binary serializer / de-serializer.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
88935
2133