domotz-remote-pawn
Version:
Domotz Agent
66 lines (61 loc) • 1.91 kB
JavaScript
/** This file is part of Domotz Agent.
* Copyright (C) 2016 Domotz UK LLP
*
* Domotz Agent is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Domotz Agent is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Domotz Agent. If not, see <http://www.gnu.org/licenses/>.
**/
/**
*
* Created by Iacopo Papalini <iacopo@domotz.com> on 11/04/16.
*/
module.exports.transformer = function (value) {
"use strict";
return {
'string': function (o) {
return '' + o;
},
'mac': function (o) {
var byteList = [];
for (var i = 0; i < o.length; i++) {
var tmpByte = o.readUInt8(i);
var tmpStr = tmpByte.toString(16);
if (tmpStr.length < 2) {
tmpStr = '0' + tmpStr;
}
byteList.push(tmpStr);
}
return byteList.join(':').toUpperCase();
},
'int': function (o) {
return o;
}
}[value];
};
module.exports.extractOids = function(oids_mapping) {
"use strict";
var oids = [];
for (var oid in oids_mapping) {
if (oids_mapping.hasOwnProperty(oid)) {
oids.push(oid);
}
}
return oids;
};
module.exports.isEmpty = function(obj) {
for(var prop in obj) {
if(obj.hasOwnProperty(prop)) {
return false;
}
}
return JSON.stringify(obj) === JSON.stringify({});
};