@tstdl/base 0.84.35 → 0.84.37

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.
@@ -42,13 +42,13 @@ var __metadata = function(k, v) {
42
42
  return Reflect.metadata(k, v);
43
43
  };
44
44
  var ConsoleLogger_1;
45
- const levelFuncMap = {
46
- [import_level.LogLevel.Error]: console.error,
47
- [import_level.LogLevel.Warn]: console.warn,
48
- [import_level.LogLevel.Info]: console.info,
49
- [import_level.LogLevel.Verbose]: console.info,
50
- [import_level.LogLevel.Debug]: console.debug,
51
- [import_level.LogLevel.Trace]: console.debug
45
+ const consoleLevelFuncMap = {
46
+ [import_level.LogLevel.Error]: "error",
47
+ [import_level.LogLevel.Warn]: "warn",
48
+ [import_level.LogLevel.Info]: "info",
49
+ [import_level.LogLevel.Verbose]: "info",
50
+ [import_level.LogLevel.Debug]: "debug",
51
+ [import_level.LogLevel.Trace]: "debug"
52
52
  };
53
53
  let ConsoleLogger = ConsoleLogger_1 = class ConsoleLogger2 extends import_logger.Logger {
54
54
  entryPrefix;
@@ -60,7 +60,7 @@ let ConsoleLogger = ConsoleLogger_1 = class ConsoleLogger2 extends import_logger
60
60
  fork(options) {
61
61
  const level = options.level ?? this.level;
62
62
  const module2 = (0, import_type_guards.isDefined)(options.subModule) ? [...this.module ?? [], options.subModule] : this.module;
63
- return new ConsoleLogger_1(level, module2, options.prefix);
63
+ return new ConsoleLogger_1(level, module2, (0, import_type_guards.isDefined)(options.subModule) ? options.prefix : options.prefix ?? this.logPrefix);
64
64
  }
65
65
  subModule(subModule) {
66
66
  return new ConsoleLogger_1(this.level, [...this.module ?? [], subModule]);
@@ -71,13 +71,18 @@ let ConsoleLogger = ConsoleLogger_1 = class ConsoleLogger2 extends import_logger
71
71
  log(level, entryOrError, errorOptions) {
72
72
  const entry = (0, import_type_guards.isString)(entryOrError) ? entryOrError : (0, import_format_error.formatError)(entryOrError, errorOptions);
73
73
  const dateString = (0, import_date_time.now)().toISOString();
74
- levelFuncMap[level](`${dateString} - ${this.entryPrefix}${entry}`);
74
+ console[consoleLevelFuncMap[level]](`${dateString} - ${this.entryPrefix}${entry}`);
75
75
  }
76
76
  };
77
77
  ConsoleLogger = ConsoleLogger_1 = __decorate([
78
78
  (0, import_container.singleton)({
79
79
  provider: {
80
- useFactory: (argument, context) => new ConsoleLogger_1(((0, import_type_guards.isObject)(argument) ? argument.level : void 0) ?? context.resolve(import_level.LogLevel), (0, import_type_guards.isObject)(argument) ? argument.module : argument, (0, import_type_guards.isObject)(argument) ? argument.prefix : void 0)
80
+ useFactory: (argument, context) => {
81
+ if ((0, import_type_guards.isObject)(argument)) {
82
+ return new ConsoleLogger_1(argument.level ?? context.resolve(import_level.LogLevel), argument.module, argument.prefix);
83
+ }
84
+ return new ConsoleLogger_1(context.resolve(import_level.LogLevel), argument, void 0);
85
+ }
81
86
  }
82
87
  }),
83
88
  __metadata("design:paramtypes", [Number, Object, String])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.84.35",
3
+ "version": "0.84.37",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -181,7 +181,7 @@ let PdfService = class PdfService2 {
181
181
  const context = options.browserContext ?? await this.browserController.newContext({ locale: options.locale ?? this.defaultLocale });
182
182
  const page = await context.newPage();
183
183
  if ((0, import_type_guards.isDefined)(options.log) && options.log != false) {
184
- const level = options.log == true ? import_level.LogLevel.Info : options.log;
184
+ const level = options.log == true ? import_level.LogLevel.Trace : options.log;
185
185
  const logger = this.logger.fork({ level, subModule: "PAGE" });
186
186
  page.attachLogger(logger);
187
187
  }
@@ -22,7 +22,7 @@ __export(event_loop_exports, {
22
22
  runEventLoopWatcher: () => runEventLoopWatcher
23
23
  });
24
24
  module.exports = __toCommonJS(event_loop_exports);
25
- var import_helpers = require("./helpers.js");
25
+ var import_format = require("./format.js");
26
26
  var import_periodic_sampler = require("./periodic-sampler.js");
27
27
  var import_timer = require("./timer.js");
28
28
  async function measureEventLoopDelay() {
@@ -36,7 +36,7 @@ async function measureEventLoopDelay() {
36
36
  }
37
37
  function runEventLoopWatcher(logger, cancellationToken) {
38
38
  const sampler = new import_periodic_sampler.PeriodicSampler(measureEventLoopDelay, 50);
39
- sampler.watch(0, 100, import_periodic_sampler.AggregationMode.ThirdQuartile).subscribe((delay) => logger.debug(`eventloop: ${(0, import_helpers.formatDuration)(delay, 2)}`));
39
+ sampler.watch(0, 100, import_periodic_sampler.AggregationMode.ThirdQuartile).subscribe((delay) => logger.debug(`eventloop: ${(0, import_format.formatDuration)(delay, 2)}`));
40
40
  sampler.start();
41
41
  cancellationToken.then(async () => sampler.stop());
42
42
  }
@@ -0,0 +1,5 @@
1
+ export declare function formatDuration(milliseconds: number, precision: number): string;
2
+ export declare function formatBytes(bytes: number, { decimals, unit }?: {
3
+ decimals?: number;
4
+ unit?: 'SI' | 'IEC';
5
+ }): string;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var format_exports = {};
20
+ __export(format_exports, {
21
+ formatBytes: () => formatBytes,
22
+ formatDuration: () => formatDuration
23
+ });
24
+ module.exports = __toCommonJS(format_exports);
25
+ const siByteSizes = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
26
+ const iecByteSizes = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
27
+ function formatDuration(milliseconds, precision) {
28
+ let value;
29
+ let suffix;
30
+ if (milliseconds >= 10 ** 3) {
31
+ value = milliseconds / 10 ** 3;
32
+ suffix = "s";
33
+ } else if (milliseconds >= 1) {
34
+ value = milliseconds;
35
+ suffix = "ms";
36
+ } else if (milliseconds >= 1 / 10 ** 3) {
37
+ value = milliseconds * 10 ** 3;
38
+ suffix = "us";
39
+ } else {
40
+ value = milliseconds * 10 ** 6;
41
+ suffix = "ns";
42
+ }
43
+ const trimmed = parseFloat(value.toFixed(precision));
44
+ const result = `${trimmed} ${suffix}`;
45
+ return result;
46
+ }
47
+ function formatBytes(bytes, { decimals = 2, unit = "IEC" } = {}) {
48
+ const iec = unit == "IEC";
49
+ const base = iec ? 1024 : 1e3;
50
+ const exponent = Math.floor(Math.log(bytes) / Math.log(base));
51
+ const prefix = (iec ? iecByteSizes : siByteSizes)[exponent];
52
+ const result = bytes / base ** exponent;
53
+ const formattedResult = Intl.NumberFormat(void 0, { useGrouping: false, maximumFractionDigits: decimals }).format(result);
54
+ return `${formattedResult} ${prefix}`;
55
+ }
@@ -17,7 +17,6 @@ export declare function structuredClone<T>(value: T): T;
17
17
  export declare function structuredCloneAsync<T>(value: T, options?: {
18
18
  transfer?: any[];
19
19
  }): Promise<T>;
20
- export declare function formatDuration(milliseconds: number, precision: number): string;
21
20
  export declare function valueOfType<T>(value: T): T;
22
21
  export declare function flatten<T>(array: DeepArray<T>): T[];
23
22
  export declare function toError(obj: any): Error;
package/utils/helpers.js CHANGED
@@ -19,7 +19,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var helpers_exports = {};
20
20
  __export(helpers_exports, {
21
21
  flatten: () => flatten,
22
- formatDuration: () => formatDuration,
23
22
  iif: () => iif,
24
23
  normalizeText: () => normalizeText,
25
24
  parseFirstAndFamilyName: () => parseFirstAndFamilyName,
@@ -50,26 +49,6 @@ async function structuredCloneAsync(value, options) {
50
49
  port1.postMessage(value, options);
51
50
  return promise;
52
51
  }
53
- function formatDuration(milliseconds, precision) {
54
- let value;
55
- let suffix;
56
- if (milliseconds >= 10 ** 3) {
57
- value = milliseconds / 10 ** 3;
58
- suffix = "s";
59
- } else if (milliseconds >= 1) {
60
- value = milliseconds;
61
- suffix = "ms";
62
- } else if (milliseconds >= 1 / 10 ** 3) {
63
- value = milliseconds * 10 ** 3;
64
- suffix = "us";
65
- } else {
66
- value = milliseconds * 10 ** 6;
67
- suffix = "ns";
68
- }
69
- const trimmed = parseFloat(value.toFixed(precision));
70
- const result = `${trimmed} ${suffix}`;
71
- return result;
72
- }
73
52
  function valueOfType(value) {
74
53
  return value;
75
54
  }