use protodef utils, fix #295

This commit is contained in:
Romain Beaumont 2015-11-09 15:40:04 +01:00
parent 3007740135
commit d86a59c393
4 changed files with 2 additions and 47 deletions

View file

@ -1,5 +1,3 @@
var utils = require("./utils");
module.exports = {
Client: require('./client'),
supportedVersions:require("./version").supportedVersions

View file

@ -1,7 +1,6 @@
var Client = require('./client');
var Server = require('./server');
var serializer = require("./transforms/serializer");
var utils = require("./utils");
var createClient = require("./createClient");
var createServer = require("./createServer");

View file

@ -1,42 +0,0 @@
module.exports = {
getField: getField,
getFieldInfo: getFieldInfo,
addErrorField: addErrorField,
tryCatch: tryCatch,
};
function getField(countField, context) {
var countFieldArr = countField.split("/");
var i = 0;
if (countFieldArr[i] === "") {
while (context.hasOwnProperty(".."))
context = context[".."];
i++;
}
for(; i < countFieldArr.length; i++) {
context = context[countFieldArr[i]];
}
return context;
}
function getFieldInfo(fieldInfo) {
if (typeof fieldInfo === "string")
return { type: fieldInfo };
else if (Array.isArray(fieldInfo))
return { type: fieldInfo[0], typeArgs: fieldInfo[1] };
else if (typeof fieldInfo.type === "string")
return fieldInfo;
else
throw new Error("Not a fieldinfo");
}
function addErrorField(e, field) {
if (e.field)
e.field = field + "." + e.field;
else
e.field = field;
}
function tryCatch(tryfn, catchfn) {
try { tryfn(); } catch (e) { catchfn(e); }
}

View file

@ -4,8 +4,8 @@ var Client = mc.Client;
var Server = mc.Server;
var net = require('net');
var assert = require('power-assert');
var getFieldInfo = require('../dist/utils').getFieldInfo;
var getField = require('../dist/utils').getField;
var getFieldInfo = require('protodef').utils.getFieldInfo;
var getField = require('protodef').utils.getField;
function evalCount(count, fields) {
if(fields[count["field"]] in count["map"])