iotagent-node-lib
Version:
IoT Agent library to interface with NGSI Context Broker
66 lines (56 loc) • 1.92 kB
JavaScript
/*
* Copyright 2013 Telefonica Investigación y Desarrollo, S.A.U
*
* This file is part of fiware-orion-pep
*
* fiware-orion-pep is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* fiware-orion-pep 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with fiware-orion-pep.
* If not, see http://www.gnu.org/licenses/.
*
* For those usages not covered by the GNU Affero General Public License
* please contact with::[daniel.moranjimenez@telefonica.com]
*/
const fs = require('fs');
const request = require('../../lib/fiware-iotagent-lib').request;
function readExampleFile(name, raw) {
let text = null;
try {
text = fs.readFileSync(name, 'UTF8');
} catch (e) {
/* eslint-disable no-console */
console.error(JSON.stringify(e));
}
return raw ? text : JSON.parse(text);
}
function deepEqual(objA, objB) {
if (objA === objB) {
return true;
}
if (typeof objA !== 'object' || typeof objB !== 'object' || objA === null || objB === null) {
return false;
}
const keysA = Object.keys(objA);
const keysB = Object.keys(objB);
if (keysA.length !== keysB.length) {
return false;
}
for (const key of keysA) {
if (!keysB.includes(key) || !deepEqual(objA[key], objB[key])) {
return false;
}
}
return true;
}
exports.readExampleFile = readExampleFile;
exports.deepEqual = deepEqual;
exports.request = request;