source: trip-planner-front/node_modules/resolve-url-loader/lib/log-to-test-harness.js@ 1ad8e64

Last change on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 779 bytes
Line 
1/*
2 * MIT License http://opensource.org/licenses/MIT
3 * Author: Ben Holloway @bholloway
4 */
5'use strict';
6
7var stream = require('stream');
8
9var hasLogged = false;
10
11function logToTestHarness(maybeStream, options) {
12 var doLogging =
13 !hasLogged &&
14 !!maybeStream &&
15 (typeof maybeStream === 'object') &&
16 (maybeStream instanceof stream.Writable);
17
18 if (doLogging) {
19 hasLogged = true; // ensure we log only once
20 Object.keys(options).forEach(eachOptionKey);
21 }
22
23 function eachOptionKey(key) {
24 maybeStream.write(key + ': ' + stringify(options[key]) + '\n');
25 }
26
27 function stringify(value) {
28 try {
29 return JSON.stringify(value) || String(value);
30 } catch (e) {
31 return '-unstringifyable-';
32 }
33 }
34}
35
36module.exports = logToTestHarness;
Note: See TracBrowser for help on using the repository browser.