diff --git a/hwe/ts/battle_simulator.ts b/hwe/ts/battle_simulator.ts index 6de0eb4f..920b7ce3 100644 --- a/hwe/ts/battle_simulator.ts +++ b/hwe/ts/battle_simulator.ts @@ -2,7 +2,7 @@ import $ from 'jquery'; import 'bootstrap'; import { DateTime } from 'luxon'; import download from 'downloadjs'; -import { unwrap } from './util'; +import { unwrap } from "./util/unwrap"; import { isInteger } from 'lodash'; import { combineArray, errUnknown, getNpcColor, isBrightColor, numberWithCommas } from './common_legacy'; import { unwrap_any } from './util/unwrap_any'; diff --git a/hwe/ts/chiefCenter.ts b/hwe/ts/chiefCenter.ts index 6cd78328..543d4196 100644 --- a/hwe/ts/chiefCenter.ts +++ b/hwe/ts/chiefCenter.ts @@ -4,7 +4,7 @@ import { range } from 'lodash'; import { DateTime } from 'luxon'; import { errUnknown, getNpcColor } from './common_legacy'; import { InvalidResponse } from './defs'; -import { unwrap } from './util'; +import { unwrap } from "./util/unwrap"; import { convertFormData } from './util/convertFormData'; import { unwrap_any } from "./util/unwrap_any"; diff --git a/hwe/ts/common_legacy.ts b/hwe/ts/common_legacy.ts index d03ffe21..3fbc72e7 100644 --- a/hwe/ts/common_legacy.ts +++ b/hwe/ts/common_legacy.ts @@ -1,4 +1,4 @@ -import { unwrap } from "./util"; +import { unwrap } from "./util/unwrap"; import jQuery from "jquery"; import 'bootstrap'; @@ -8,7 +8,7 @@ import axios from "axios"; axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; //TODO: X-Requested-With 믿지 말자. -/** +/** * <>& 등을 html에서도 그대로 보이도록 escape주는 함수 * @see https://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery */ @@ -121,7 +121,7 @@ export function convertSet(arr: ArrayLike): Record } -/** +/** * {0}, {1}, {2}형태로 포맷해주는 함수 */ @@ -199,8 +199,8 @@ export function linkifyStrWithOpt(text: string): string { /** * 단순한 Template 함수. <%변수명%>으로 template 가능 * @see https://github.com/krasimir/absurd/blob/master/lib/processors/html/helpers/TemplateEngine.js - * @param {string} html - * @param {object} options + * @param {string} html + * @param {object} options * @returns {string} */ export function TemplateEngine(html: string, options: Record = {}): string { @@ -332,7 +332,7 @@ export function nl2br(text: string): string { return text.replace(/\n/g, "
"); } /* -function br2nl (text) { +function br2nl (text) { return text.replace(/<\s*\/?br\s*[\/]?>/gi, '\n'); } */ diff --git a/hwe/ts/ext.plugin_troop.ts b/hwe/ts/ext.plugin_troop.ts index e514bc42..529537ae 100644 --- a/hwe/ts/ext.plugin_troop.ts +++ b/hwe/ts/ext.plugin_troop.ts @@ -1,5 +1,6 @@ import axios from "axios"; -import { RuntimeError, unwrap } from "./util"; +import { unwrap } from "./util/unwrap"; +import { RuntimeError } from "./util/RuntimeError"; declare global { interface Window { @@ -46,7 +47,7 @@ export function launchTroopPlugin($: JQueryStatic): void { const rawData = response.data; try { - const $html = $(rawData); + const $html = $(rawData); const tmpUsers: JQuery = (() => { let tmpUsers = undefined; diff --git a/hwe/ts/inheritPoint.ts b/hwe/ts/inheritPoint.ts index ae10b6dd..f63b1713 100644 --- a/hwe/ts/inheritPoint.ts +++ b/hwe/ts/inheritPoint.ts @@ -1,9 +1,9 @@ import "../scss/inheritPoint.scss"; import { sum } from "lodash"; -import { unwrap } from "./util"; +import { unwrap } from "./util/unwrap"; declare global { - interface Window { + interface Window { formStart: ()=>void; items: {[name: string]:number}; helpText: {[name: string]:string}; diff --git a/hwe/ts/map.ts b/hwe/ts/map.ts index c7e2800f..a11bafd9 100644 --- a/hwe/ts/map.ts +++ b/hwe/ts/map.ts @@ -3,7 +3,7 @@ import $ from 'jquery'; import { extend, isNumber } from 'lodash'; import { convColorValue, convertDictById, convertSet } from './common_legacy'; import { InvalidResponse } from './defs'; -import { unwrap } from './util'; +import { unwrap } from "./util/unwrap"; import { convertFormData } from './util/convertFormData'; declare const serverNick: string; diff --git a/hwe/ts/processing.ts b/hwe/ts/processing.ts index c960129b..424176b7 100644 --- a/hwe/ts/processing.ts +++ b/hwe/ts/processing.ts @@ -7,7 +7,7 @@ import { convertFormData } from './util/convertFormData'; import { InvalidResponse } from './defs'; import { unwrap_any } from './util/unwrap_any'; import { DataFormat, IdTextPair, OptionData } from 'select2'; -import { unwrap } from './util'; +import { unwrap } from "./util/unwrap"; declare const isChiefTurn: boolean; declare global { diff --git a/hwe/ts/util.ts b/hwe/ts/util.ts deleted file mode 100644 index f1b3bc07..00000000 --- a/hwe/ts/util.ts +++ /dev/null @@ -1,35 +0,0 @@ -type ErrType = { new(msg?: string): T } -export type Nullable = T | null | undefined - -export class RuntimeError extends Error { - public name = 'RuntimeError'; - constructor(public message: string = '') { - super(message); - } - toString(): string { - if (this.message) { - return this.name + ': ' + this.message; - } - else { - return this.name; - } - } -} - -export class NotNullExpected extends RuntimeError { - public name = 'NotNullExpected'; -} - -export function unwrap(result: Nullable): T { - if (result === null || result === undefined) { - throw new NotNullExpected(); - } - return result; -} - -export function unwrap_err(result: Nullable, errType: ErrType, errMsg?: string): T { - if (result === null || result === undefined) { - throw new errType(errMsg); - } - return result; -} \ No newline at end of file diff --git a/hwe/ts/util/NotNullExpected.ts b/hwe/ts/util/NotNullExpected.ts new file mode 100644 index 00000000..1ea17d1b --- /dev/null +++ b/hwe/ts/util/NotNullExpected.ts @@ -0,0 +1,4 @@ + +export class NotNullExpected extends TypeError { + public name = 'NotNullExpected'; +} diff --git a/hwe/ts/util/Nullable.ts b/hwe/ts/util/Nullable.ts new file mode 100644 index 00000000..164a7056 --- /dev/null +++ b/hwe/ts/util/Nullable.ts @@ -0,0 +1 @@ +export type Nullable = T | null | undefined; diff --git a/hwe/ts/util/RuntimeError.ts b/hwe/ts/util/RuntimeError.ts new file mode 100644 index 00000000..59920289 --- /dev/null +++ b/hwe/ts/util/RuntimeError.ts @@ -0,0 +1,14 @@ +export class RuntimeError extends Error { + public name = 'RuntimeError'; + constructor(public message: string = '') { + super(message); + } + toString(): string { + if (this.message) { + return this.name + ': ' + this.message; + } + else { + return this.name; + } + } +} diff --git a/hwe/ts/util/unwrap.ts b/hwe/ts/util/unwrap.ts new file mode 100644 index 00000000..68c1936f --- /dev/null +++ b/hwe/ts/util/unwrap.ts @@ -0,0 +1,9 @@ +import { Nullable } from "./Nullable"; +import { NotNullExpected } from "./NotNullExpected"; + +export function unwrap(result: Nullable): T { + if (result === null || result === undefined) { + throw new NotNullExpected(); + } + return result; +} diff --git a/hwe/ts/util/unwrap_any.ts b/hwe/ts/util/unwrap_any.ts index ece83c39..70d343c8 100644 --- a/hwe/ts/util/unwrap_any.ts +++ b/hwe/ts/util/unwrap_any.ts @@ -1,4 +1,5 @@ -import { Nullable, NotNullExpected } from "../util"; +import { Nullable } from "./Nullable"; +import { NotNullExpected } from "./NotNullExpected"; export function unwrap_any(result: Nullable): T { diff --git a/hwe/ts/util/unwrap_err.ts b/hwe/ts/util/unwrap_err.ts new file mode 100644 index 00000000..eee98384 --- /dev/null +++ b/hwe/ts/util/unwrap_err.ts @@ -0,0 +1,10 @@ +import { Nullable } from "./Nullable"; + +type ErrType = { new(msg?: string): T } + +export function unwrap_err(result: Nullable, errType: ErrType, errMsg?: string): T { + if (result === null || result === undefined) { + throw new errType(errMsg); + } + return result; +} diff --git a/ts/user_info.ts b/ts/user_info.ts index bb718633..352440f6 100644 --- a/ts/user_info.ts +++ b/ts/user_info.ts @@ -7,7 +7,7 @@ import { DATE_TIME_FORMAT, getDateTimeNow } from "../hwe/ts/util/getDateTimeNow" import { sha512 } from "js-sha512"; import { convertFormData } from "../hwe/ts/util/convertFormData"; import { InvalidResponse } from "../hwe/ts/defs"; -import { unwrap } from "./util"; +import { unwrap } from "../hwe/ts/util/unwrap"; type ResultUserInfo = { result: true, diff --git a/ts/util.ts b/ts/util.ts deleted file mode 100644 index 99a04ab5..00000000 --- a/ts/util.ts +++ /dev/null @@ -1,35 +0,0 @@ -type ErrType = { new(msg?: string): T } -type Nullable = T | null | undefined - -export class RuntimeError extends Error { - public name = 'RuntimeError'; - constructor(public message: string = '') { - super(message); - } - toString(): string { - if (this.message) { - return this.name + ': ' + this.message; - } - else { - return this.name; - } - } -} - -export class NotNullExpected extends RuntimeError { - public name = 'NotNullExpected'; -} - -export function unwrap(result: Nullable): T { - if (result === null || result === undefined) { - throw new NotNullExpected(); - } - return result; -} - -export function unwrap_err(result: Nullable, errType: ErrType, errMsg?: string): T { - if (result === null || result === undefined) { - throw new errType(errMsg); - } - return result; -} \ No newline at end of file