const getDockerConfig = async () => { try { const content = await fs.readFile( getDockerSettings(), 'utf8' ); return JSON.parse( content ); } catch ( err ) { throw new Error( `Can't load Docker config, ${ err.stack }` ); } }
function findPkgJson( target ) { let root = path.dirname( target ); while ( root !== '/' ) { const filepath = path.join( root, 'package.json' ); if ( fs.existsSync( filepath ) ) { return JSON.parse( fs.readFileSync( filepath, 'utf8' ) ); } root = path.join( root, '../' ); } throw new Error( 'could not find a pkg json' ); }
resultSet.tablePivot().map((item) => { data['features'].push({ type: 'Feature', properties: { value: parseInt(item['Users.count']), }, geometry: JSON.parse(item['Users.geometry']), }); });
function readJsonSafe(file) { try { file = fs.readFileSync(file, ENCODING); file = file && JSON.parse(file); } catch(e) { file = null; } return file; }
/* * Deep clone an object. * Note: This will not clone functions and dates * @param {object} object Object to clone * @return {object} */ deepClone (object) { return JSON.parse(JSON.stringify(object)) }
handleFind(req) { const body = Object.assign(req.body, _ClassesRouter.default.JSONFromQuery(req.query)); const options = _ClassesRouter.default.optionsFromBody(body); return _rest.default.find(req.config, req.auth, '_Audience', body.where, options, req.info.clientSDK, req.info.context).then(response => { response.results.forEach(item => { item.query = JSON.parse(item.query); }); return { response: response }; }); }
it('can push error', function() { const parseWebSocket = { send: jasmine.createSpy('send'), }; Client.pushError(parseWebSocket, 1, 'error', true); const lastCall = parseWebSocket.send.calls.first(); const messageJSON = JSON.parse(lastCall.args[0]); expect(messageJSON.op).toBe('error'); expect(messageJSON.error).toBe('error'); expect(messageJSON.code).toBe(1); expect(messageJSON.reconnect).toBe(true); });
it('can push subscribe response', function() { const parseWebSocket = { send: jasmine.createSpy('send'), }; const client = new Client(1, parseWebSocket); client.pushSubscribe(2); const lastCall = parseWebSocket.send.calls.first(); const messageJSON = JSON.parse(lastCall.args[0]); expect(messageJSON.op).toBe('subscribed'); expect(messageJSON.clientId).toBe(1); expect(messageJSON.requestId).toBe(2); });
test('serializes to JSON ignoring properties', () => { profile.currentEpicScore = 'ignored'; profile.currentEpicGrades = 'ignored'; profile.directoryPath = 'ignored'; profile.tower = 'ignored'; const serializedProfile = JSON.parse(JSON.stringify(profile)); expect(serializedProfile).not.toHaveProperty('currentEpicScore'); expect(serializedProfile).not.toHaveProperty('currentEpicGrades'); expect(serializedProfile).not.toHaveProperty('directoryPath'); expect(serializedProfile).not.toHaveProperty('tower'); });
getUser() { if (this.user) { return this.user; } const data = keyValueStore.get(GATEWAY_USER_KEY); if (data) { this.user = JSON.parse(data); } return this.user; }
handleClientConnectivityStatusChange(event) { AppDispatcher.dispatchServerAction({ type: ActionTypes.CLIENT_CONNECTIVITY_STATUS_CHANGE, data: JSON.parse(event.data), }); }
it('serialized httpResponse correctly with body string', () => { const httpResponse = new HTTPResponse({}, 'hello'); expect(httpResponse.text).toBe('hello'); expect(httpResponse.data).toBe(undefined); expect(httpResponse.body).toBe('hello'); const serialized = JSON.stringify(httpResponse); const result = JSON.parse(serialized); expect(result.text).toBe('hello'); expect(result.data).toBe(undefined); expect(result.body).toBe(undefined); });
function decodeClientPayload(payload) { /* Special function which Client using to "encode" clients JSON payload */ return JSON.parse(String.fromCharCode.apply(null, payload)); }
handleTaxonomyFullUpdate(event) { AppDispatcher.dispatchServerAction({ type: ActionTypes.TAXONOMY_FULL_UPDATE, data: JSON.parse(event.data), }); }
function moduleOrObjectParser(opt) { if (typeof opt == 'object') { return opt; } try { return JSON.parse(opt); } catch (e) { /* */ } return opt; }