Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@simplism/core

Package Overview
Dependencies
Maintainers
1
Versions
224
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@simplism/core - npm Package Compare versions

Comparing version 6.0.52 to 7.0.1

dist/exceptions/Exception.js

3

dist/exceptions/Exception.d.ts
import { Type } from "../types/Type";
export declare class Exception extends Error {
constructor(message: string, constructorOpt?: Type<any>);
code?: string;
constructor(message?: string, code?: string, constructorOpt?: Type<any>);
}
import { Exception } from "./Exception";
export declare class NotImplementedException extends Exception {
constructor(message?: string);
constructor();
}

@@ -1,4 +0,43 @@

interface Array<T> {
mapMany<R>(predicate: (item: T, index: number) => R[]): R[];
last(predicate?: (item: T, index: number) => boolean): T | undefined;
import { Type } from "../types/Type";
declare global {
interface Array<T> {
groupBy<K>(keySelector: (item: T, index: number) => K): {
key: K;
values: T[];
}[];
groupBy<K, V>(keySelector: (item: T, index: number) => K, valueSelector: (item: T, index: number) => V): {
key: K;
values: V[];
}[];
toMap<K>(keySelector: (item: T, index: number) => K): Map<K, T>;
toMap<K, V>(keySelector: (item: T, index: number) => K, valueSelector: (item: T, index: number) => V): Map<K, V>;
mapMany<R>(selector?: (item: T, index: number) => R[]): R[];
single(predicate?: (item: T, index: number) => boolean): T | undefined;
last(predicate?: (item: T, index: number) => boolean): T | undefined;
sum(): T | undefined;
sum<P extends NonNullable<any>>(selector: (item: T) => P): P | undefined;
max(): T | undefined;
max<P extends NonNullable<any>>(selector: (item: T) => P): P | undefined;
min(): T | undefined;
min<P extends NonNullable<any>>(selector: (item: T) => P): P | undefined;
distinct(): T[];
orderBy(selector?: (item: T) => any, desc?: boolean): T[];
pushRange(items: T[]): void;
insert(index: number, item: T): void;
remove(item: T): void;
remove(items: T[]): void;
remove(predicate: (item: T, index: number) => boolean): void;
filterExists(): NonNullable<T>[];
ofType<N>(type: Type<N>): N[];
diffs<K extends keyof T>(target: T[], options?: {
keyProps?: K[];
}): {
source?: T;
target?: T;
}[];
merge<K extends keyof T>(target: Partial<T>[], options?: {
keyProps?: K[];
replacement?: boolean;
}): void;
}
}
import "./extensions/ArrayExtensions";
export * from "./exceptions/ArgumentsException";
import "./extensions/ObjectConstructorExtensions";
export * from "./exceptions/Exception";
export * from "./exceptions/InvalidArgumentsException";
export * from "./exceptions/NotImplementedException";
export * from "./types/DateOnly";
export * from "./types/DateTime";
export * from "./types/Time";
export * from "./types/Type";
export * from "./types/Uuid";
export * from "./utils/JsonConvert";
export * from "./utils/LambdaParser";
export * from "./utils/Logger";
export * from "./utils/Wait";

@@ -1,233 +0,2 @@

(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else {
var a = factory();
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
}
})(global, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // object to store loaded and loading wasm modules
/******/ var installedWasmModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // object with all compiled WebAssembly.Modules
/******/ __webpack_require__.w = {};
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = "./packages/core/src/index.ts");
/******/ })
/************************************************************************/
/******/ ({
/***/ "./packages/core/src/exceptions/ArgumentsException.ts":
/*!************************************************************!*\
!*** ./packages/core/src/exceptions/ArgumentsException.ts ***!
\************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var Exception_1 = __webpack_require__(/*! ./Exception */ "./packages/core/src/exceptions/Exception.ts");
var ArgumentsException = (function (_super) {
__extends(ArgumentsException, _super);
function ArgumentsException(args) {
var _this = _super.call(this, "\uC785\uB825\uAC12\uC774 \uC798\uBABB\uB418\uC5C8\uC2B5\uB2C8\uB2E4. " + JSON.stringify(args)) || this;
_this.arguments = args;
return _this;
}
return ArgumentsException;
}(Exception_1.Exception));
exports.ArgumentsException = ArgumentsException;
/***/ }),
/***/ "./packages/core/src/exceptions/Exception.ts":
/*!***************************************************!*\
!*** ./packages/core/src/exceptions/Exception.ts ***!
\***************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var Exception = (function (_super) {
__extends(Exception, _super);
function Exception(message, constructorOpt) {
var _newTarget = this.constructor;
var _this = _super.call(this, message) || this;
Object.setPrototypeOf(_this, _newTarget.prototype);
_this.name = _newTarget.name;
_this.message = message;
Error.captureStackTrace(_this, constructorOpt || _newTarget);
return _this;
}
return Exception;
}(Error));
exports.Exception = Exception;
/***/ }),
/***/ "./packages/core/src/exceptions/NotImplementedException.ts":
/*!*****************************************************************!*\
!*** ./packages/core/src/exceptions/NotImplementedException.ts ***!
\*****************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var Exception_1 = __webpack_require__(/*! ./Exception */ "./packages/core/src/exceptions/Exception.ts");
var NotImplementedException = (function (_super) {
__extends(NotImplementedException, _super);
function NotImplementedException(message) {
return _super.call(this, "\uC544\uC9C1 \uAD6C\uD604\uB418\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4. [" + message + "]") || this;
}
return NotImplementedException;
}(Exception_1.Exception));
exports.NotImplementedException = NotImplementedException;
/***/ }),
/***/ "./packages/core/src/extensions/ArrayExtensions.ts":
/*!*********************************************************!*\
!*** ./packages/core/src/extensions/ArrayExtensions.ts ***!
\*********************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Array.prototype.mapMany = function (predicate) {
return this.length > 0 ? this.map(predicate).reduce(function (p, n) { return p.concat(n); }) : [];
};
Array.prototype.last = function (predicate) {
if (predicate) {
for (var i = this.length - 1; i >= 0; i--) {
if (predicate(this[i], i)) {
return this[i];
}
}
}
else {
return this[this.length - 1];
}
};
/***/ }),
/***/ "./packages/core/src/index.ts":
/*!************************************!*\
!*** ./packages/core/src/index.ts ***!
\************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
function __export(m) {

@@ -237,366 +6,16 @@ for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];

Object.defineProperty(exports, "__esModule", { value: true });
__webpack_require__(/*! ./extensions/ArrayExtensions */ "./packages/core/src/extensions/ArrayExtensions.ts");
__export(__webpack_require__(/*! ./exceptions/ArgumentsException */ "./packages/core/src/exceptions/ArgumentsException.ts"));
__export(__webpack_require__(/*! ./exceptions/Exception */ "./packages/core/src/exceptions/Exception.ts"));
__export(__webpack_require__(/*! ./exceptions/NotImplementedException */ "./packages/core/src/exceptions/NotImplementedException.ts"));
__export(__webpack_require__(/*! ./types/DateTime */ "./packages/core/src/types/DateTime.ts"));
__export(__webpack_require__(/*! ./types/Type */ "./packages/core/src/types/Type.ts"));
__export(__webpack_require__(/*! ./types/Uuid */ "./packages/core/src/types/Uuid.ts"));
__export(__webpack_require__(/*! ./utils/Logger */ "./packages/core/src/utils/Logger.ts"));
/***/ }),
/***/ "./packages/core/src/types/DateTime.ts":
/*!*********************************************!*\
!*** ./packages/core/src/types/DateTime.ts ***!
\*********************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ArgumentsException_1 = __webpack_require__(/*! ../exceptions/ArgumentsException */ "./packages/core/src/exceptions/ArgumentsException.ts");
var DateTime = (function () {
function DateTime() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (args.length === 0)
this._date = new Date();
else if (args.length === 1)
this._date = new Date(args[0]);
else if (args.length === 2)
this._date = new Date(args[0], args[1]);
else if (args.length === 3)
this._date = new Date(args[0], args[1], args[2]);
else if (args.length === 4)
this._date = new Date(args[0], args[1], args[2], args[3]);
else if (args.length === 5)
this._date = new Date(args[0], args[1], args[2], args[3], args[4]);
else if (args.length === 6)
this._date = new Date(args[0], args[1], args[2], args[3], args[4], args[5]);
else if (args.length === 7)
this._date = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
else
throw new ArgumentsException_1.ArgumentsException({ args: args });
}
DateTime.prototype.getFullYear = function () {
return this._date.getFullYear();
};
DateTime.prototype.getMonth = function () {
return this._date.getMonth();
};
DateTime.prototype.getDate = function () {
return this._date.getDate();
};
DateTime.prototype.getHours = function () {
return this._date.getHours();
};
DateTime.prototype.getMinutes = function () {
return this._date.getMinutes();
};
DateTime.prototype.getSeconds = function () {
return this._date.getSeconds();
};
DateTime.prototype.getMilliseconds = function () {
return this._date.getMilliseconds();
};
DateTime.prototype.getTimezoneOffset = function () {
return this._date.getTimezoneOffset();
};
DateTime.prototype.getDay = function () {
return this._date.getDay();
};
DateTime.prototype.toFormatString = function (format) {
var year = this.getFullYear();
var month = this.getMonth() + 1;
var day = this.getDate();
var hour = this.getHours();
var minute = this.getMinutes();
var second = this.getSeconds();
var milliSecond = this.getMilliseconds();
var offsetHour = -Math.floor(this.getTimezoneOffset() / 60);
var offsetMinute = -this.getTimezoneOffset() % 60;
var weekString = this.getDay() === 0 ? "일" :
this.getDay() === 1 ? "월" :
this.getDay() === 2 ? "화" :
this.getDay() === 3 ? "수" :
this.getDay() === 4 ? "목" :
this.getDay() === 5 ? "금" :
this.getDay() === 6 ? "토" :
"";
var result = format;
result = result.replace(/yyyy/g, year.toString());
result = result.replace(/yyy/g, year.toString().substr(1, 3));
result = result.replace(/yy/g, year.toString().substr(2, 2));
result = result.replace(/y/g, year.toString().substr(3, 1));
result = result.replace(/MM/g, month.toString().padStart(2, "0"));
result = result.replace(/M/g, month.toString());
result = result.replace(/dddd/g, weekString + "\uC694\uC77C");
result = result.replace(/ddd/g, weekString);
result = result.replace(/dd/g, day.toString().padStart(2, "0"));
result = result.replace(/d/g, day.toString());
result = result.replace(/tt/g, hour < 12 ? "오전" : "오후");
result = result.replace(/hh/g, (hour % 12).toString().padStart(2, "0"));
result = result.replace(/h/g, (hour % 12).toString());
result = result.replace(/HH/g, hour.toString().padStart(2, "0"));
result = result.replace(/H/g, hour.toString());
result = result.replace(/mm/g, minute.toString().padStart(2, "0"));
result = result.replace(/m/g, minute.toString());
result = result.replace(/ss/g, second.toString().padStart(2, "0"));
result = result.replace(/s/g, second.toString());
result = result.replace(/fff/g, milliSecond.toString().padStart(3, "0"));
result = result.replace(/ff/g, milliSecond.toString().padStart(3, "0").substr(0, 2));
result = result.replace(/f/g, milliSecond.toString().padStart(3, "0").substr(0, 1));
result = result.replace(/zzz/g, "" + (offsetHour > 0 ? "+" : "-") + Math.abs(offsetHour).toString().padStart(2, "0") + ":" + Math.abs(offsetMinute).toString().padStart(2, "0"));
result = result.replace(/zz/g, (offsetHour > 0 ? "+" : "-") + Math.abs(offsetHour).toString().padStart(2, "0"));
result = result.replace(/z/g, (offsetHour > 0 ? "+" : "-") + Math.abs(offsetHour).toString());
return result;
};
return DateTime;
}());
exports.DateTime = DateTime;
/***/ }),
/***/ "./packages/core/src/types/Type.ts":
/*!*****************************************!*\
!*** ./packages/core/src/types/Type.ts ***!
\*****************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/***/ }),
/***/ "./packages/core/src/types/Uuid.ts":
/*!*****************************************!*\
!*** ./packages/core/src/types/Uuid.ts ***!
\*****************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Uuid = (function () {
function Uuid() {
this._uuid = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0;
var v = c === "x" ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
Uuid.prototype.toString = function () {
return this._uuid;
};
return Uuid;
}());
exports.Uuid = Uuid;
/***/ }),
/***/ "./packages/core/src/utils/Logger.ts":
/*!*******************************************!*\
!*** ./packages/core/src/utils/Logger.ts ***!
\*******************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var fs = __webpack_require__(/*! fs-extra */ "fs-extra");
var path = __webpack_require__(/*! path */ "path");
var DateTime_1 = __webpack_require__(/*! ../types/DateTime */ "./packages/core/src/types/DateTime.ts");
var Logger = (function () {
function Logger(groupName, name) {
this._groupName = groupName;
this._name = typeof name === "string" ? name : name.constructor.name;
Logger._lastId++;
this._id = Logger._lastId;
}
Logger.setGroupConfig = function (groupName, config) {
this._groupMap.set(groupName, __assign({ consoleLogTypes: ["log", "info", "warn", "error"], fileLogTypes: [], outputPath: undefined, historySize: 30 }, config));
};
Logger.prototype.log = function () {
var logs = [];
for (var _i = 0; _i < arguments.length; _i++) {
logs[_i] = arguments[_i];
}
this._write("log", logs);
};
Logger.prototype.info = function () {
var logs = [];
for (var _i = 0; _i < arguments.length; _i++) {
logs[_i] = arguments[_i];
}
this._write("info", logs);
};
Logger.prototype.warn = function () {
var logs = [];
for (var _i = 0; _i < arguments.length; _i++) {
logs[_i] = arguments[_i];
}
this._write("warn", logs);
};
Logger.prototype.error = function () {
var logs = [];
for (var _i = 0; _i < arguments.length; _i++) {
logs[_i] = arguments[_i];
}
this._write("error", logs);
};
Logger.prototype._write = function (type, logs) {
var now = new DateTime_1.DateTime();
var config = (this._groupName && Logger._groupMap.get(this._groupName)) || {
consoleLogTypes: ["log", "info", "warn", "error"],
fileLogTypes: [],
outputPath: undefined,
historySize: 30
};
Logger.history.push({
groupName: this._groupName,
loggerName: this._name,
loggerId: this._id,
logType: type,
logs: logs,
loggedAtDateTime: now
});
Logger.history = Logger.history.slice(0, config.historySize);
var convertedLogs = logs.map(function (log) {
if (typeof log === "string") {
return log.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, "");
}
else if (log instanceof Error) {
return log.stack;
}
return log;
});
if (config.consoleLogTypes.includes(type)) {
var text = "[%c" + now.toFormatString("yyMMdd HH:mm:ss.fff") + "%c] ";
text += "[%c" + this._id.toString().padStart(4, "0") + "%c] ";
text += "[%c" + this._groupName + "%c] ";
text += "[%c" + this._name + "%c] %c%s%c";
if (process.versions.node) {
var colors = {
log: 0,
info: 36,
warn: 33,
error: 31
};
console.log.apply(console, [
text.replace(/%c/g, "%s"),
"\u001B[90m",
"\u001B[0m",
"\u001B[90m",
"\u001B[0m",
"\u001B[0m",
"\u001B[0m",
"\u001B[" + colors.warn + "m",
"\u001B[0m",
"\u001B[" + colors[type] + "m",
convertedLogs[0],
"\x1b[0m"
].concat(convertedLogs.slice(1)));
}
else {
var colors = {
log: "black",
info: "#2196F3",
warn: "#FF9800",
error: "#F44336"
};
console.log.apply(console, [
text,
"color: grey;",
"color: black;",
"color: grey;",
"color: black;",
"color: black;",
"color: black;",
"\u001B[" + colors.warn + "m",
"\u001B[0m",
"color: " + colors[type] + ";",
convertedLogs[0],
"color: black;"
].concat(convertedLogs.slice(1)));
}
}
if (config.fileLogTypes.includes(type)) {
if (!process.versions.node) {
throw new Error("웹에서는 파일 로그를 사용할 수 없습니다.");
}
config.outputPath = config.outputPath || path.resolve(process.cwd(), "logs");
var text = "[" + type.toUpperCase().padEnd(5, " ") + "] ";
text += "[" + now.toFormatString("yyMMdd HH:mm:ss.fff") + "] ";
text += "[" + this._id.toString().padStart(4, "0") + "] ";
text += "[" + this._groupName + ": " + this._name + "] " + convertedLogs.join("\n");
try {
fs.mkdirsSync(config.outputPath);
var filePath = path.resolve(config.outputPath, "logs-" + new DateTime_1.DateTime().toFormatString("yyyyMMdd") + ".log");
if (fs.existsSync(filePath)) {
fs.appendFileSync(filePath, text + "\r\n", "utf8");
}
else {
fs.writeFileSync(filePath, text + "\r\n", "utf8");
}
}
catch (e) {
console.error(e);
throw e;
}
}
};
Logger.history = [];
Logger._groupMap = new Map();
Logger._lastId = 0;
return Logger;
}());
exports.Logger = Logger;
/***/ }),
/***/ "fs-extra":
/*!***************************!*\
!*** external "fs-extra" ***!
\***************************/
/*! no static exports found */
/***/ (function(module, exports) {
module.exports = require("fs-extra");
/***/ }),
/***/ "path":
/*!***********************!*\
!*** external "path" ***!
\***********************/
/*! no static exports found */
/***/ (function(module, exports) {
module.exports = require("path");
/***/ })
/******/ });
});
require("./extensions/ArrayExtensions");
require("./extensions/ObjectConstructorExtensions");
__export(require("./exceptions/Exception"));
__export(require("./exceptions/InvalidArgumentsException"));
__export(require("./exceptions/NotImplementedException"));
__export(require("./types/DateOnly"));
__export(require("./types/DateTime"));
__export(require("./types/Time"));
__export(require("./types/Type"));
__export(require("./types/Uuid"));
__export(require("./utils/JsonConvert"));
__export(require("./utils/LambdaParser"));
__export(require("./utils/Logger"));
__export(require("./utils/Wait"));
//# sourceMappingURL=index.js.map

@@ -0,17 +1,38 @@

import { DateOnly } from "./DateOnly";
import { Time } from "./Time";
export declare class DateTime {
private _date;
private readonly _date;
constructor();
constructor(value: number);
constructor(value: string);
constructor(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, milliseconds?: number);
getFullYear(): number;
getMonth(): number;
getDate(): number;
getHours(): number;
getMinutes(): number;
getSeconds(): number;
getMilliseconds(): number;
getTimezoneOffset(): number;
getDay(): number;
constructor(tick: number);
constructor(year: number, month: number, date?: number, hour?: number, minute?: number, second?: number, millisecond?: number);
constructor(date: Date);
static parse(value: string): DateTime;
readonly timezoneOffset: number;
year: number;
month: number;
day: number;
readonly week: number;
hour: number;
minute: number;
second: number;
millisecond: number;
tick: number;
setYear(year: number): DateTime;
setMonth(month: number): DateTime;
setDay(day: number): DateTime;
setHour(hour: number): DateTime;
setMinute(minute: number): DateTime;
setSecond(second: number): DateTime;
setMillisecond(millisecond: number): DateTime;
addYears(years: number): DateTime;
addMonths(months: number): DateTime;
addDays(days: number): DateTime;
addHours(hours: number): DateTime;
addMinutes(minutes: number): DateTime;
addSeconds(seconds: number): DateTime;
addMilliseconds(milliseconds: number): DateTime;
toDateOnly(): DateOnly;
toTime(): Time;
toFormatString(format: string): string;
toString(): string;
}
export declare class Uuid {
private readonly _uuid;
constructor();
constructor(uuid: string);
static newUuid(): Uuid;
toString(): string;
}
import { DateTime } from "../types/DateTime";
export declare class Logger {
private readonly _groupName;
private readonly _name;
static history: ILoggerHistory[];
static setGroupConfig(groupName: string, config?: Partial<ILoggerConfig>): void;
private static _groupMap;
private static readonly _groupMap;
private static _lastId;
private readonly _groupName;
private readonly _name;
private static _defaultConfig;
private readonly _id;
constructor(groupName: string, name: string | object);
constructor(_groupName: string, _name: string);
static setDefaultConfig(config: Partial<ILoggerConfig>): void;
static setGroupConfig(groupName: string, config?: Partial<ILoggerConfig>): void;
log(...logs: any[]): void;

@@ -15,7 +17,8 @@ info(...logs: any[]): void;

error(...logs: any[]): void;
private _write(type, logs);
private _write(severity, logs);
private readonly _config;
}
export interface ILoggerConfig {
consoleLogTypes: LoggerTypeString[];
fileLogTypes: LoggerTypeString[];
consoleLogSeverities: LoggerSeverityString[];
fileLogSeverities: LoggerSeverityString[];
outputPath: string | undefined;

@@ -26,8 +29,15 @@ historySize: number;

groupName: string | undefined;
loggerId: number;
loggerName: string | undefined;
loggerId: number;
logType: LoggerTypeString;
logs: any[];
severity: LoggerSeverityString;
messages: any[];
loggedAtDateTime: DateTime;
}
export declare type LoggerTypeString = "log" | "info" | "warn" | "error";
export interface ILogColors {
grey: string;
log: string;
info: string;
warn: string;
error: string;
}
export declare type LoggerSeverityString = "log" | "info" | "warn" | "error";
{
"name": "@simplism/core",
"version": "6.0.52",
"version": "7.0.1",
"description": "Simplism Core Package",
"repository": "github:kslhunter/simplism6",
"repository": "github:kslhunter/simplism",
"author": "kslhunter",

@@ -7,0 +7,0 @@ "license": "MIT",

import {Type} from "../types/Type";
export class Exception extends Error {
public constructor(message: string, constructorOpt?: Type<any>) {
super(message);
Object.setPrototypeOf(this, new.target.prototype);
this.name = new.target.name;
this.message = message;
Error.captureStackTrace(this, constructorOpt || new.target);
}
}
public code?: string;
public constructor(message: string = "", code?: string, constructorOpt?: Type<any>) {
super(message);
Object.setPrototypeOf(this, new.target.prototype);
this.name = new.target.name;
this.message = message;
this.code = code;
Error.captureStackTrace(this, constructorOpt || new.target);
}
}
import {Exception} from "./Exception";
export class NotImplementedException extends Exception {
public constructor(message?: string) {
super(`아직 구현되지 않았습니다. [${message}]`);
}
public constructor() {
super(`아직 구현되지 않았습니다`);
}
}

@@ -1,22 +0,285 @@

declare interface Array<T> {
mapMany<R>(predicate: (item: T, index: number) => R[]): R[];
import {Type} from "../types/Type";
import {Exception} from "../exceptions/Exception";
import {JsonConvert} from "../utils/JsonConvert";
declare global {
// tslint:disable-next-line:interface-name
interface Array<T> {
groupBy<K>(keySelector: (item: T, index: number) => K): { key: K; values: T[] }[];
groupBy<K, V>(keySelector: (item: T, index: number) => K, valueSelector: (item: T, index: number) => V): { key: K; values: V[] }[];
toMap<K>(keySelector: (item: T, index: number) => K): Map<K, T>;
toMap<K, V>(keySelector: (item: T, index: number) => K, valueSelector: (item: T, index: number) => V): Map<K, V>;
mapMany<R>(selector?: (item: T, index: number) => R[]): R[];
single(predicate?: (item: T, index: number) => boolean): T | undefined;
last(predicate?: (item: T, index: number) => boolean): T | undefined;
sum(): T | undefined;
sum<P extends NonNullable<any>>(selector: (item: T) => P): P | undefined;
max(): T | undefined;
max<P extends NonNullable<any>>(selector: (item: T) => P): P | undefined;
min(): T | undefined;
min<P extends NonNullable<any>>(selector: (item: T) => P): P | undefined;
distinct(): T[];
orderBy(selector?: (item: T) => any, desc?: boolean): T[];
pushRange(items: T[]): void;
insert(index: number, item: T): void;
remove(item: T): void;
remove(items: T[]): void;
remove(predicate: (item: T, index: number) => boolean): void;
filterExists(): NonNullable<T>[];
ofType<N>(type: Type<N>): N[];
diffs<K extends keyof T>(target: T[], options?: { keyProps?: K[] }): { source?: T; target?: T }[];
merge<K extends keyof T>(target: Partial<T>[], options?: { keyProps?: K[]; replacement?: boolean }): void;
}
}
Array.prototype.mapMany = function (predicate: (item: any, index: number) => any[]): any[] {
return this.length > 0 ? this.map(predicate).reduce((p: any, n: any) => p.concat(n)) : [];
Array.prototype.groupBy = function (keySelector: (item: any, index: number) => any, valueSelector?: (item: any, index: number) => any): { key: any; values: any[] }[] {
const result: { key: any; values: any[] }[] = [];
for (let i = 0; i < this.length; i++) {
const key = keySelector(this[i], i);
const value = valueSelector ? valueSelector(this[i], i) : this[i];
const existsRecord = result.single(item => Object.equal(item.key, key));
if (existsRecord) {
existsRecord.values.push(value);
}
else {
result.push({key, values: [value]});
}
}
return result;
};
Array.prototype.toMap = function (keySelector: (item: any, index: number) => any, valueSelector?: (item: any, index: number) => any): Map<any, any> {
const result = new Map<string, any>();
for (let i = 0; i < this.length; i++) {
const item = this[i];
const key = keySelector(item, i);
const value = valueSelector ? valueSelector(item, i) : item;
if (result.has(key)) {
throw new Exception(`키가 중복되었습니다. (중복된키: ${JsonConvert.stringify(key)})`);
}
result.set(key, value);
}
return result;
};
Array.prototype.mapMany = function (selector?: (item: any, index: number) => any[]): any[] {
if (this.length < 1) return [];
return (selector ? this.map(selector) : this).reduce((p: any, n: any) => p.concat(n));
};
Array.prototype.single = function (predicate?: (item: any, index: number) => boolean): any {
const filtered = predicate ? this.filter(predicate.bind(this)) : this;
if (filtered.length > 1) {
throw new Error(`복수의 결과물이 있습니다.`);
}
return filtered[0];
};
Array.prototype.last = function (predicate?: (item: any, index: number) => boolean): any {
if (predicate) {
for (let i = this.length - 1; i >= 0; i--) {
if (predicate(this[i], i)) {
return this[i];
}
}
if (predicate) {
for (let i = this.length - 1; i >= 0; i--) {
if (predicate(this[i], i)) {
return this[i];
}
}
}
else {
return this[this.length - 1];
}
};
Array.prototype.sum = function (selector?: (item: any) => any): any {
let result;
for (let item of this) {
item = selector ? selector(item) : item;
if (result) {
result += item;
}
else {
return this[this.length - 1];
result = item;
}
};
}
return result;
};
Array.prototype.max = function (selector?: (item: any) => any): any {
let result;
for (let item of this) {
item = selector ? selector(item) : item;
if (!result || result < item) {
result = item;
}
}
return result;
};
Array.prototype.min = function (selector?: (item: any) => any): any {
let result;
for (let item of this) {
item = selector ? selector(item) : item;
if (!result || result > item) {
result = item;
}
}
return result;
};
Array.prototype.distinct = function (): any[] {
const result: any[] = [];
for (const item of this) {
if (result.every(item1 => !Object.equal(item1, item))) {
result.push(item);
}
}
return result;
};
Array.prototype.orderBy = function (selector?: (item: any) => any, desc?: boolean): any[] {
return this.concat().sort((p: any, n: any) => {
const pn = selector ? selector(n) : n;
const pp = selector ? selector(p) : p;
return desc
? pn < pp ? -1 : pn > pp ? 1 : 0
: pn > pp ? -1 : pn < pp ? 1 : 0;
});
};
Array.prototype.pushRange = function (items: any[]): void {
for (const item of items) {
this.push(item);
}
};
Array.prototype.insert = function (index: number, item: any): void {
this.splice(index, 0, item);
};
Array.prototype.remove = function (arg: any): void {
const items = typeof arg === "function" ? this.filter(arg)
? arg instanceof Array : arg
: [arg];
for (const item of items) {
const index = this.indexOf(item);
if (index > -1) this.splice(index, 1);
}
};
Array.prototype.filterExists = function (): any[] {
return this.filter(item => item);
};
Array.prototype.ofType = function <N>(type: Type<N>): N[] {
return this.filter(item => item instanceof type);
};
Array.prototype.diffs = function (target: any[], options?: { keyProps?: string[] }): { source?: any; target?: any }[] {
if (target.length < 1) {
return this.map(item => ({source: item}));
}
const result = [];
const currTarget = ([] as any[]).concat(target);
for (const item of this) {
const existsTargetItem = currTarget.find(targetItem => {
if (options && options.keyProps) {
return options.keyProps.every(keyProp => targetItem[keyProp] === item[keyProp]);
}
else {
return Object.equal(targetItem, item);
}
});
// 추가됨
if (!existsTargetItem) {
result.push({source: item});
}
else {
// 수정됨
if (options && options.keyProps && !Object.equal(item, existsTargetItem)) {
result.push({source: item, target: existsTargetItem});
}
currTarget.remove(existsTargetItem);
}
}
for (const remainedTargetItem of currTarget) {
// 삭제됨
result.push({target: remainedTargetItem});
}
return result;
};
Array.prototype.merge = function (target: any[], options?: { keyProps?: string[]; replacement?: boolean }): void {
if (!options || !options.keyProps) {
this.forEach((item, i) => {
if (options && options.replacement) {
for (const key of Object.keys(item)) {
delete item[key];
}
}
Object.assign(item, target[i]);
});
if (target.length > this.length) {
for (const targetItem of target.splice(this.length)) {
this.push(targetItem);
}
}
}
else {
for (const targetItem of target) {
const item = this.single(sourceItem => options.keyProps!.every(keyProp => sourceItem[keyProp] === targetItem[keyProp]));
if (item) {
if (options && options.replacement) {
for (const key of Object.keys(item)) {
delete item[key];
}
}
Object.assign(item, targetItem);
}
else {
this.push(targetItem);
}
}
}
};
import "./extensions/ArrayExtensions";
import "./extensions/ObjectConstructorExtensions";
export * from "./exceptions/ArgumentsException";
export * from "./exceptions/Exception";
export * from "./exceptions/InvalidArgumentsException";
export * from "./exceptions/NotImplementedException";
export * from "./types/DateOnly";
export * from "./types/DateTime";
export * from "./types/Time";
export * from "./types/Type";
export * from "./types/Uuid";
export * from "./utils/Logger";
export * from "./utils/JsonConvert";
export * from "./utils/LambdaParser";
export * from "./utils/Logger";
export * from "./utils/Wait";

@@ -1,118 +0,240 @@

import {ArgumentsException} from "../exceptions/ArgumentsException";
import {InvalidArgumentsException} from "../exceptions/InvalidArgumentsException";
import {DateOnly} from "./DateOnly";
import {Time} from "./Time";
export class DateTime {
private _date: Date;
private readonly _date: Date;
public constructor();
public constructor(value: number);
public constructor(value: string);
public constructor(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, milliseconds?: number);
public constructor(...args: any[]) {
if (args.length === 0) this._date = new Date();
else if (args.length === 1) this._date = new Date(args[0]);
else if (args.length === 2) this._date = new Date(args[0], args[1]);
else if (args.length === 3) this._date = new Date(args[0], args[1], args[2]);
else if (args.length === 4) this._date = new Date(args[0], args[1], args[2], args[3]);
else if (args.length === 5) this._date = new Date(args[0], args[1], args[2], args[3], args[4]);
else if (args.length === 6) this._date = new Date(args[0], args[1], args[2], args[3], args[4], args[5]);
else if (args.length === 7) this._date = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
else throw new ArgumentsException({args});
public constructor();
public constructor(tick: number);
public constructor(year: number, month: number, date?: number, hour?: number, minute?: number, second?: number, millisecond?: number);
public constructor(date: Date);
public constructor(args1?: number | Date, args2?: number, args3?: number, args4?: number, args5?: number, args6?: number, args7?: number) {
if (args1 === undefined) {
this._date = new Date(new Date().getTime());
}
public getFullYear(): number {
return this._date.getFullYear();
else if (typeof args1 === "number" && args2 === undefined) {
this._date = new Date(args1);
}
public getMonth(): number {
return this._date.getMonth();
else if (typeof args1 === "number" && args2 !== undefined) {
this._date = new Date(args1, args2 - 1, args3, args4, args5, args6, args7);
}
public getDate(): number {
return this._date.getDate();
else if (args1 instanceof Date) {
this._date = new Date(args1.getTime());
}
public getHours(): number {
return this._date.getHours();
else {
throw new InvalidArgumentsException({args: [args1, args2, args3, args4, args5, args6, args7]});
}
}
public getMinutes(): number {
return this._date.getMinutes();
public static parse(value: string): DateTime {
const parsedTick = Date.parse(value) as any;
if (typeof parsedTick === "number") {
return new DateTime(parsedTick);
}
throw new InvalidArgumentsException({value});
}
public getSeconds(): number {
return this._date.getSeconds();
}
public get timezoneOffset(): number {
return this._date.getTimezoneOffset();
}
public getMilliseconds(): number {
return this._date.getMilliseconds();
}
public get year(): number {
return this._date.getFullYear();
}
public getTimezoneOffset(): number {
return this._date.getTimezoneOffset();
}
public set year(year: number) {
this._date.setFullYear(year);
}
public getDay(): number {
return this._date.getDay();
}
public get month(): number {
return this._date.getMonth() + 1;
}
public toFormatString(format: string): string {
const year = this.getFullYear();
const month = this.getMonth() + 1;
const day = this.getDate();
const hour = this.getHours();
const minute = this.getMinutes();
const second = this.getSeconds();
const milliSecond = this.getMilliseconds();
const offsetHour = -Math.floor(this.getTimezoneOffset() / 60);
const offsetMinute = -this.getTimezoneOffset() % 60;
public set month(month: number) {
this._date.setMonth(month - 1);
}
const weekString =
this.getDay() === 0 ? "일" :
this.getDay() === 1 ? "월" :
this.getDay() === 2 ? "화" :
this.getDay() === 3 ? "수" :
this.getDay() === 4 ? "목" :
this.getDay() === 5 ? "금" :
this.getDay() === 6 ? "토" :
"";
public get day(): number {
return this._date.getDate();
}
let result = format;
result = result.replace(/yyyy/g, year.toString());
result = result.replace(/yyy/g, year.toString().substr(1, 3));
result = result.replace(/yy/g, year.toString().substr(2, 2));
result = result.replace(/y/g, year.toString().substr(3, 1));
public set day(day: number) {
this._date.setMonth(day - 1);
}
result = result.replace(/MM/g, month.toString().padStart(2, "0"));
result = result.replace(/M/g, month.toString());
public get week(): number {
return this._date.getDay();
}
result = result.replace(/dddd/g, `${weekString}요일`);
result = result.replace(/ddd/g, weekString);
public get hour(): number {
return this._date.getHours();
}
result = result.replace(/dd/g, day.toString().padStart(2, "0"));
result = result.replace(/d/g, day.toString());
public set hour(hour: number) {
this._date.setHours(hour);
}
result = result.replace(/tt/g, hour < 12 ? "오전" : "오후");
public get minute(): number {
return this._date.getMinutes();
}
result = result.replace(/hh/g, (hour % 12).toString().padStart(2, "0"));
result = result.replace(/h/g, (hour % 12).toString());
public set minute(minute: number) {
this._date.setMinutes(minute);
}
result = result.replace(/HH/g, hour.toString().padStart(2, "0"));
result = result.replace(/H/g, hour.toString());
public get second(): number {
return this._date.getSeconds();
}
result = result.replace(/mm/g, minute.toString().padStart(2, "0"));
result = result.replace(/m/g, minute.toString());
public set second(second: number) {
this._date.setSeconds(second);
}
result = result.replace(/ss/g, second.toString().padStart(2, "0"));
result = result.replace(/s/g, second.toString());
public get millisecond(): number {
return this._date.getMilliseconds();
}
result = result.replace(/fff/g, milliSecond.toString().padStart(3, "0"));
result = result.replace(/ff/g, milliSecond.toString().padStart(3, "0").substr(0, 2));
result = result.replace(/f/g, milliSecond.toString().padStart(3, "0").substr(0, 1));
public set millisecond(millisecond: number) {
this._date.setMilliseconds(millisecond);
}
result = result.replace(/zzz/g, `${offsetHour > 0 ? "+" : "-"}${Math.abs(offsetHour).toString().padStart(2, "0")}:${Math.abs(offsetMinute).toString().padStart(2, "0")}`);
result = result.replace(/zz/g, (offsetHour > 0 ? "+" : "-") + Math.abs(offsetHour).toString().padStart(2, "0"));
result = result.replace(/z/g, (offsetHour > 0 ? "+" : "-") + Math.abs(offsetHour).toString());
public get tick(): number {
return this._date.getTime();
}
return result;
}
public set tick(tick: number) {
this._date.setTime(tick);
}
public setYear(year: number): DateTime {
return new DateTime(new Date(this.tick).setFullYear(year));
}
public setMonth(month: number): DateTime {
return new DateTime(new Date(this.tick).setMonth(month - 1));
}
public setDay(day: number): DateTime {
return new DateTime(new Date(this.tick).setDate(day));
}
public setHour(hour: number): DateTime {
return new DateTime(new Date(this.tick).setHours(hour));
}
public setMinute(minute: number): DateTime {
return new DateTime(new Date(this.tick).setMinutes(minute));
}
public setSecond(second: number): DateTime {
return new DateTime(new Date(this.tick).setSeconds(second));
}
public setMillisecond(millisecond: number): DateTime {
return new DateTime(new Date(this.tick).setMilliseconds(millisecond));
}
public addYears(years: number): DateTime {
return this.setYear(this.year + years);
}
public addMonths(months: number): DateTime {
return this.setMonth(this.month + months);
}
public addDays(days: number): DateTime {
return this.setDay(this.day + days);
}
public addHours(hours: number): DateTime {
return this.setHour(this.hour + hours);
}
public addMinutes(minutes: number): DateTime {
return this.setMinute(this.minute + minutes);
}
public addSeconds(seconds: number): DateTime {
return this.setSecond(this.second + seconds);
}
public addMilliseconds(milliseconds: number): DateTime {
return this.setMillisecond(this.millisecond + milliseconds);
}
public toDateOnly(): DateOnly {
return new DateOnly(this._date);
}
public toTime(): Time {
return new Time(this._date);
}
public toFormatString(format: string): string {
const year = this.year;
const month = this.month;
const day = this.day;
const hour = this.hour;
const minute = this.minute;
const second = this.second;
const millisecond = this.millisecond;
const offsetHour = -Math.floor(this.timezoneOffset / 60);
const offsetMinute = -this.timezoneOffset % 60;
const weekString =
this.week === 0 ? "일" :
this.week === 1 ? "월" :
this.week === 2 ? "화" :
this.week === 3 ? "수" :
this.week === 4 ? "목" :
this.week === 5 ? "금" :
this.week === 6 ? "토" :
"";
let result = format;
result = result.replace(/yyyyy/g, year.toString() + "년");
result = result.replace(/yyyy/g, year.toString());
result = result.replace(/yyy/g, year.toString().substr(1, 3));
result = result.replace(/yy/g, year.toString().substr(2, 2));
result = result.replace(/y/g, year.toString().substr(3, 1));
result = result.replace(/MMM/g, month.toString().padStart(2, "0") + "월");
result = result.replace(/MM/g, month.toString().padStart(2, "0"));
result = result.replace(/M/g, month.toString());
result = result.replace(/dddd/g, `${weekString}요일`);
result = result.replace(/ddd/g, weekString);
result = result.replace(/dd/g, day.toString().padStart(2, "0"));
result = result.replace(/d/g, day.toString());
result = result.replace(/tt/g, hour < 12 ? "오전" : "오후");
result = result.replace(/hh/g, (hour % 12).toString().padStart(2, "0"));
result = result.replace(/h/g, (hour % 12).toString());
result = result.replace(/HH/g, hour.toString().padStart(2, "0"));
result = result.replace(/H/g, hour.toString());
result = result.replace(/mm/g, minute.toString().padStart(2, "0"));
result = result.replace(/m/g, minute.toString());
result = result.replace(/ss/g, second.toString().padStart(2, "0"));
result = result.replace(/s/g, second.toString());
result = result.replace(/fff/g, millisecond.toString().padStart(3, "0"));
result = result.replace(/ff/g, millisecond.toString().padStart(3, "0").substr(0, 2));
result = result.replace(/f/g, millisecond.toString().padStart(3, "0").substr(0, 1));
result = result.replace(/zzz/g, (offsetHour > 0 ? "+" : "-") + Math.abs(offsetHour).toString().padStart(2, "0") + ":" + Math.abs(offsetMinute).toString().padStart(2, "0"));
result = result.replace(/zz/g, (offsetHour > 0 ? "+" : "-") + Math.abs(offsetHour).toString().padStart(2, "0"));
result = result.replace(/z/g, (offsetHour > 0 ? "+" : "-") + Math.abs(offsetHour).toString());
return result;
}
public toString(): string {
return this.toFormatString("yyyy-MM-ddTHH:mm:ss.fffZzzz");
}
}
export declare const Type: FunctionConstructor;
// tslint:disable-next-line:interface-name
export interface Type<T> extends Function {
new(...args: any[]): T;
new(...args: any[]): T;
}
export class Uuid {
private readonly _uuid: string;
private readonly _uuid: string;
public constructor() {
this._uuid = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
const r = Math.random() * 16 | 0;
const v = c === "x" ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
public constructor(uuid: string) {
this._uuid = uuid;
}
public toString(): string {
return this._uuid;
}
}
public static newUuid(): Uuid {
const uuid = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, c => {
const r = Math.random() * 16 | 0;
const v = c === "x" ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
return new Uuid(uuid);
}
public toString(): string {
return this._uuid;
}
}

@@ -1,194 +0,172 @@

import * as fs from "fs-extra";
import * as path from "path";
import {DateTime} from "../types/DateTime";
export class Logger {
public static history: ILoggerHistory[] = [];
public static history: ILoggerHistory[] = [];
private static readonly _groupMap = new Map<string, ILoggerConfig>();
private static _lastId = 0;
public static setGroupConfig(groupName: string, config?: Partial<ILoggerConfig>): void {
this._groupMap.set(groupName, {
consoleLogTypes: ["log", "info", "warn", "error"],
fileLogTypes: [],
outputPath: undefined,
historySize: 30,
...config
});
}
private static _defaultConfig: ILoggerConfig = {
consoleLogSeverities: ["log", "info", "warn", "error"],
fileLogSeverities: [],
outputPath: undefined,
historySize: 30
};
private static _groupMap = new Map<string, ILoggerConfig>();
private static _lastId = 0;
private readonly _id: number;
private readonly _groupName: string;
private readonly _name: string;
private readonly _id: number;
public constructor(private readonly _groupName: string,
private readonly _name: string) {
Logger._lastId++;
this._id = Logger._lastId;
}
public constructor(groupName: string, name: string | object) {
this._groupName = groupName;
this._name = typeof name === "string" ? name : name.constructor.name;
public static setDefaultConfig(config: Partial<ILoggerConfig>): void {
this._defaultConfig = {
...this._defaultConfig,
...config
};
}
Logger._lastId++;
this._id = Logger._lastId;
public static setGroupConfig(groupName: string, config?: Partial<ILoggerConfig>): void {
if (this._groupMap.has(groupName)) {
const prevConfig = this._groupMap.get(groupName)!;
this._groupMap.set(groupName, {
...prevConfig,
...config
});
}
public log(...logs: any[]): void {
this._write("log", logs);
else {
this._groupMap.set(groupName, {
...Logger._defaultConfig,
...config
});
}
}
public info(...logs: any[]): void {
this._write("info", logs);
}
public log(...logs: any[]): void {
this._write("log", logs);
}
public warn(...logs: any[]): void {
this._write("warn", logs);
}
public info(...logs: any[]): void {
this._write("info", logs);
}
public error(...logs: any[]): void {
this._write("error", logs);
}
public warn(...logs: any[]): void {
this._write("warn", logs);
}
private _write(type: LoggerTypeString, logs: any[]): void {
const now = new DateTime();
public error(...logs: any[]): void {
this._write("error", logs);
}
// 설정 가져오기
const config = (this._groupName && Logger._groupMap.get(this._groupName)) || {
consoleLogTypes: ["log", "info", "warn", "error"],
fileLogTypes: [],
outputPath: undefined,
historySize: 30
} as ILoggerConfig;
private _write(severity: LoggerSeverityString, logs: any[]): void {
const now = new DateTime();
// 로그이력 등록
Logger.history.push({
groupName: this._groupName,
loggerName: this._name,
loggerId: this._id,
logType: type,
logs,
loggedAtDateTime: now
});
Logger.history = Logger.history.slice(0, config.historySize);
// 로그이력 등록
Logger.history.push({
groupName: this._groupName,
loggerId: this._id,
loggerName: this._name,
severity,
messages: logs,
loggedAtDateTime: now
});
Logger.history = Logger.history.slice(0, this._config.historySize);
// 로그 변환
const convertedLogs = logs.map((log) => {
// 색상있으면 색상 빼기
if (typeof log === "string") {
return log.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, "");
}
// 로그 변환
const convertedLogs = logs.map(item => {
// 색상있으면 색상 빼기
if (typeof item === "string") {
return item.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, "");
}
else if (item instanceof Error) {
return item.stack;
}
// 에러는 스택만 추출
else if (log instanceof Error) {
return log.stack;
}
return item;
});
return log;
});
const colors: ILogColors = process.env.TARGET === "browser"
? {
grey: "color: grey;",
log: "color: black;",
info: "color: #2196F3;",
warn: "color: #FF9800;",
error: "color: #F44336;"
}
: {
grey: "\x1b[90m",
log: "\x1b[0m",
info: "\x1b[36m",
warn: "\x1b[33m",
error: "\x1b[31m"
};
// 콘솔 출력
if (config.consoleLogTypes.includes(type)) {
let text = `[%c${now.toFormatString("yyMMdd HH:mm:ss.fff")}%c] `;
text += `[%c${this._id.toString().padStart(4, "0")}%c] `;
text += `[%c${this._groupName}%c] `;
text += `[%c${this._name}%c] %c%s%c`;
const log = {
id: this._id.toString(),
now: now.toFormatString("yyMMdd HH:mm:ss.fff"),
group: this._groupName,
name: this._name,
severity: severity.toUpperCase()
};
// Node.js
if (process.versions.node) {
const colors = {
log: 0,
info: 36,
warn: 33,
error: 31
};
let text = `${colors.grey}[${log.id}] ${log.now} - ${log.group} - ${log.name} - ${colors[severity]}${log.severity}: ${convertedLogs[0]}${colors.log}`;
if (convertedLogs.length > 1) {
text += "\r\n" + convertedLogs.slice(1).join("\r\n");
}
console.log.apply(console, [
text.replace(/%c/g, "%s"),
`\x1b[90m`,
`\x1b[0m`,
`\x1b[90m`,
`\x1b[0m`,
`\x1b[0m`,
`\x1b[0m`,
`\x1b[${colors.warn}m`,
`\x1b[0m`,
`\x1b[${colors[type]}m`,
convertedLogs[0],
"\x1b[0m"
].concat(convertedLogs.slice(1)));
}
// 콘솔 출력
if (this._config.consoleLogSeverities.includes(severity)) {
console.log(text);
}
// Browser
else {
const colors = {
log: "black",
info: "#2196F3",
warn: "#FF9800",
error: "#F44336"
};
// 파일 출력
if (this._config.fileLogSeverities.includes(severity)) {
const path = eval("require('path')"); //tslint:disable-line:no-eval
const fs = eval("require('fs')"); //tslint:disable-line:no-eval
console.log.apply(console, [
text,
`color: grey;`,
`color: black;`,
`color: grey;`,
`color: black;`,
`color: black;`,
`color: black;`,
`\x1b[${colors.warn}m`,
`\x1b[0m`,
`color: ${colors[type]};`,
convertedLogs[0],
"color: black;"
].concat(convertedLogs.slice(1)));
}
}
const outputPath = this._config.outputPath || path.resolve(process.cwd(), "logs");
if (!fs.existsSync(outputPath)) {
fs.mkdirSync(outputPath);
}
// 로그 파일 출력
if (config.fileLogTypes.includes(type)) {
if (!process.versions.node) {
throw new Error("웹에서는 파일 로그를 사용할 수 없습니다.");
}
const filePath = path.resolve(outputPath, `${now.toFormatString("yyyyMMdd-HH")}.log`);
if (fs.existsSync(filePath)) {
fs.appendFileSync(filePath, `${text}\r\n`, "utf8");
}
else {
fs.writeFileSync(filePath, `${text}\r\n`, "utf8");
}
}
}
config.outputPath = config.outputPath || path.resolve(process.cwd(), "logs");
let text = `[${type.toUpperCase().padEnd(5, " ")}] `;
text += `[${now.toFormatString("yyMMdd HH:mm:ss.fff")}] `;
text += `[${this._id.toString().padStart(4, "0")}] `;
text += `[${this._groupName}: ${this._name}] ${convertedLogs.join("\n")}`;
try {
fs.mkdirsSync(config.outputPath);
const filePath = path.resolve(
config.outputPath,
`logs-${new DateTime().toFormatString("yyyyMMdd")}.log`
);
if (fs.existsSync(filePath)) {
fs.appendFileSync(filePath, `${text}\r\n`, "utf8");
}
else {
fs.writeFileSync(filePath, `${text}\r\n`, "utf8");
}
} catch (e) {
console.error(e);
throw e;
}
}
}
private get _config(): ILoggerConfig {
return (this._groupName && Logger._groupMap.get(this._groupName)) || Logger._defaultConfig;
}
}
export interface ILoggerConfig {
consoleLogTypes: LoggerTypeString[];
fileLogTypes: LoggerTypeString[];
outputPath: string | undefined;
historySize: number;
consoleLogSeverities: LoggerSeverityString[];
fileLogSeverities: LoggerSeverityString[];
outputPath: string | undefined;
historySize: number;
}
export interface ILoggerHistory {
groupName: string | undefined;
loggerName: string | undefined;
loggerId: number;
logType: LoggerTypeString;
logs: any[];
loggedAtDateTime: DateTime;
groupName: string | undefined;
loggerId: number;
loggerName: string | undefined;
severity: LoggerSeverityString;
messages: any[];
loggedAtDateTime: DateTime;
}
export type LoggerTypeString = "log" | "info" | "warn" | "error";
export interface ILogColors {
grey: string;
log: string;
info: string;
warn: string;
error: string;
}
export type LoggerSeverityString = "log" | "info" | "warn" | "error";
{
"extends": "../../ts-configs/tsconfig.common.json",
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist"
"sourceMap": true,
"declaration": true,
"lib": [
"es2017"
],
"outDir": "dist"
},
"files": [
"./src/index.ts"
"src/index.ts"
]
}
{
"extends": "../../ts-configs/tslint.common.json"
}
"extends": "../../tslint.json"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc