@nu-art/ts-common 0.200.22 → 0.200.24

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.
Files changed (101) hide show
  1. package/consts/consts.js +0 -1
  2. package/core/application.js +12 -31
  3. package/core/debug-flags.js +32 -38
  4. package/core/dispatcher.js +30 -92
  5. package/core/error-handling.js +1 -2
  6. package/core/exceptions.js +47 -84
  7. package/core/logger/BeLogged.js +19 -26
  8. package/core/logger/LogClient.js +14 -16
  9. package/core/logger/LogClient_BaseRotate.js +20 -42
  10. package/core/logger/LogClient_Browser.js +16 -36
  11. package/core/logger/LogClient_Function.js +14 -34
  12. package/core/logger/LogClient_MemBuffer.js +14 -35
  13. package/core/logger/LogClient_Terminal.js +12 -34
  14. package/core/logger/Logger.js +67 -152
  15. package/core/logger/types.js +0 -1
  16. package/core/logger/utils.js +16 -18
  17. package/core/module-manager.js +33 -61
  18. package/core/module.js +43 -65
  19. package/csv.js +0 -1
  20. package/index.js +0 -1
  21. package/modules/CSVModule.js +50 -110
  22. package/modules/CliParamsModule.js +32 -54
  23. package/modules/csv-serializer.js +10 -22
  24. package/package.json +8 -18
  25. package/permissions/permission-group.js +9 -12
  26. package/test-index.js +0 -1
  27. package/testing/consts.js +18 -54
  28. package/testing/types.js +0 -1
  29. package/tools/Replacer.js +71 -96
  30. package/tools/get-log-style.js +5 -10
  31. package/utils/array-tools.js +63 -127
  32. package/utils/crypto-tools.js +1 -2
  33. package/utils/date-time-tools.js +19 -75
  34. package/utils/db-object-tools.js +0 -1
  35. package/utils/filter-tools.js +37 -43
  36. package/utils/hash-tools.js +4 -8
  37. package/utils/merge-tools.js +4 -5
  38. package/utils/mimetype-tools.js +0 -1
  39. package/utils/number-tools.js +3 -4
  40. package/utils/object-tools.js +16 -20
  41. package/utils/query-params.js +8 -11
  42. package/utils/queue.js +47 -115
  43. package/utils/random-tools.js +2 -3
  44. package/utils/storage-capacity-tools.js +0 -1
  45. package/utils/string-tools.js +16 -18
  46. package/utils/tools.js +11 -42
  47. package/utils/types.js +1 -2
  48. package/utils/ui-tools.js +8 -15
  49. package/utils/version-tools.js +6 -7
  50. package/validator/type-validators.js +65 -84
  51. package/validator/validator-core.js +34 -58
  52. package/consts/consts.js.map +0 -1
  53. package/core/application.js.map +0 -1
  54. package/core/debug-flags.js.map +0 -1
  55. package/core/dispatcher.js.map +0 -1
  56. package/core/error-handling.js.map +0 -1
  57. package/core/exceptions.js.map +0 -1
  58. package/core/logger/BeLogged.js.map +0 -1
  59. package/core/logger/LogClient.js.map +0 -1
  60. package/core/logger/LogClient_BaseRotate.js.map +0 -1
  61. package/core/logger/LogClient_Browser.js.map +0 -1
  62. package/core/logger/LogClient_Function.js.map +0 -1
  63. package/core/logger/LogClient_MemBuffer.js.map +0 -1
  64. package/core/logger/LogClient_Terminal.js.map +0 -1
  65. package/core/logger/Logger.js.map +0 -1
  66. package/core/logger/types.js.map +0 -1
  67. package/core/logger/utils.js.map +0 -1
  68. package/core/module-manager.js.map +0 -1
  69. package/core/module.js.map +0 -1
  70. package/csv.js.map +0 -1
  71. package/index.js.map +0 -1
  72. package/modules/CSVModule.js.map +0 -1
  73. package/modules/CliParamsModule.js.map +0 -1
  74. package/modules/csv-serializer.js.map +0 -1
  75. package/permissions/permission-group.js.map +0 -1
  76. package/test-index.js.map +0 -1
  77. package/testing/consts.js.map +0 -1
  78. package/testing/types.js.map +0 -1
  79. package/tools/Replacer.js.map +0 -1
  80. package/tools/get-log-style.js.map +0 -1
  81. package/utils/array-tools.js.map +0 -1
  82. package/utils/crypto-tools.js.map +0 -1
  83. package/utils/date-time-tools.js.map +0 -1
  84. package/utils/db-object-tools.js.map +0 -1
  85. package/utils/filter-tools.js.map +0 -1
  86. package/utils/hash-tools.js.map +0 -1
  87. package/utils/merge-tools.js.map +0 -1
  88. package/utils/mimetype-tools.js.map +0 -1
  89. package/utils/number-tools.js.map +0 -1
  90. package/utils/object-tools.js.map +0 -1
  91. package/utils/query-params.js.map +0 -1
  92. package/utils/queue.js.map +0 -1
  93. package/utils/random-tools.js.map +0 -1
  94. package/utils/storage-capacity-tools.js.map +0 -1
  95. package/utils/string-tools.js.map +0 -1
  96. package/utils/tools.js.map +0 -1
  97. package/utils/types.js.map +0 -1
  98. package/utils/ui-tools.js.map +0 -1
  99. package/utils/version-tools.js.map +0 -1
  100. package/validator/type-validators.js.map +0 -1
  101. package/validator/validator-core.js.map +0 -1
@@ -21,14 +21,14 @@ exports._logger_indentNewLineBy = exports._logger_logException = exports._logger
21
21
  /**
22
22
  * Created by TacB0sS on 3/16/17.
23
23
  */
24
- var array_tools_1 = require("../../utils/array-tools");
25
- var tools_1 = require("../../utils/tools");
24
+ const array_tools_1 = require("../../utils/array-tools");
25
+ const tools_1 = require("../../utils/tools");
26
26
  function _logger_logObject(instance) {
27
27
  return (0, tools_1.__stringify)(instance, true);
28
28
  }
29
29
  exports._logger_logObject = _logger_logObject;
30
30
  function _logger_convertLogParamsToStrings(params) {
31
- return params.map(function (toLog) {
31
+ return params.map(toLog => {
32
32
  if (typeof toLog === 'undefined')
33
33
  return 'undefined';
34
34
  if (toLog === null)
@@ -36,7 +36,7 @@ function _logger_convertLogParamsToStrings(params) {
36
36
  if (typeof toLog === 'string')
37
37
  return toLog;
38
38
  if (typeof toLog === 'number')
39
- return "".concat(toLog);
39
+ return `${toLog}`;
40
40
  // @ts-ignore
41
41
  if (toLog.stack)
42
42
  return _logger_logException(toLog);
@@ -44,37 +44,35 @@ function _logger_convertLogParamsToStrings(params) {
44
44
  });
45
45
  }
46
46
  exports._logger_convertLogParamsToStrings = _logger_convertLogParamsToStrings;
47
- function _logger_logException(error, fullStack) {
48
- if (fullStack === void 0) { fullStack = ''; }
49
- var toPrint = '';
50
- var errorMessage;
51
- var isCustomException = false;
47
+ function _logger_logException(error, fullStack = '') {
48
+ let toPrint = '';
49
+ let errorMessage;
50
+ let isCustomException = false;
52
51
  if (error.stack) {
53
- var stackAsList = error.stack.split('\n');
52
+ const stackAsList = error.stack.split('\n');
54
53
  errorMessage = stackAsList[0];
55
54
  (0, array_tools_1.removeItemFromArray)(stackAsList, errorMessage);
56
- toPrint = stackAsList.reduce(function (toRet, stacktrace) {
55
+ toPrint = stackAsList.reduce((toRet, stacktrace) => {
57
56
  if (fullStack.indexOf(stacktrace) !== -1)
58
57
  return toRet;
59
58
  return toRet + stacktrace + '\n';
60
59
  }, toPrint);
61
60
  isCustomException = toPrint.indexOf('CustomException') !== -1;
62
61
  toPrint = toPrint.replace(/\s+at.*?CustomException.*?\n/, '\n');
63
- toPrint = toPrint.replace(/\s+at.*?new\s+(.*?) \(.*?\n/, "".concat(fullStack.length === 0 ? '' : '\nCaused by ', "$1: ").concat(errorMessage.replace('Error: ', ''), "\n"));
62
+ toPrint = toPrint.replace(/\s+at.*?new\s+(.*?) \(.*?\n/, `${fullStack.length === 0 ? '' : '\nCaused by '}$1: ${errorMessage.replace('Error: ', '')}\n`);
64
63
  if (!isCustomException && errorMessage)
65
64
  toPrint = errorMessage + '\n' + toPrint;
66
65
  }
67
- var cause = error.cause;
66
+ const cause = error.cause;
68
67
  if (cause) {
69
- var causeStack = _logger_logException(cause, toPrint);
70
- causeStack = causeStack.replace("Error: ".concat(cause.message), "".concat(cause.message));
71
- toPrint += "".concat(causeStack);
68
+ let causeStack = _logger_logException(cause, toPrint);
69
+ causeStack = causeStack.replace(`Error: ${cause.message}`, `${cause.message}`);
70
+ toPrint += `${causeStack}`;
72
71
  }
73
72
  return toPrint;
74
73
  }
75
74
  exports._logger_logException = _logger_logException;
76
75
  function _logger_indentNewLineBy(linePrefix, input) {
77
- return linePrefix + input.replace(/\n/g, "\n".concat(linePrefix));
76
+ return linePrefix + input.replace(/\n/g, `\n${linePrefix}`);
78
77
  }
79
78
  exports._logger_indentNewLineBy = _logger_indentNewLineBy;
80
- //# sourceMappingURL=utils.js.map
@@ -16,97 +16,69 @@
16
16
  * See the License for the specific language governing permissions and
17
17
  * limitations under the License.
18
18
  */
19
- var __extends = (this && this.__extends) || (function () {
20
- var extendStatics = function (d, b) {
21
- extendStatics = Object.setPrototypeOf ||
22
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
23
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
24
- return extendStatics(d, b);
25
- };
26
- return function (d, b) {
27
- if (typeof b !== "function" && b !== null)
28
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
29
- extendStatics(d, b);
30
- function __() { this.constructor = d; }
31
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
32
- };
33
- })();
34
19
  Object.defineProperty(exports, "__esModule", { value: true });
35
20
  exports.ModuleManager = exports.moduleResolver = void 0;
36
- var dispatcher_1 = require("./dispatcher");
37
- var exceptions_1 = require("./exceptions");
38
- var Logger_1 = require("./logger/Logger");
39
- var array_tools_1 = require("../utils/array-tools");
40
- var _modules = [];
21
+ const dispatcher_1 = require("./dispatcher");
22
+ const exceptions_1 = require("./exceptions");
23
+ const Logger_1 = require("./logger/Logger");
24
+ const array_tools_1 = require("../utils/array-tools");
25
+ const _modules = [];
41
26
  function moduleResolver() {
42
27
  return _modules;
43
28
  }
44
29
  exports.moduleResolver = moduleResolver;
45
- var ModuleManager = /** @class */ (function (_super) {
46
- __extends(ModuleManager, _super);
30
+ class ModuleManager extends Logger_1.Logger {
47
31
  // noinspection JSUnusedLocalSymbols
48
- function ModuleManager() {
49
- var _this = _super.call(this) || this;
50
- _this.modules = _modules;
32
+ constructor() {
33
+ super();
34
+ this.modules = _modules;
51
35
  if (ModuleManager.instance)
52
36
  throw new exceptions_1.BadImplementationException('Already have one instance of ModuleManager');
53
- ModuleManager.instance = _this;
37
+ ModuleManager.instance = this;
54
38
  dispatcher_1.Dispatcher.modulesResolver = moduleResolver;
55
- return _this;
56
39
  }
57
- ModuleManager.prototype.filterModules = function (filter) {
40
+ filterModules(filter) {
58
41
  return this.modules.filter(filter);
59
- };
60
- ModuleManager.prototype.setConfig = function (config) {
42
+ }
43
+ setConfig(config) {
61
44
  this.config = config || {};
62
45
  return this;
63
- };
64
- ModuleManager.prototype.addModules = function () {
65
- var modules = [];
66
- for (var _i = 0; _i < arguments.length; _i++) {
67
- modules[_i] = arguments[_i];
68
- }
69
- modules.reduce(function (carry, module) {
46
+ }
47
+ addModules(...modules) {
48
+ modules.reduce((carry, module) => {
70
49
  if (!carry.includes(module))
71
50
  (0, array_tools_1.addItemToArray)(carry, module);
72
51
  return carry;
73
52
  }, this.modules);
74
53
  return this;
75
- };
76
- ModuleManager.prototype.setModules = function () {
77
- var modules = [];
78
- for (var _i = 0; _i < arguments.length; _i++) {
79
- modules[_i] = arguments[_i];
80
- }
54
+ }
55
+ setModules(...modules) {
81
56
  this.modules = (0, array_tools_1.filterDuplicates)(modules);
82
57
  return this;
83
- };
84
- ModuleManager.prototype.init = function () {
85
- var _this = this;
86
- this.logInfo("--------- initializing app ---------");
87
- this.modules.forEach(function (module) {
58
+ }
59
+ init() {
60
+ this.logInfo(`--------- initializing app ---------`);
61
+ this.modules.forEach((module) => {
88
62
  // @ts-ignore
89
- module.setManager(_this);
90
- if (_this.config)
63
+ module.setManager(this);
64
+ if (this.config)
91
65
  // @ts-ignore
92
- module.setConfig(_this.config[module.getName()]);
66
+ module.setConfig(this.config[module.getName()]);
93
67
  });
94
- this.modules.forEach(function (module) {
95
- _this.logDebug("--------- ".concat(module.getName(), " ---------"));
68
+ this.modules.forEach(module => {
69
+ this.logDebug(`--------- ${module.getName()} ---------`);
96
70
  // @ts-ignore
97
71
  module.init();
98
72
  // @ts-ignore
99
73
  module.initiated = true;
100
74
  });
101
75
  // @ts-ignore
102
- this.modules.forEach(function (module) { return module.validate(); });
103
- this.logInfo("--------- INITIALIZED ---------");
76
+ this.modules.forEach(module => module.validate());
77
+ this.logInfo(`--------- INITIALIZED ---------`);
104
78
  return this;
105
- };
106
- ModuleManager.prototype.build = function () {
79
+ }
80
+ build() {
107
81
  this.init();
108
- };
109
- return ModuleManager;
110
- }(Logger_1.Logger));
82
+ }
83
+ }
111
84
  exports.ModuleManager = ModuleManager;
112
- //# sourceMappingURL=module-manager.js.map
package/core/module.js CHANGED
@@ -16,56 +16,38 @@
16
16
  * See the License for the specific language governing permissions and
17
17
  * limitations under the License.
18
18
  */
19
- var __extends = (this && this.__extends) || (function () {
20
- var extendStatics = function (d, b) {
21
- extendStatics = Object.setPrototypeOf ||
22
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
23
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
24
- return extendStatics(d, b);
25
- };
26
- return function (d, b) {
27
- if (typeof b !== "function" && b !== null)
28
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
29
- extendStatics(d, b);
30
- function __() { this.constructor = d; }
31
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
32
- };
33
- })();
34
19
  Object.defineProperty(exports, "__esModule", { value: true });
35
20
  exports.Module = void 0;
36
- var exceptions_1 = require("./exceptions");
37
- var merge_tools_1 = require("../utils/merge-tools");
38
- var Logger_1 = require("./logger/Logger");
39
- var __1 = require("..");
40
- var Module = /** @class */ (function (_super) {
41
- __extends(Module, _super);
21
+ const exceptions_1 = require("./exceptions");
22
+ const merge_tools_1 = require("../utils/merge-tools");
23
+ const Logger_1 = require("./logger/Logger");
24
+ const __1 = require("..");
25
+ class Module extends Logger_1.Logger {
42
26
  // noinspection TypeScriptAbstractClassConstructorCanBeMadeProtected
43
- function Module(tag) {
44
- var _this = _super.call(this, tag) || this;
45
- _this.initiated = false;
46
- _this.config = {};
47
- _this.timeoutMap = {};
48
- _this.runAsync = function (label, toCall) {
49
- setTimeout(function () {
50
- _this.logDebug("Running async: ".concat(label));
27
+ constructor(tag) {
28
+ super(tag);
29
+ this.initiated = false;
30
+ this.config = {};
31
+ this.timeoutMap = {};
32
+ this.runAsync = (label, toCall) => {
33
+ setTimeout(() => {
34
+ this.logDebug(`Running async: ${label}`);
51
35
  new Promise(toCall)
52
- .then(function () {
53
- _this.logDebug("Async call completed: ".concat(label));
36
+ .then(() => {
37
+ this.logDebug(`Async call completed: ${label}`);
54
38
  })
55
- .catch(function (reason) { return _this.logError("Async call error: ".concat(label), reason); });
39
+ .catch(reason => this.logError(`Async call error: ${label}`, reason));
56
40
  }, 0);
57
41
  };
58
- _this.name = _this.constructor['name'];
59
- if (!_this.name.endsWith('_Class'))
60
- throw new exceptions_1.BadImplementationException("Found module named: ".concat(_this.name, ", Module class MUST end with '_Class' e.g. MyModule_Class"));
61
- _this.name = _this.name.replace('_Class', '');
62
- return _this;
42
+ this.name = this.constructor['name'];
43
+ if (!this.name.endsWith('_Class'))
44
+ throw new exceptions_1.BadImplementationException(`Found module named: ${this.name}, Module class MUST end with '_Class' e.g. MyModule_Class`);
45
+ this.name = this.name.replace('_Class', '');
63
46
  }
64
- Module.prototype.debounce = function (handler, key, ms) {
65
- if (ms === void 0) { ms = 0; }
47
+ debounce(handler, key, ms = 0) {
66
48
  (0, __1._clearTimeout)(this.timeoutMap[key]);
67
49
  this.timeoutMap[key] = (0, __1._setTimeout)(handler, ms);
68
- };
50
+ }
69
51
  // // possibly to add
70
52
  // public async debounceSync(handler: TimerHandler, key: string, ms = 0) {
71
53
  // _clearTimeout(this.timeoutMap[key]);
@@ -81,46 +63,42 @@ var Module = /** @class */ (function (_super) {
81
63
  // }, ms) as unknown as number;
82
64
  // });
83
65
  // }
84
- Module.prototype.throttle = function (handler, key, ms) {
85
- var _this = this;
86
- if (ms === void 0) { ms = 0; }
66
+ throttle(handler, key, ms = 0) {
87
67
  if (this.timeoutMap[key])
88
68
  return;
89
- this.timeoutMap[key] = (0, __1._setTimeout)(function () {
69
+ this.timeoutMap[key] = (0, __1._setTimeout)(() => {
90
70
  handler();
91
- delete _this.timeoutMap[key];
71
+ delete this.timeoutMap[key];
92
72
  }, ms);
93
- };
94
- Module.prototype.setConfigValidator = function (validator) {
73
+ }
74
+ setConfigValidator(validator) {
95
75
  // @ts-ignore
96
76
  this.configValidator = validator;
97
- };
98
- Module.prototype.setDefaultConfig = function (config) {
77
+ }
78
+ setDefaultConfig(config) {
99
79
  // @ts-ignore
100
80
  this.config = (0, merge_tools_1.merge)(this.config, config);
101
- };
102
- Module.prototype.getName = function () {
81
+ }
82
+ getName() {
103
83
  return this.name;
104
- };
105
- Module.prototype.setName = function (name) {
84
+ }
85
+ setName(name) {
106
86
  this.name = name;
107
- };
108
- Module.prototype.setConfig = function (config) {
87
+ }
88
+ setConfig(config) {
109
89
  // @ts-ignore
110
90
  this.config = this.config ? (0, merge_tools_1.merge)(this.config, config || {}) : config;
111
91
  this.config.minLogLevel && this.setMinLevel(this.config.minLogLevel);
112
- };
113
- Module.prototype.setManager = function (manager) {
92
+ }
93
+ setManager(manager) {
114
94
  // @ts-ignore
115
95
  this.manager = manager;
116
- };
117
- Module.prototype.init = function () {
96
+ }
97
+ init() {
118
98
  // ignorance is bliss
119
- };
120
- Module.prototype.validate = function () {
99
+ }
100
+ validate() {
121
101
  // ignorance is bliss
122
- };
123
- return Module;
124
- }(Logger_1.Logger));
102
+ }
103
+ }
125
104
  exports.Module = Module;
126
- //# sourceMappingURL=module.js.map
package/csv.js CHANGED
@@ -32,4 +32,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
32
32
  };
33
33
  Object.defineProperty(exports, "__esModule", { value: true });
34
34
  __exportStar(require("./modules/CSVModule"), exports);
35
- //# sourceMappingURL=csv.js.map
package/index.js CHANGED
@@ -75,4 +75,3 @@ __exportStar(require("./validator/type-validators"), exports);
75
75
  __exportStar(require("./consts/consts"), exports);
76
76
  __exportStar(require("./modules/CliParamsModule"), exports);
77
77
  __exportStar(require("./modules/csv-serializer"), exports);
78
- //# sourceMappingURL=index.js.map
@@ -16,21 +16,6 @@
16
16
  * See the License for the specific language governing permissions and
17
17
  * limitations under the License.
18
18
  */
19
- var __extends = (this && this.__extends) || (function () {
20
- var extendStatics = function (d, b) {
21
- extendStatics = Object.setPrototypeOf ||
22
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
23
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
24
- return extendStatics(d, b);
25
- };
26
- return function (d, b) {
27
- if (typeof b !== "function" && b !== null)
28
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
29
- extendStatics(d, b);
30
- function __() { this.constructor = d; }
31
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
32
- };
33
- })();
34
19
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
35
20
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
36
21
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -40,44 +25,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
40
25
  step((generator = generator.apply(thisArg, _arguments || [])).next());
41
26
  });
42
27
  };
43
- var __generator = (this && this.__generator) || function (thisArg, body) {
44
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
45
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
46
- function verb(n) { return function (v) { return step([n, v]); }; }
47
- function step(op) {
48
- if (f) throw new TypeError("Generator is already executing.");
49
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
50
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
51
- if (y = 0, t) op = [op[0] & 2, t.value];
52
- switch (op[0]) {
53
- case 0: case 1: t = op; break;
54
- case 4: _.label++; return { value: op[1], done: false };
55
- case 5: _.label++; y = op[1]; op = [0]; continue;
56
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
57
- default:
58
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
59
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
60
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
61
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
62
- if (t[2]) _.ops.pop();
63
- _.trys.pop(); continue;
64
- }
65
- op = body.call(thisArg, _);
66
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
67
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
68
- }
69
- };
70
28
  Object.defineProperty(exports, "__esModule", { value: true });
71
29
  exports.CSVModule = void 0;
72
30
  /**
73
31
  * Created by tacb0ss on 07/05/2018.
74
32
  */
75
- var export_to_csv_1 = require("export-to-csv");
76
- var fs_1 = require("fs");
77
- var module_1 = require("../core/module");
78
- var stream_1 = require("stream");
79
- var csvParser = require("csv-parser");
80
- var DefaultConfig = {
33
+ const export_to_csv_1 = require("export-to-csv");
34
+ const fs_1 = require("fs");
35
+ const module_1 = require("../core/module");
36
+ const stream_1 = require("stream");
37
+ const csvParser = require("csv-parser");
38
+ const DefaultConfig = {
81
39
  options: {
82
40
  fieldSeparator: ',',
83
41
  quoteStrings: '"',
@@ -90,85 +48,67 @@ var DefaultConfig = {
90
48
  useKeysAsHeaders: true,
91
49
  }
92
50
  };
93
- var CSVModule_Class = /** @class */ (function (_super) {
94
- __extends(CSVModule_Class, _super);
95
- function CSVModule_Class() {
96
- var _this = _super.call(this) || this;
97
- _this.setDefaultConfig(DefaultConfig);
98
- return _this;
51
+ class CSVModule_Class extends module_1.Module {
52
+ constructor() {
53
+ super();
54
+ this.setDefaultConfig(DefaultConfig);
99
55
  }
100
- CSVModule_Class.prototype.init = function () {
56
+ init() {
101
57
  this.csvExporter = CSVModule_Class.createExporter(this.config.options);
102
- };
103
- CSVModule_Class.createExporter = function (options) {
58
+ }
59
+ static createExporter(options) {
104
60
  return new export_to_csv_1.ExportToCsv(options);
105
- };
106
- CSVModule_Class.prototype.export = function (items, returnCsv) {
107
- if (returnCsv === void 0) { returnCsv = true; }
61
+ }
62
+ export(items, returnCsv = true) {
108
63
  return this.csvExporter.generateCsv(items, returnCsv);
109
- };
110
- CSVModule_Class.prototype.saveToFile = function (outputFile, items, columnsToProps) {
111
- return __awaiter(this, void 0, void 0, function () {
112
- var csv;
113
- return __generator(this, function (_a) {
114
- csv = this.csvExporter.generateCsv(items, true);
115
- return [2 /*return*/, fs_1.promises.writeFile(outputFile, csv, { encoding: 'utf8' })];
116
- });
64
+ }
65
+ saveToFile(outputFile, items, columnsToProps) {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ const csv = this.csvExporter.generateCsv(items, true);
68
+ return fs_1.promises.writeFile(outputFile, csv, { encoding: 'utf8' });
117
69
  });
118
- };
119
- CSVModule_Class.prototype.readCsvFromFile = function (inputFile, readOptions) {
120
- return __awaiter(this, void 0, void 0, function () {
121
- var stream;
122
- return __generator(this, function (_a) {
123
- stream = (0, fs_1.createReadStream)(inputFile, { encoding: 'utf8' });
124
- return [2 /*return*/, this.readCsvFromStream(stream, readOptions)];
125
- });
70
+ }
71
+ readCsvFromFile(inputFile, readOptions) {
72
+ return __awaiter(this, void 0, void 0, function* () {
73
+ const stream = (0, fs_1.createReadStream)(inputFile, { encoding: 'utf8' });
74
+ return this.readCsvFromStream(stream, readOptions);
126
75
  });
127
- };
128
- CSVModule_Class.prototype.readCsvFromBuffer = function (buffer, readOptions) {
129
- return __awaiter(this, void 0, void 0, function () {
130
- var stream;
131
- return __generator(this, function (_a) {
132
- stream = stream_1.Readable.from(buffer.toString('utf-8'), { encoding: 'utf8' });
133
- return [2 /*return*/, this.readCsvFromStream(stream, readOptions)];
134
- });
76
+ }
77
+ readCsvFromBuffer(buffer, readOptions) {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ const stream = stream_1.Readable.from(buffer.toString('utf-8'), { encoding: 'utf8' });
80
+ return this.readCsvFromStream(stream, readOptions);
135
81
  });
136
- };
137
- CSVModule_Class.prototype.readCsvFromStream = function (stream, readOptions) {
138
- if (readOptions === void 0) { readOptions = {}; }
139
- return __awaiter(this, void 0, void 0, function () {
140
- var _this = this;
141
- return __generator(this, function (_a) {
142
- return [2 /*return*/, new Promise(function (resolve, reject) {
143
- var results = [];
144
- stream
145
- .pipe(csvParser(_this.createReadParserOptions(readOptions)))
146
- .on('data', function (instance) {
147
- delete instance['undefined'];
148
- results.push(instance);
149
- })
150
- .on('error', function (err) { return reject(err); })
151
- .on('end', function () { return resolve(results); });
152
- })];
82
+ }
83
+ readCsvFromStream(stream, readOptions = {}) {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ return new Promise((resolve, reject) => {
86
+ const results = [];
87
+ stream
88
+ .pipe(csvParser(this.createReadParserOptions(readOptions)))
89
+ .on('data', (instance) => {
90
+ delete instance['undefined'];
91
+ results.push(instance);
92
+ })
93
+ .on('error', (err) => reject(err))
94
+ .on('end', () => resolve(results));
153
95
  });
154
96
  });
155
- };
156
- CSVModule_Class.prototype.createReadParserOptions = function (readOptions) {
97
+ }
98
+ createReadParserOptions(readOptions) {
157
99
  return {
158
- mapHeaders: function (args) {
100
+ mapHeaders: (args) => {
159
101
  var _a, _b;
160
102
  return (_b = (_a = readOptions.columnsToProps) === null || _a === void 0 ? void 0 : _a[args.header]) !== null && _b !== void 0 ? _b : args.header;
161
103
  },
162
- mapValues: function (args) {
104
+ mapValues: (args) => {
163
105
  var _a;
164
- var mapValues = (_a = readOptions.mapValues) === null || _a === void 0 ? void 0 : _a.call(readOptions, args.header, args.value, args.index);
106
+ const mapValues = (_a = readOptions.mapValues) === null || _a === void 0 ? void 0 : _a.call(readOptions, args.header, args.value, args.index);
165
107
  return mapValues !== null && mapValues !== void 0 ? mapValues : args.value;
166
108
  },
167
109
  quote: readOptions.quote || '"',
168
110
  headers: readOptions.headers
169
111
  };
170
- };
171
- return CSVModule_Class;
172
- }(module_1.Module));
112
+ }
113
+ }
173
114
  exports.CSVModule = new CSVModule_Class();
174
- //# sourceMappingURL=CSVModule.js.map