@daeryun/dr_components 0.1.9 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/lib/utils.js CHANGED
@@ -1,105 +1,118 @@
1
- /**
2
- *
3
- * <pre>
4
- * utils.ts
5
- * 수정일 수정자 수정내용
6
- * -------------------------------------------------
7
- * 2022-08-16 최초생성
8
- * </pre>
9
- * @author sbpark
10
- * @since 2022-08-16
11
- * @version 1.0
12
- *
13
- * Copyright (C) by DeaRyunLaw All right Preserved.
14
- */
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
15
10
  export function htmlTagRemove(str) {
16
- if (str === "")
17
- return "";
11
+ if (str === '')
12
+ return '';
18
13
  const removeMd = require('remove-markdown');
19
14
  str = removeMd(str);
20
15
  return str
21
- .replace(/<br\/>/gi, "\n")
22
- .replace(/<(\/)?([a-zA-Z]*)(\s[a-zA-Z]*=[^>]*)?(\s)*(\/)?>/gi, "")
23
- .replace(/&amp;/g, "&")
24
- .replace(/&lt;/g, "<")
25
- .replace(/&gt;/g, ">")
16
+ .replace(/<br\/>/gi, '\n')
17
+ .replace(/<(\/)?([a-zA-Z]*)(\s[a-zA-Z]*=[^>]*)?(\s)*(\/)?>/gi, '')
18
+ .replace(/&amp;/g, '&')
19
+ .replace(/&lt;/g, '<')
20
+ .replace(/&gt;/g, '>')
26
21
  .replace(/&quot;/g, '"')
27
22
  .replace(/&#039;/g, "'")
28
23
  .replace(/&#39;/g, "'")
29
- .replace(/&nbsp;/g, " ");
24
+ .replace(/&nbsp;/g, ' ');
30
25
  }
31
26
  export function htmlUrlDecode(str) {
32
- if (str === "")
33
- return "";
27
+ if (str === '')
28
+ return '';
34
29
  return str
35
- .replace(/&amp;/g, "&")
36
- .replace(/&lt;/g, "<")
37
- .replace(/&gt;/g, ">")
30
+ .replace(/&amp;/g, '&')
31
+ .replace(/&lt;/g, '<')
32
+ .replace(/&gt;/g, '>')
38
33
  .replace(/&quot;/g, '"')
39
34
  .replace(/&#039;/g, "'")
40
35
  .replace(/&#39;/g, "'")
41
- .replace(/&nbsp;/g, " ");
36
+ .replace(/&nbsp;/g, ' ');
42
37
  }
43
38
  export function htmlUrlEncode(str) {
44
- if (str === "")
45
- return "";
39
+ if (str === '')
40
+ return '';
46
41
  return str
47
- .replace(new RegExp("&", 'g'), "&amp;")
48
- .replace(new RegExp("<", 'g'), "&lt;")
49
- .replace(new RegExp(">", 'g'), "&gt;")
50
- .replace(new RegExp('"', 'g'), "&quot;")
51
- .replace(new RegExp("'", 'g'), "&#039;")
52
- .replace(new RegExp("'", 'g'), "&#39;")
53
- .replace(new RegExp("\r\n", 'g'), " ")
54
- .replace(new RegExp("\n", 'g'), " ");
42
+ .replace(new RegExp('&', 'g'), '&amp;')
43
+ .replace(new RegExp('<', 'g'), '&lt;')
44
+ .replace(new RegExp('>', 'g'), '&gt;')
45
+ .replace(new RegExp('"', 'g'), '&quot;')
46
+ .replace(new RegExp("'", 'g'), '&#039;')
47
+ .replace(new RegExp("'", 'g'), '&#39;')
48
+ .replace(new RegExp('\r\n', 'g'), ' ')
49
+ .replace(new RegExp('\n', 'g'), ' ');
55
50
  }
56
51
  export function numComma(x) {
57
52
  if (x === undefined || x === null) {
58
- return "";
53
+ return '';
59
54
  }
60
- return ("" + x).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
55
+ return ('' + x).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
61
56
  }
62
- export function bodyFetch(url, sendData, processFn, method = "POST") {
63
- let myHeaders = new Headers();
64
- myHeaders.append("Content-Type", "application/json");
65
- let parsedJson;
66
- try {
67
- parsedJson = JSON.stringify(sendData);
68
- }
69
- catch (exception) {
70
- console.error(exception);
71
- parsedJson = null;
72
- }
73
- let requestOptions = {
74
- method: method,
75
- headers: myHeaders,
76
- body: parsedJson,
77
- };
78
- fetch(url, requestOptions)
79
- .then((response) => response.json())
80
- .then(processFn)
81
- .catch((error) => {
82
- console.error(error);
57
+ export function bodyFetch(url, sendData, processFn, method = 'POST') {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ const myHeaders = new Headers();
60
+ myHeaders.append('Content-Type', 'application/json');
61
+ let parsedJson;
62
+ try {
63
+ parsedJson = JSON.stringify(sendData);
64
+ }
65
+ catch (exception) {
66
+ console.error(exception);
67
+ parsedJson = null;
68
+ }
69
+ const requestOptions = {
70
+ method: method,
71
+ headers: myHeaders,
72
+ body: parsedJson
73
+ };
74
+ try {
75
+ const response = yield fetch(url, requestOptions);
76
+ if (!response.ok) {
77
+ throw new Error(`HTTP error! status: ${response.status}`);
78
+ }
79
+ const data = yield response.json();
80
+ processFn(data);
81
+ }
82
+ catch (error) {
83
+ console.error('Error:', error);
84
+ throw error;
85
+ }
83
86
  });
84
87
  }
85
- export function paramFetch(url, sendData, processFn, method = "POST") {
86
- let myHeaders = new Headers();
87
- let sendParam = "";
88
- for (const key in sendData) {
89
- if (sendParam !== "")
90
- sendParam += "&";
91
- sendParam += key + "=" + sendData[key];
92
- }
93
- let requestOptions = {
94
- method: method,
95
- headers: myHeaders,
96
- };
97
- url += "?" + sendParam;
98
- fetch(url, requestOptions)
99
- .then((response) => response.json())
100
- .then(processFn)
101
- .catch((error) => {
102
- console.error(error);
88
+ export function paramFetch(url, sendData, processFn, method = 'POST') {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ const myHeaders = new Headers();
91
+ let sendParam = '';
92
+ for (const key in sendData) {
93
+ if (sendParam !== '')
94
+ sendParam += '&';
95
+ sendParam += key + '=' + sendData[key];
96
+ }
97
+ const requestOptions = {
98
+ method: method,
99
+ headers: myHeaders
100
+ };
101
+ url += '?' + sendParam;
102
+ try {
103
+ const response = yield fetch(url, requestOptions);
104
+ if (!response.ok) {
105
+ throw new Error(`HTTP error! status: ${response.status}`);
106
+ }
107
+ const data = yield response.json();
108
+ if (processFn != null) {
109
+ processFn(data);
110
+ }
111
+ }
112
+ catch (error) {
113
+ console.error('Error:', error);
114
+ throw error;
115
+ }
103
116
  });
104
117
  }
105
118
  //이메일 정규식
@@ -133,54 +146,50 @@ export function isBirthDay(asValue) {
133
146
  }
134
147
  // 핸드폰 번호 체크 정규식
135
148
  export function setCelluar(asValue) {
136
- if (asValue === undefined || asValue === "" || asValue === null) {
137
- return "";
149
+ if (asValue === undefined || asValue === '' || asValue === null) {
150
+ return '';
138
151
  }
139
152
  else {
140
- return asValue.replace(/(^02.{0}|^01.{1}|[0-9]{3})([0-9]+)([0-9]{4})/, "$1-$2-$3");
153
+ return asValue.replace(/(^02.{0}|^01.{1}|[0-9]{3})([0-9]+)([0-9]{4})/, '$1-$2-$3');
141
154
  }
142
155
  }
143
156
  export function dateFomat(date, formatStr) {
144
- const moment = require("moment");
145
- const returnDate = moment(date).format(formatStr);
157
+ const dayjs = require('dayjs');
158
+ const returnDate = dayjs(date).format(formatStr);
146
159
  return returnDate;
147
160
  }
148
161
  export function nowDate(formatStr) {
149
- const moment = require("moment");
150
- const returnDate = moment().format(formatStr);
162
+ const dayjs = require('dayjs');
163
+ const returnDate = dayjs().format(formatStr);
151
164
  return returnDate;
152
165
  }
153
166
  export function dateAddDay(formatStr, addDay) {
154
- const moment = require("moment");
155
- const returnDate = moment().add(addDay, "day").format(formatStr);
167
+ const dayjs = require('dayjs');
168
+ const returnDate = dayjs().add(addDay, 'day').format(formatStr);
156
169
  return returnDate;
157
170
  }
158
171
  export function dateAddMonth(formatStr, addMonth) {
159
- const moment = require("moment");
160
- const returnDate = moment().add(addMonth, "month").format(formatStr);
172
+ const dayjs = require('dayjs');
173
+ const returnDate = dayjs().add(addMonth, 'month').format(formatStr);
161
174
  return returnDate;
162
175
  }
163
176
  //전화번호 마스킹 20220816 임의로 수정이후 테스트안함. 사용시 테스트해보고하세요~~
164
177
  export function maskTell(tell) {
165
178
  if (tell === undefined || tell === null)
166
- return "";
167
- let maskingData = "";
179
+ return '';
180
+ let maskingData = '';
168
181
  let phoneMatchValue = tell.match(/\d{2,3}-\d{3,4}-\d{4}/gi);
169
182
  if (phoneMatchValue === null) {
170
- return "";
183
+ return '';
171
184
  }
172
185
  let str = phoneMatchValue.toString();
173
186
  if (/-[0-9]{3}-/.test(str)) {
174
187
  // 000-000-0000 형태인 경우
175
- maskingData = tell
176
- .toString()
177
- .replace(str, str.replace(/-[0-9]{3}-/g, "-***-"));
188
+ maskingData = tell.toString().replace(str, str.replace(/-[0-9]{3}-/g, '-***-'));
178
189
  }
179
190
  else if (/-[0-9]{4}-/.test(str)) {
180
191
  // 000-0000-0000 형태인 경우
181
- maskingData = tell
182
- .toString()
183
- .replace(str, str.replace(/-[0-9]{4}-/g, "-****-"));
192
+ maskingData = tell.toString().replace(str, str.replace(/-[0-9]{4}-/g, '-****-'));
184
193
  }
185
194
  else {
186
195
  // - 없을 경우
@@ -191,32 +200,24 @@ export function maskTell(tell) {
191
200
  : tell.match(/\d{10}/gi)
192
201
  : tell.match(/\d{11}/gi);
193
202
  if (phoneMatchValue === null) {
194
- return "";
203
+ return '';
195
204
  }
196
205
  str = phoneMatchValue.toString();
197
206
  if (tell.length < 11) {
198
207
  if (tell.length < 10) {
199
- maskingData = tell
200
- .toString()
201
- .replace(str, str.replace(/(\d{2})(\d{3})(\d{4})/gi, "$1-***-$3"));
208
+ maskingData = tell.toString().replace(str, str.replace(/(\d{2})(\d{3})(\d{4})/gi, '$1-***-$3'));
202
209
  }
203
210
  else {
204
- if (tell.indexOf("02") < 0) {
205
- maskingData = tell
206
- .toString()
207
- .replace(str, str.replace(/(\d{3})(\d{3})(\d{4})/gi, "$1-***-$3"));
211
+ if (tell.indexOf('02') < 0) {
212
+ maskingData = tell.toString().replace(str, str.replace(/(\d{3})(\d{3})(\d{4})/gi, '$1-***-$3'));
208
213
  }
209
214
  else {
210
- maskingData = tell
211
- .toString()
212
- .replace(str, str.replace(/(\d{2})(\d{4})(\d{4})/gi, "$1-****-$3"));
215
+ maskingData = tell.toString().replace(str, str.replace(/(\d{2})(\d{4})(\d{4})/gi, '$1-****-$3'));
213
216
  }
214
217
  }
215
218
  }
216
219
  else {
217
- maskingData = tell
218
- .toString()
219
- .replace(str, str.replace(/(\d{3})(\d{4})(\d{4})/gi, "$1-****-$3"));
220
+ maskingData = tell.toString().replace(str, str.replace(/(\d{3})(\d{4})(\d{4})/gi, '$1-****-$3'));
220
221
  }
221
222
  }
222
223
  return maskingData;
@@ -224,24 +225,24 @@ export function maskTell(tell) {
224
225
  //이름 마스킹
225
226
  export function maskName(name) {
226
227
  if (name === null || name === undefined)
227
- return "";
228
- return setCharAt(name, 1, "*");
228
+ return '';
229
+ return setCharAt(name, 1, '*');
229
230
  }
230
231
  //이메일 마스킹
231
232
  export function maskEmail(email) {
232
233
  if (email === null || email === undefined)
233
- return "";
234
- var temp = email.split("@");
235
- var maskEmail;
234
+ return '';
235
+ const temp = email.split('@');
236
+ let maskEmail;
236
237
  //아이디 뒤 세자리
237
238
  if (temp[0].length > 3) {
238
- maskEmail = temp[0].substring(0, temp[0].length - 3) + "***";
239
+ maskEmail = temp[0].substring(0, temp[0].length - 3) + '***';
239
240
  }
240
241
  else {
241
- maskEmail = "***";
242
+ maskEmail = '***';
242
243
  }
243
244
  if (temp[1] !== undefined) {
244
- return maskEmail + "@" + temp[1];
245
+ return maskEmail + '@' + temp[1];
245
246
  }
246
247
  else {
247
248
  return maskEmail;
@@ -254,14 +255,82 @@ function setCharAt(str, index, chr) {
254
255
  return str.substr(0, index) + chr + str.substr(index + 1);
255
256
  }
256
257
  export function cutString(str, length) {
257
- if (str.length > length - 3) {
258
- let tempStr = htmlTagRemove(str);
259
- return tempStr.substring(0, length - 3) + "...";
258
+ if (str.length > length) {
259
+ return htmlTagRemove(str).substring(0, length);
260
260
  }
261
261
  else {
262
262
  return htmlTagRemove(str);
263
263
  }
264
264
  }
265
- export const getLangClassName = (type, kor, en, jp, cn) => {
266
- return (type == "ko" ? ` ${kor} ` : type == "en" ? ` ${en} ` : type === 'jp' ? ` ${jp} ` : type === 'cn' ? ` ${cn} ` : '');
265
+ export function isCurrentTimeWithinPopupRange(days, startHour, startMin, endHour, endMin) {
266
+ if (startHour == null || startMin == null || endHour == null || endMin == null) {
267
+ return true;
268
+ }
269
+ const today = new Date();
270
+ const currentDayIndex = today.getDay();
271
+ const popupStartTime = new Date();
272
+ popupStartTime.setHours(startHour, startMin, 0);
273
+ const popupEndTime = new Date();
274
+ popupEndTime.setHours(endHour, endMin, 59);
275
+ return days.includes(currentDayIndex) && today >= popupStartTime && today <= popupEndTime;
276
+ }
277
+ export const formatPhoneNumber = (str) => {
278
+ if (typeof str !== 'string')
279
+ return '';
280
+ str = str.replace(/[^0-9]/g, '');
281
+ if (str.indexOf('82') == 0) {
282
+ return str.replace(/(^82)(2|\d{2})(\d+)?(\d{4})$/, '+$1-$2-$3-$4'); // +82
283
+ }
284
+ else if (str.indexOf('1') == 0) {
285
+ return str.replace(/(^1\d{3})(\d{4})$/, '$1-$2'); // 1588, 1566, 1677, ...
286
+ }
287
+ return str.replace(/(^02|^0504|^0505|^0\d{2})(\d+)?(\d{4})$/, '$1-$2-$3'); // 02/0504/0505/010/011/031
288
+ };
289
+ export function telValidator(tel) {
290
+ return /^[0-9]{2,3}-[0-9]{3,4}-[0-9]{4}/.test(tel);
291
+ }
292
+ //첫번째 글자가 자음 포함하는지 체크하는 정규식, 쌍자음 포함
293
+ //str > ㄱ,ㄴ,ㄷ,ㄹ
294
+ //testStr > 체크할 단어
295
+ export const consonantRegExp = (str, testStr) => {
296
+ switch (str) {
297
+ case 'ㄱ':
298
+ return testStr.match(/^[가-깋|까-낗]/);
299
+ case 'ㄴ':
300
+ return testStr.match(/^[나-닣]/);
301
+ case 'ㄷ':
302
+ return testStr.match(/^[다-딯|따-띻]/);
303
+ case 'ㄹ':
304
+ return testStr.match(/^[라-맇]/);
305
+ case 'ㅁ':
306
+ return testStr.match(/^[마-밓]/);
307
+ case 'ㅂ':
308
+ return testStr.match(/^[바-빟|빠-삫]/);
309
+ case 'ㅅ':
310
+ return testStr.match(/^[사-싷|싸-앃]/);
311
+ case 'ㅇ':
312
+ return testStr.match(/^[아-잏]/);
313
+ case 'ㅈ':
314
+ return testStr.match(/^[자-짛|짜-찧]/);
315
+ case 'ㅊ':
316
+ return testStr.match(/^[차-칳]/);
317
+ case 'ㅋ':
318
+ return testStr.match(/^[카-킿]/);
319
+ case 'ㅌ':
320
+ return testStr.match(/^[타-팋]/);
321
+ case 'ㅍ':
322
+ return testStr.match(/^[파-핗]/);
323
+ case 'ㅎ':
324
+ return testStr.match(/^[하-힣]/);
325
+ default:
326
+ return true;
327
+ }
328
+ };
329
+ export const getDomainHandler = (centerCode, subDomain) => {
330
+ if (centerCode === 'CT0000') {
331
+ return `https://www.daeryunlaw.com`;
332
+ }
333
+ else {
334
+ return `https://www.daeryunlaw-${subDomain}.com`;
335
+ }
267
336
  };