Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function testEJSON(t, patch, expected, recursive = true) {
const string_djson = DJSON.stringify(patch)
const string_ejson = EJSON.stringify(patch)
const parsed_json_djson = JSON.parse(string_djson)
const parsed_json_ejson = JSON.parse(string_ejson)
t.deepEqual(parsed_json_djson, expected)
t.deepEqual(parsed_json_djson, parsed_json_ejson)
if (recursive) {
testEJSON(t, DJSON.parse(string_djson), expected, false)
// testEJSON(t, EJSON.parse(string_ejson), expected, false)
}
}
var stringForErrorMessage = function (value, options) {
options = options || {};
if ( value === null ) return "null";
if ( options.onlyShowType ) {
return typeof value;
}
// Your average non-object things. Saves from doing the try/catch below for.
if ( typeof value !== "object" ) {
return EJSON.stringify(value)
}
try {
// Find objects with circular references since EJSON doesn't support them yet (Issue #4778 + Unaccepted PR)
// If the native stringify is going to choke, EJSON.stringify is going to choke too.
JSON.stringify(value);
} catch (stringifyError) {
if ( stringifyError.name === "TypeError" ) {
return typeof value;
}
}
return EJSON.stringify(value);
};
exports.encoder = function encoder(data, fn) {
var err;
try { data = EJSON.stringify(data); }
catch (e) { err = e; }
fn(err, data);
};
Device.prototype.sendState = function(state, time, callback) {
if(typeof(time) === 'function') {
callback = time;
time = null;
}
time = time || new Date();
var payload = { time: time, data: state };
debug('Publishing state:');
debug(EJSON.stringify(payload));
debug('Topic: ' + this.stateTopic);
this.mqtt.publish(this.stateTopic, EJSON.stringify(payload), callback);
return { topic: this.stateTopic, payload: payload };
};
const stringify = function(value) {
if (value === undefined) return 'undefined';
return EJSON.stringify(value);
};
let responseUpdate = {
msg: 'updated',
id,
};
switch (method) {
case 'login':
response.result = 'mock_session_id';
break;
default:
break;
}
server.send(EJSON.stringify(response));
server.send(EJSON.stringify(responseUpdate));
}
publicationName: string,
id: number,
params: any,
) {
const response = {
id: `test_${publicationName}`,
msg: 'added',
collection: publicationName,
fields: {
_id: `test_${publicationName}`,
full_name: 'Test',
email: 'test@test.com',
},
};
server.send(EJSON.stringify(response));
}
}
exportData(format) {
if (format === undefined || format == 'string') {
return EJSON.stringify(this.collections);
} else if (format == 'raw') {
return fullCopy(this.collections);
}
}