semlog 0.6.9 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -11,8 +11,8 @@
11
11
  // Requirements //
12
12
  //////////////////////////////////////////
13
13
 
14
- var chalk = require('chalk');
15
- var prettyjson = require('prettyjson');
14
+ const chalk = require('chalk');
15
+ const prettyjson = require('prettyjson');
16
16
 
17
17
  //////////////////////////////////////////
18
18
  // Variables //
@@ -30,14 +30,14 @@ if (!global.githubFannonSemlog) {
30
30
  printDateTime: false,
31
31
  printDebug: true,
32
32
  printVerbose: true,
33
- historySize: 2048 // 0 for none
33
+ historySize: 2048, // 0 for none
34
34
  },
35
35
  statistics: {
36
36
  debug: 0,
37
37
  warning: 0,
38
38
  error: 0,
39
- total: 0
40
- }
39
+ total: 0,
40
+ },
41
41
  };
42
42
  }
43
43
 
@@ -56,7 +56,7 @@ exports.chalk = chalk;
56
56
  * @param {string|object} msg Message String or Object
57
57
  * @param {boolean} [silent] Dot not print message to the console, but stores it to the log history.
58
58
  */
59
- exports.log = function(obj, silent) {
59
+ exports.log = function (obj, silent) {
60
60
  if (obj && obj instanceof Error) {
61
61
  exports.error(obj, silent);
62
62
  } else if (obj && typeof obj === 'object') {
@@ -66,8 +66,7 @@ exports.log = function(obj, silent) {
66
66
  }
67
67
  };
68
68
 
69
- exports.message = function(msg, silent) {
70
-
69
+ exports.message = function (msg, silent) {
71
70
  global.githubFannonSemlog.statistics.total += 1;
72
71
  if (msg && msg.indexOf && (msg.indexOf('[V]') >= 0 || msg.indexOf('[D]') >= 0)) {
73
72
  global.githubFannonSemlog.statistics.debug += 1;
@@ -77,13 +76,13 @@ exports.message = function(msg, silent) {
77
76
  global.githubFannonSemlog.statistics.error += 1;
78
77
  }
79
78
 
80
- var config = global.githubFannonSemlog.config;
79
+ const config = global.githubFannonSemlog.config;
81
80
  silent = silent || config.silent;
82
81
 
83
82
  if (typeof msg !== 'string') {
84
83
  try {
85
84
  msg = '' + JSON.stringify(msg);
86
- } catch (e) {
85
+ } catch {
87
86
  msg = '[E] [SEMLOG] Could not stringify given parameter';
88
87
  }
89
88
  }
@@ -91,12 +90,11 @@ exports.message = function(msg, silent) {
91
90
  exports.addToHistory(msg);
92
91
 
93
92
  if (!silent) {
94
-
95
93
  if (config.colorize) {
96
94
  msg = exports.colorize(msg);
97
95
  }
98
96
 
99
- if ((config.printTime || config.printDateTime) && msg.trim && msg.trim().length > 0) {
97
+ if ((config.printTime || config.printDateTime) && msg.trim().length > 0) {
100
98
  if (config.printDateTime) {
101
99
  msg = chalk.gray('[' + exports.humanDate() + '] ') + msg;
102
100
  } else {
@@ -104,11 +102,9 @@ exports.message = function(msg, silent) {
104
102
  }
105
103
  }
106
104
 
107
- if (!config.printVerbose && msg.indexOf('[V]') >= 0) {
108
- // Supressing output of verbose message
109
- } else if (!config.printDebug && msg.indexOf('[D]') >= 0) {
110
- // Supressing output of debug message
111
- } else {
105
+ const suppress =
106
+ (!config.printVerbose && msg.indexOf('[V]') >= 0) || (!config.printDebug && msg.indexOf('[D]') >= 0);
107
+ if (!suppress) {
112
108
  console.log(msg);
113
109
  }
114
110
  }
@@ -119,32 +115,30 @@ exports.message = function(msg, silent) {
119
115
  *
120
116
  * @param {object} obj Object
121
117
  */
122
- exports.debug = function(obj, silent) {
123
-
118
+ exports.debug = function (obj, silent) {
124
119
  global.githubFannonSemlog.statistics.total += 1;
125
120
 
126
- var config = global.githubFannonSemlog.config;
121
+ const config = global.githubFannonSemlog.config;
127
122
  silent = silent || config.silent;
128
123
  exports.addToHistory(obj);
129
124
 
130
125
  if (!silent) {
131
126
  if (global.githubFannonSemlog.config.printYaml) {
132
127
  // Print YAML
133
- var options = {
128
+ const options = {
134
129
  keysColor: 'white',
135
130
  dashColor: 'white',
136
131
  stringColor: 'yellow',
137
- numberColor: 'blue'
132
+ numberColor: 'blue',
138
133
  };
139
134
 
140
135
  if (!global.githubFannonSemlog.config.colorize) {
141
136
  options.noColor = true;
142
137
  }
143
138
  console.log(chalk.gray('---\n') + prettyjson.render(obj, options));
144
-
145
139
  } else {
146
140
  // Print indented JSON
147
- var msg = JSON.stringify(obj, false, 4);
141
+ const msg = JSON.stringify(obj, false, 4);
148
142
  console.log(chalk.gray(msg));
149
143
  }
150
144
  }
@@ -155,12 +149,11 @@ exports.debug = function(obj, silent) {
155
149
  *
156
150
  * @param {object} obj Object
157
151
  */
158
- exports.error = function(obj, silent) {
159
-
152
+ exports.error = function (obj, silent) {
160
153
  global.githubFannonSemlog.statistics.total += 1;
161
154
  global.githubFannonSemlog.statistics.error += 1;
162
155
 
163
- var config = global.githubFannonSemlog.config;
156
+ const config = global.githubFannonSemlog.config;
164
157
  silent = silent || config.silent;
165
158
  exports.addToHistory(obj);
166
159
 
@@ -173,11 +166,9 @@ exports.error = function(obj, silent) {
173
166
  }
174
167
  };
175
168
 
176
-
177
- exports.addToHistory = function(obj) {
178
-
179
- var config = global.githubFannonSemlog.config;
180
- var msg = '';
169
+ exports.addToHistory = function (obj) {
170
+ const config = global.githubFannonSemlog.config;
171
+ let msg;
181
172
 
182
173
  try {
183
174
  msg = JSON.stringify(obj, null, 4);
@@ -190,8 +181,7 @@ exports.addToHistory = function(obj) {
190
181
  if (config.logDateTime) {
191
182
  msg = '[' + exports.humanDate() + '] ' + msg;
192
183
  }
193
-
194
- } catch (e) {
184
+ } catch {
195
185
  msg = '[W] Internal semlog error: Could not push circular/invalid object into the history';
196
186
  }
197
187
 
@@ -205,28 +195,26 @@ exports.addToHistory = function(obj) {
205
195
  * @param {string} msg
206
196
  * @returns {string}
207
197
  */
208
- exports.colorize = function(msg) {
209
-
210
- var colorMap = {
211
- '[E]': 'red', // ERROR
212
- '[W]': 'yellow', // WARNING
213
- '[?]': 'yellow', // MISSING
214
- '[S]': 'green', // SUCCESS
215
- '[i]': 'blue', // INFO
216
- '[+]': 'green', // ADDED
217
- '[-]': 'red', // REMOVED
218
- '[C]': 'cyan', // CHANGED
219
- '[U]': 'grey', // UNCHANGED
220
- '[=]': 'grey', // EQUAL
221
- '[/]': 'grey', // SKIPPED
222
- '[V]': 'magenta', // VERBOSE
223
- '[D]': 'magenta', // DEBUG
224
- '[T]': 'magenta', // TO-DO
225
- '[TODO]': 'magenta' // TO-DO
198
+ exports.colorize = function (msg) {
199
+ const colorMap = {
200
+ '[E]': 'red', // ERROR
201
+ '[W]': 'yellow', // WARNING
202
+ '[?]': 'yellow', // MISSING
203
+ '[S]': 'green', // SUCCESS
204
+ '[i]': 'blue', // INFO
205
+ '[+]': 'green', // ADDED
206
+ '[-]': 'red', // REMOVED
207
+ '[C]': 'cyan', // CHANGED
208
+ '[U]': 'grey', // UNCHANGED
209
+ '[=]': 'grey', // EQUAL
210
+ '[/]': 'grey', // SKIPPED
211
+ '[V]': 'magenta', // VERBOSE
212
+ '[D]': 'magenta', // DEBUG
213
+ '[T]': 'magenta', // TO-DO
214
+ '[TODO]': 'magenta', // TO-DO
226
215
  };
227
216
 
228
- for (var searchString in colorMap) {
229
- var color = colorMap[searchString];
217
+ for (const [searchString, color] of Object.entries(colorMap)) {
230
218
  if (msg && msg.indexOf && msg.indexOf(searchString) > -1) {
231
219
  return chalk[color](msg);
232
220
  }
@@ -235,7 +223,6 @@ exports.colorize = function(msg) {
235
223
  return msg;
236
224
  };
237
225
 
238
-
239
226
  //////////////////////////////////////////
240
227
  // LOGGER FUNCTIONS //
241
228
  //////////////////////////////////////////
@@ -243,15 +230,14 @@ exports.colorize = function(msg) {
243
230
  /**
244
231
  * Gets the current config
245
232
  */
246
- exports.getConfig = function() {
233
+ exports.getConfig = function () {
247
234
  return global.githubFannonSemlog.config;
248
235
  };
249
236
 
250
-
251
237
  /**
252
238
  * Gets the current config
253
239
  */
254
- exports.getStatistics = function() {
240
+ exports.getStatistics = function () {
255
241
  return global.githubFannonSemlog.statistics;
256
242
  };
257
243
 
@@ -261,24 +247,21 @@ exports.getStatistics = function() {
261
247
  *
262
248
  * @param {object} config
263
249
  */
264
- exports.updateConfig = function(config) {
265
- for (var key in config) {
266
- var value = config[key];
267
- global.githubFannonSemlog.config[key] = value;
268
- }
250
+ exports.updateConfig = function (config) {
251
+ Object.assign(global.githubFannonSemlog.config, config);
269
252
  return global.githubFannonSemlog.config;
270
253
  };
271
254
 
272
255
  /**
273
256
  * Clears (empties) the log object
274
257
  */
275
- exports.clearLogHistory = function() {
258
+ exports.clearLogHistory = function () {
276
259
  global.githubFannonSemlog.history = [];
277
260
  global.githubFannonSemlog.statistics = {
278
261
  debug: 0,
279
262
  warning: 0,
280
263
  error: 0,
281
- total: 0
264
+ total: 0,
282
265
  };
283
266
  };
284
267
 
@@ -287,11 +270,10 @@ exports.clearLogHistory = function() {
287
270
  *
288
271
  * @returns {Array}
289
272
  */
290
- exports.getLogHistory = function() {
273
+ exports.getLogHistory = function () {
291
274
  return global.githubFannonSemlog.history;
292
275
  };
293
276
 
294
-
295
277
  //////////////////////////////////////////
296
278
  // HELPER UTILITIES //
297
279
  //////////////////////////////////////////
@@ -303,7 +285,7 @@ exports.getLogHistory = function() {
303
285
  * @param {number} digits number of total digits
304
286
  * @returns {string}
305
287
  */
306
- exports.pad = function(number, digits) {
288
+ exports.pad = function (number, digits) {
307
289
  return new Array(Math.max(digits - String(number).length + 1, 0)).join(0) + number;
308
290
  };
309
291
 
@@ -315,7 +297,7 @@ exports.pad = function(number, digits) {
315
297
  * @param number
316
298
  * @returns {string}
317
299
  */
318
- exports.prettyNumber = function(number) {
300
+ exports.prettyNumber = function (number) {
319
301
  return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, '.');
320
302
  };
321
303
 
@@ -328,12 +310,11 @@ exports.prettyNumber = function(number) {
328
310
 
329
311
  * @returns {String}
330
312
  */
331
- exports.cleanUrl = function(url) {
313
+ exports.cleanUrl = function (url) {
332
314
  url = url.trim();
333
315
  return url.replace(/^\/|\/$/g, '');
334
316
  };
335
317
 
336
-
337
318
  /**
338
319
  * Strips trailing slashes from URL
339
320
  *
@@ -342,7 +323,7 @@ exports.cleanUrl = function(url) {
342
323
  * @param {String} url URL to cleanup
343
324
  * @returns {String}
344
325
  */
345
- exports.stripTrailingSlash = function(url) {
326
+ exports.stripTrailingSlash = function (url) {
346
327
  if (url.substr(-1) === '/') {
347
328
  url = url.substr(0, url.length - 1);
348
329
  }
@@ -354,9 +335,8 @@ exports.stripTrailingSlash = function(url) {
354
335
  *
355
336
  * @see http://stackoverflow.com/a/23329386
356
337
  */
357
- exports.byteSize = function(obj) {
358
-
359
- var str = '';
338
+ exports.byteSize = function (obj) {
339
+ let str;
360
340
 
361
341
  if (typeof obj === 'object') {
362
342
  str = JSON.stringify(obj);
@@ -364,15 +344,15 @@ exports.byteSize = function(obj) {
364
344
  str = obj.toString();
365
345
  }
366
346
 
367
- var s = str.length;
368
- for (var i = str.length - 1; i >= 0; i--) {
369
- var code = str.charCodeAt(i);
347
+ let s = str.length;
348
+ for (let i = str.length - 1; i >= 0; i--) {
349
+ const code = str.charCodeAt(i);
370
350
  if (code > 0x7f && code <= 0x7ff) {
371
351
  s++;
372
352
  } else if (code > 0x7ff && code <= 0xffff) {
373
353
  s += 2;
374
354
  }
375
- if (code >= 0xDC00 && code <= 0xDFFF) {
355
+ if (code >= 0xdc00 && code <= 0xdfff) {
376
356
  i--;
377
357
  } //trail surrogate
378
358
  }
@@ -387,13 +367,15 @@ exports.byteSize = function(obj) {
387
367
  *
388
368
  * @see http://stackoverflow.com/a/14919494
389
369
  */
390
- exports.prettyBytes = function(bytes, si) {
391
- var thresh = si ? 1000 : 1024;
370
+ exports.prettyBytes = function (bytes, si) {
371
+ const thresh = si ? 1000 : 1024;
392
372
  if (bytes < thresh) {
393
373
  return bytes + ' B';
394
374
  }
395
- var units = si ? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] : ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
396
- var u = -1;
375
+ const units = si
376
+ ? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
377
+ : ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
378
+ let u = -1;
397
379
  do {
398
380
  bytes /= thresh;
399
381
  ++u;
@@ -408,7 +390,7 @@ exports.prettyBytes = function(bytes, si) {
408
390
  * @param {Date=} date Optional date object. If falsy, will take current time.
409
391
  * @returns {Array}
410
392
  */
411
- exports.getDateArray = function(date) {
393
+ exports.getDateArray = function (date) {
412
394
  date = date || new Date();
413
395
  return [
414
396
  date.getFullYear(),
@@ -417,7 +399,7 @@ exports.getDateArray = function(date) {
417
399
  exports.pad(date.getHours(), 2),
418
400
  exports.pad(date.getMinutes(), 2),
419
401
  exports.pad(date.getSeconds(), 2),
420
- exports.pad(date.getMilliseconds(), 2)
402
+ exports.pad(date.getMilliseconds(), 3),
421
403
  ];
422
404
  };
423
405
 
@@ -428,9 +410,9 @@ exports.getDateArray = function(date) {
428
410
  * @param {object} [date]
429
411
  * @returns {string}
430
412
  */
431
- exports.humanDate = function(date) {
413
+ exports.humanDate = function (date) {
432
414
  date = date || new Date();
433
- var d = exports.getDateArray(date);
415
+ const d = exports.getDateArray(date);
434
416
  return d[0] + '-' + d[1] + '-' + d[2] + ' ' + d[3] + ':' + d[4] + ':' + d[5];
435
417
  };
436
418
 
@@ -441,9 +423,9 @@ exports.humanDate = function(date) {
441
423
  * @param {object} [date]
442
424
  * @returns {string}
443
425
  */
444
- exports.roboDate = function(date) {
426
+ exports.roboDate = function (date) {
445
427
  date = date || new Date();
446
- var d = exports.getDateArray(date);
428
+ const d = exports.getDateArray(date);
447
429
  return d[0] + '-' + d[1] + '-' + d[2] + '_' + d[3] + '-' + d[4] + '-' + d[5];
448
430
  };
449
431
 
@@ -454,9 +436,9 @@ exports.roboDate = function(date) {
454
436
  * @param {object} [date]
455
437
  * @returns {string}
456
438
  */
457
- exports.humanTime = function(date) {
439
+ exports.humanTime = function (date) {
458
440
  date = date || new Date();
459
- var d = exports.getDateArray(date);
441
+ const d = exports.getDateArray(date);
460
442
  return d[3] + ':' + d[4] + ':' + d[5];
461
443
  };
462
444
 
@@ -467,9 +449,8 @@ exports.humanTime = function(date) {
467
449
  * @param {object} [date]
468
450
  * @returns {string}
469
451
  */
470
- exports.roboTime = function(date) {
452
+ exports.roboTime = function (date) {
471
453
  date = date || new Date();
472
- var d = exports.getDateArray(date);
454
+ const d = exports.getDateArray(date);
473
455
  return d[3] + '-' + d[4] + '-' + d[5];
474
456
  };
475
-
package/package.json CHANGED
@@ -1,16 +1,32 @@
1
1
  {
2
2
  "name": "semlog",
3
- "version": "0.6.9",
3
+ "version": "0.7.0",
4
4
  "description": "A semantic logger module, that colors and formats automatically depending on the content",
5
- "homepage": "https://github.com/Fannon/semlog",
5
+ "homepage": "https://github.com/gesinn-it-pub/semlog",
6
6
  "author": {
7
7
  "name": "Simon Heimler",
8
8
  "email": "heimlersimon@gmail.com",
9
9
  "url": "http://www.fannon.de"
10
10
  },
11
- "repository": "Fannon/semlog",
11
+ "contributors": [
12
+ {
13
+ "name": "gesinn.it GmbH & Co. KG",
14
+ "email": "github@gesinn.it",
15
+ "url": "https://gesinn.it"
16
+ }
17
+ ],
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/gesinn-it-pub/semlog.git"
21
+ },
22
+ "publishConfig": {
23
+ "registry": "https://registry.npmjs.org/"
24
+ },
12
25
  "license": "MIT",
13
26
  "main": "index.js",
27
+ "engines": {
28
+ "node": ">=20.0.0"
29
+ },
14
30
  "keywords": [
15
31
  "semlog",
16
32
  "log",
@@ -19,26 +35,37 @@
19
35
  "colors"
20
36
  ],
21
37
  "dependencies": {
22
- "chalk": "^1.1.3",
23
- "prettyjson": "^1.1.3"
38
+ "chalk": "^4.1.2",
39
+ "prettyjson": "^1.2.1"
24
40
  },
25
41
  "devDependencies": {
26
- "chai": "^3.5.0",
27
- "codeclimate-test-reporter": "0.3.1",
28
- "grunt": "^1.0.1",
29
- "grunt-cli": "^1.2.0",
30
- "grunt-documentation": "^1.1.2",
31
- "grunt-eslint": "^18.0.0",
32
- "grunt-jscs": "^2.8.0",
33
- "grunt-mocha-cli": "^2.0.0",
34
- "grunt-mocha-istanbul": "^3.0.1",
35
- "grunt-release": "^0.13.0",
36
- "istanbul": "^0.4.3",
37
- "load-grunt-tasks": "^3.4.1",
38
- "mocha": "^2.4.5",
39
- "time-grunt": "^1.3.0"
42
+ "@eslint/js": "^10.0.0",
43
+ "c8": "^11.0.0",
44
+ "chai": "^4.3.7",
45
+ "eslint": "^10.0.0",
46
+ "eslint-config-prettier": "^10.0.0",
47
+ "globals": "^17.0.0",
48
+ "mocha": "^11.0.0",
49
+ "prettier": "^3.0.0"
40
50
  },
41
51
  "scripts": {
42
- "test": "grunt"
52
+ "lint": "eslint index.js test/",
53
+ "format:check": "prettier --check index.js test/",
54
+ "test": "mocha 'test/**/*.spec.js'",
55
+ "test:coverage": "c8 mocha 'test/**/*.spec.js'"
56
+ },
57
+ "mocha": {
58
+ "timeout": 16000,
59
+ "reporter": "spec"
60
+ },
61
+ "c8": {
62
+ "reporter": [
63
+ "lcov",
64
+ "text",
65
+ "clover"
66
+ ],
67
+ "include": [
68
+ "index.js"
69
+ ]
43
70
  }
44
71
  }