sales-frontend-utils 0.0.39 → 0.0.41

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/index.d.cts CHANGED
@@ -1,3 +1,5 @@
1
+ import dayjs from 'dayjs';
2
+
1
3
  /**
2
4
  * 쓰로틀
3
5
  * @param func
@@ -360,7 +362,7 @@ declare const getOneMonthLater: (value?: string, format?: string) => string;
360
362
  * @param date2 (yyyymmdd or yyyy.mm.dd or yyyy-mm-dd)
361
363
  * @returns date1 - date2
362
364
  */
363
- declare const getDateDiff: (date1: string, date2: string) => number;
365
+ declare const getDateDiff: (date1: string | number | dayjs.Dayjs | Date, date2: string | number | dayjs.Dayjs | Date) => number;
364
366
  /**
365
367
  * 입력되어진 생년월일 값이 당일 기준으로 미래시점인 경우 false를 반환합니다. (회원체계 기준 9, 0 일 경우 오류)
366
368
  * @param front 주민등록번호 앞 6자리
@@ -374,14 +376,14 @@ declare const validateBirthdate: (front: string, back: string) => boolean;
374
376
  * @param compareDate
375
377
  * @returns boolean
376
378
  */
377
- declare function isDateAfter(targetDate: string, compareDate: string): boolean;
379
+ declare function isDateAfter(targetDate: string | number | dayjs.Dayjs | Date, compareDate: string | number | dayjs.Dayjs | Date): boolean;
378
380
  /**
379
381
  * 날짜를 포맷형태로 리턴
380
382
  * @param 20200101 string
381
383
  * @param 'YYYY.MM.DD
382
384
  * @returns 포맷화된 날짜
383
385
  */
384
- declare const convertDateFormat: (value?: string, format?: string) => string;
386
+ declare const convertDateFormat: (value?: string | number | dayjs.Dayjs | Date, format?: string) => string;
385
387
  /**
386
388
  * 주어진 날짜가 오늘 날짜 이후인지 확인합니다.
387
389
  *
@@ -389,7 +391,26 @@ declare const convertDateFormat: (value?: string, format?: string) => string;
389
391
  * @param {dayjs.OptionType} [format] - 날짜 문자열의 형식입니다.
390
392
  * @returns {boolean} - 주어진 날짜가 오늘 이후라면 true를 반환합니다.
391
393
  */
392
- declare const isFutureDate: (dateString?: string, format?: string) => boolean;
394
+ declare const isFutureDate: (dateString?: string | number | dayjs.Dayjs | Date, format?: dayjs.OptionType) => boolean;
395
+ /**
396
+ * 자주 사용하는 타입들 추가해두었습니다. 필요하신 형태 있으면 추가해주세요.
397
+ */
398
+ type DateFormat = 'YYYY-MM-DD' | 'YYYY.MM.DD' | 'YYYY-MM' | 'YYYY-MM-DD HH:mm:ss' | 'YYYY.MM.DD HH:mm:ss' | 'YYYY-MM-DD HH:mm' | 'YYYYMMDD' | 'YYYY.M.D' | 'YYYY.M' | 'YYYY.MM.DD(dd) HH:mm:ss' | 'HH:mm:ss' | 'YYYY.M.D(dd)' | 'HH:mm';
399
+ interface Props {
400
+ /** 날짜 문자열 */
401
+ dateString: string | number | Date | dayjs.Dayjs;
402
+ /** 현재 날짜 포맷 */
403
+ fromFormat?: string;
404
+ /** 컨버팅할 날짜 포맷 */
405
+ toFormat: string;
406
+ }
407
+ /**
408
+ * date string 을 입력받고 패턴에 맞게 포맷팅을 변경하는 유틸 함수
409
+ * fromFormat 현재 날짜 포맷
410
+ * toFormat 리턴 날짜 포맷
411
+ */
412
+ declare const convertDateString: ({ dateString, fromFormat, toFormat }: Props) => string;
413
+ declare const isDate: (value: unknown) => boolean;
393
414
  /**
394
415
  * 날짜 유효성 검사
395
416
  *
@@ -397,11 +418,25 @@ declare const isFutureDate: (dateString?: string, format?: string) => boolean;
397
418
  * @param {dayjs.OptionType} [format] - 날짜 문자열의 형식입니다.
398
419
  * @returns {boolean} - 유효한 날짜이면 true를 반환하고, 그렇지 않으면 false를 반환합니다.
399
420
  */
400
- declare const isValidDate: (dateString?: string, format?: string) => boolean;
401
- type PeriodType = 'thisWeek' | 'lastWeek' | 'last7Days' | 'thisMonth' | 'lastMonth' | 'last365Days';
402
- declare const getPeriodDate: (periodType: PeriodType) => {
421
+ declare const isValidDate: (dateString?: string | number | dayjs.Dayjs | Date, format?: dayjs.OptionType) => boolean;
422
+ type PeriodType = 'thisWeek' | 'lastWeek' | 'last7Days' | 'thisMonth' | 'lastMonth' | 'last365Days' | 'week' | 'month' | 'today';
423
+ /**
424
+ * @description
425
+ * today 당일
426
+ * week 7일: 오늘 기준 7일 전
427
+ * month 30: 오늘 기준 30일 전
428
+ * thisWeek 이번 주 (일요일 ~ 토요일)
429
+ * lastWeek 지난 주 (일요일 ~ 토요일)
430
+ * last7Days 최근 7일 (오늘 포함)
431
+ * thisMonth 이번 달 (1일 ~ 말일)
432
+ * lastMonth 지난 달 (1일 ~ 말일)
433
+ * last365Days 최근 365일 (오늘 포함)
434
+ * @param periodType
435
+ * @returns
436
+ */
437
+ declare const getPeriodDate: (periodType: PeriodType | "today") => {
403
438
  startDate: Date;
404
439
  endDate: Date;
405
- };
440
+ } | null;
406
441
 
407
- export { type BrowserName, type ExecutionEnvironment, MessageEventManager, type OSName, type PeriodType, addE2EObject, base64ToBlob, base64ToFile, blobToFile, checkUserAgentDspApp, convertDateFormat, convertTextToImg, debounce, deleteCookie, downloadBlob, drawImageResizeCentered, fileToBase64, getApiHostNameFromEnvironment, getBrowserName, getBrowserVersion, getBusinessWorkDivisionCode, getCdnHostNameFromEnvironment, getCookie, getCurrentBrowserName, getCurrentBrowserVersion, getCurrentOSName, getCurrentOSVersion, getDateDiff, getDeviceModel, getDspApiBasePathFromEnvironment, getDspExecutionEnvironment, getDudApiBasePathFromEnvironment, getE2EDataIDs, getEnvironmentFromHostname, getExt, getFormFactorFromUserAgent, getLastDay, getNlcHostFromEnvironment, getOSName, getOSVersion, getOneMonthLater, getOrCreateDeviceId, getPeriodDate, getServicePath, getSubdomain, hasAstx2, imageUrlToFile, initASTX2, isClient, isDateAfter, isDspApp, isFpPlannerApp, isFutureDate, isPc, isPhone, isProductionApp, isSalesPortal, isStorybookEnv, isTablet, isValidDate, loadScript, objectUrlToBase64, objectUrlToBlob, setCookie, throttle, validateBirthdate };
442
+ export { type BrowserName, type DateFormat, type ExecutionEnvironment, MessageEventManager, type OSName, type PeriodType, addE2EObject, base64ToBlob, base64ToFile, blobToFile, checkUserAgentDspApp, convertDateFormat, convertDateString, convertTextToImg, debounce, deleteCookie, downloadBlob, drawImageResizeCentered, fileToBase64, getApiHostNameFromEnvironment, getBrowserName, getBrowserVersion, getBusinessWorkDivisionCode, getCdnHostNameFromEnvironment, getCookie, getCurrentBrowserName, getCurrentBrowserVersion, getCurrentOSName, getCurrentOSVersion, getDateDiff, getDeviceModel, getDspApiBasePathFromEnvironment, getDspExecutionEnvironment, getDudApiBasePathFromEnvironment, getE2EDataIDs, getEnvironmentFromHostname, getExt, getFormFactorFromUserAgent, getLastDay, getNlcHostFromEnvironment, getOSName, getOSVersion, getOneMonthLater, getOrCreateDeviceId, getPeriodDate, getServicePath, getSubdomain, hasAstx2, imageUrlToFile, initASTX2, isClient, isDate, isDateAfter, isDspApp, isFpPlannerApp, isFutureDate, isPc, isPhone, isProductionApp, isSalesPortal, isStorybookEnv, isTablet, isValidDate, loadScript, objectUrlToBase64, objectUrlToBlob, setCookie, throttle, validateBirthdate };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import dayjs from 'dayjs';
2
+
1
3
  /**
2
4
  * 쓰로틀
3
5
  * @param func
@@ -360,7 +362,7 @@ declare const getOneMonthLater: (value?: string, format?: string) => string;
360
362
  * @param date2 (yyyymmdd or yyyy.mm.dd or yyyy-mm-dd)
361
363
  * @returns date1 - date2
362
364
  */
363
- declare const getDateDiff: (date1: string, date2: string) => number;
365
+ declare const getDateDiff: (date1: string | number | dayjs.Dayjs | Date, date2: string | number | dayjs.Dayjs | Date) => number;
364
366
  /**
365
367
  * 입력되어진 생년월일 값이 당일 기준으로 미래시점인 경우 false를 반환합니다. (회원체계 기준 9, 0 일 경우 오류)
366
368
  * @param front 주민등록번호 앞 6자리
@@ -374,14 +376,14 @@ declare const validateBirthdate: (front: string, back: string) => boolean;
374
376
  * @param compareDate
375
377
  * @returns boolean
376
378
  */
377
- declare function isDateAfter(targetDate: string, compareDate: string): boolean;
379
+ declare function isDateAfter(targetDate: string | number | dayjs.Dayjs | Date, compareDate: string | number | dayjs.Dayjs | Date): boolean;
378
380
  /**
379
381
  * 날짜를 포맷형태로 리턴
380
382
  * @param 20200101 string
381
383
  * @param 'YYYY.MM.DD
382
384
  * @returns 포맷화된 날짜
383
385
  */
384
- declare const convertDateFormat: (value?: string, format?: string) => string;
386
+ declare const convertDateFormat: (value?: string | number | dayjs.Dayjs | Date, format?: string) => string;
385
387
  /**
386
388
  * 주어진 날짜가 오늘 날짜 이후인지 확인합니다.
387
389
  *
@@ -389,7 +391,26 @@ declare const convertDateFormat: (value?: string, format?: string) => string;
389
391
  * @param {dayjs.OptionType} [format] - 날짜 문자열의 형식입니다.
390
392
  * @returns {boolean} - 주어진 날짜가 오늘 이후라면 true를 반환합니다.
391
393
  */
392
- declare const isFutureDate: (dateString?: string, format?: string) => boolean;
394
+ declare const isFutureDate: (dateString?: string | number | dayjs.Dayjs | Date, format?: dayjs.OptionType) => boolean;
395
+ /**
396
+ * 자주 사용하는 타입들 추가해두었습니다. 필요하신 형태 있으면 추가해주세요.
397
+ */
398
+ type DateFormat = 'YYYY-MM-DD' | 'YYYY.MM.DD' | 'YYYY-MM' | 'YYYY-MM-DD HH:mm:ss' | 'YYYY.MM.DD HH:mm:ss' | 'YYYY-MM-DD HH:mm' | 'YYYYMMDD' | 'YYYY.M.D' | 'YYYY.M' | 'YYYY.MM.DD(dd) HH:mm:ss' | 'HH:mm:ss' | 'YYYY.M.D(dd)' | 'HH:mm';
399
+ interface Props {
400
+ /** 날짜 문자열 */
401
+ dateString: string | number | Date | dayjs.Dayjs;
402
+ /** 현재 날짜 포맷 */
403
+ fromFormat?: string;
404
+ /** 컨버팅할 날짜 포맷 */
405
+ toFormat: string;
406
+ }
407
+ /**
408
+ * date string 을 입력받고 패턴에 맞게 포맷팅을 변경하는 유틸 함수
409
+ * fromFormat 현재 날짜 포맷
410
+ * toFormat 리턴 날짜 포맷
411
+ */
412
+ declare const convertDateString: ({ dateString, fromFormat, toFormat }: Props) => string;
413
+ declare const isDate: (value: unknown) => boolean;
393
414
  /**
394
415
  * 날짜 유효성 검사
395
416
  *
@@ -397,11 +418,25 @@ declare const isFutureDate: (dateString?: string, format?: string) => boolean;
397
418
  * @param {dayjs.OptionType} [format] - 날짜 문자열의 형식입니다.
398
419
  * @returns {boolean} - 유효한 날짜이면 true를 반환하고, 그렇지 않으면 false를 반환합니다.
399
420
  */
400
- declare const isValidDate: (dateString?: string, format?: string) => boolean;
401
- type PeriodType = 'thisWeek' | 'lastWeek' | 'last7Days' | 'thisMonth' | 'lastMonth' | 'last365Days';
402
- declare const getPeriodDate: (periodType: PeriodType) => {
421
+ declare const isValidDate: (dateString?: string | number | dayjs.Dayjs | Date, format?: dayjs.OptionType) => boolean;
422
+ type PeriodType = 'thisWeek' | 'lastWeek' | 'last7Days' | 'thisMonth' | 'lastMonth' | 'last365Days' | 'week' | 'month' | 'today';
423
+ /**
424
+ * @description
425
+ * today 당일
426
+ * week 7일: 오늘 기준 7일 전
427
+ * month 30: 오늘 기준 30일 전
428
+ * thisWeek 이번 주 (일요일 ~ 토요일)
429
+ * lastWeek 지난 주 (일요일 ~ 토요일)
430
+ * last7Days 최근 7일 (오늘 포함)
431
+ * thisMonth 이번 달 (1일 ~ 말일)
432
+ * lastMonth 지난 달 (1일 ~ 말일)
433
+ * last365Days 최근 365일 (오늘 포함)
434
+ * @param periodType
435
+ * @returns
436
+ */
437
+ declare const getPeriodDate: (periodType: PeriodType | "today") => {
403
438
  startDate: Date;
404
439
  endDate: Date;
405
- };
440
+ } | null;
406
441
 
407
- export { type BrowserName, type ExecutionEnvironment, MessageEventManager, type OSName, type PeriodType, addE2EObject, base64ToBlob, base64ToFile, blobToFile, checkUserAgentDspApp, convertDateFormat, convertTextToImg, debounce, deleteCookie, downloadBlob, drawImageResizeCentered, fileToBase64, getApiHostNameFromEnvironment, getBrowserName, getBrowserVersion, getBusinessWorkDivisionCode, getCdnHostNameFromEnvironment, getCookie, getCurrentBrowserName, getCurrentBrowserVersion, getCurrentOSName, getCurrentOSVersion, getDateDiff, getDeviceModel, getDspApiBasePathFromEnvironment, getDspExecutionEnvironment, getDudApiBasePathFromEnvironment, getE2EDataIDs, getEnvironmentFromHostname, getExt, getFormFactorFromUserAgent, getLastDay, getNlcHostFromEnvironment, getOSName, getOSVersion, getOneMonthLater, getOrCreateDeviceId, getPeriodDate, getServicePath, getSubdomain, hasAstx2, imageUrlToFile, initASTX2, isClient, isDateAfter, isDspApp, isFpPlannerApp, isFutureDate, isPc, isPhone, isProductionApp, isSalesPortal, isStorybookEnv, isTablet, isValidDate, loadScript, objectUrlToBase64, objectUrlToBlob, setCookie, throttle, validateBirthdate };
442
+ export { type BrowserName, type DateFormat, type ExecutionEnvironment, MessageEventManager, type OSName, type PeriodType, addE2EObject, base64ToBlob, base64ToFile, blobToFile, checkUserAgentDspApp, convertDateFormat, convertDateString, convertTextToImg, debounce, deleteCookie, downloadBlob, drawImageResizeCentered, fileToBase64, getApiHostNameFromEnvironment, getBrowserName, getBrowserVersion, getBusinessWorkDivisionCode, getCdnHostNameFromEnvironment, getCookie, getCurrentBrowserName, getCurrentBrowserVersion, getCurrentOSName, getCurrentOSVersion, getDateDiff, getDeviceModel, getDspApiBasePathFromEnvironment, getDspExecutionEnvironment, getDudApiBasePathFromEnvironment, getE2EDataIDs, getEnvironmentFromHostname, getExt, getFormFactorFromUserAgent, getLastDay, getNlcHostFromEnvironment, getOSName, getOSVersion, getOneMonthLater, getOrCreateDeviceId, getPeriodDate, getServicePath, getSubdomain, hasAstx2, imageUrlToFile, initASTX2, isClient, isDate, isDateAfter, isDspApp, isFpPlannerApp, isFutureDate, isPc, isPhone, isProductionApp, isSalesPortal, isStorybookEnv, isTablet, isValidDate, loadScript, objectUrlToBase64, objectUrlToBlob, setCookie, throttle, validateBirthdate };
package/dist/index.js CHANGED
@@ -868,10 +868,8 @@ var getOneMonthLater = (value, format) => {
868
868
  }
869
869
  };
870
870
  var getDateDiff = (date1, date2) => {
871
- const yyyyMMdd1 = date1.replace(/[.|-]/g, "");
872
- const yyyyMMdd2 = date2.replace(/[.|-]/g, "");
873
- const diff1 = dayjs(dayjs(yyyyMMdd1).format("YYYY-MM-DD"));
874
- const diff2 = dayjs(yyyyMMdd2).format("YYYY-MM-DD");
871
+ const diff1 = dayjs(date1);
872
+ const diff2 = dayjs(date2);
875
873
  return diff1.diff(diff2, "day");
876
874
  };
877
875
  var validateBirthdate = (front, back) => {
@@ -921,6 +919,12 @@ var isFutureDate = (dateString, format) => {
921
919
  const date = dayjs(dateString, format || "YYYYMMDD", true);
922
920
  return date.isValid() && date.isAfter(today);
923
921
  };
922
+ var convertDateString = ({ dateString, fromFormat, toFormat }) => {
923
+ return dayjs(dateString, fromFormat).format(toFormat);
924
+ };
925
+ var isDate = (value) => {
926
+ return value instanceof Date && !isNaN(+value);
927
+ };
924
928
  var isValidDate = (dateString, format) => {
925
929
  if (!dateString) {
926
930
  return false;
@@ -930,7 +934,22 @@ var isValidDate = (dateString, format) => {
930
934
  };
931
935
  var getPeriodDate = (periodType) => {
932
936
  const lastMonth = dayjs().subtract(1, "M");
937
+ const today = /* @__PURE__ */ new Date();
938
+ today.setHours(0, 0, 0, 0);
939
+ const endDate = new Date(today);
940
+ let startDate;
933
941
  switch (periodType) {
942
+ case "today":
943
+ startDate = new Date(today);
944
+ return { startDate, endDate };
945
+ case "week":
946
+ startDate = new Date(today);
947
+ startDate.setDate(startDate.getDate() - 6);
948
+ return { startDate, endDate };
949
+ case "month":
950
+ startDate = new Date(today);
951
+ startDate.setDate(startDate.getDate() - 29);
952
+ return { startDate, endDate };
934
953
  case "thisWeek":
935
954
  return { startDate: dayjs().day(0).toDate(), endDate: dayjs().day(6).toDate() };
936
955
  case "lastWeek":
@@ -953,10 +972,10 @@ var getPeriodDate = (periodType) => {
953
972
  case "last365Days":
954
973
  return { startDate: dayjs().subtract(365, "d").toDate(), endDate: dayjs().toDate() };
955
974
  default:
956
- return { startDate: dayjs().toDate(), endDate: dayjs().toDate() };
975
+ return null;
957
976
  }
958
977
  };
959
978
 
960
- export { MessageEventManager, addE2EObject, base64ToBlob, base64ToFile, blobToFile, checkUserAgentDspApp, convertDateFormat, convertTextToImg, debounce, deleteCookie, downloadBlob, drawImageResizeCentered, fileToBase64, getApiHostNameFromEnvironment, getBrowserName, getBrowserVersion, getBusinessWorkDivisionCode, getCdnHostNameFromEnvironment, getCookie, getCurrentBrowserName, getCurrentBrowserVersion, getCurrentOSName, getCurrentOSVersion, getDateDiff, getDeviceModel, getDspApiBasePathFromEnvironment, getDspExecutionEnvironment, getDudApiBasePathFromEnvironment, getE2EDataIDs, getEnvironmentFromHostname, getExt, getFormFactorFromUserAgent, getLastDay, getNlcHostFromEnvironment, getOSName, getOSVersion, getOneMonthLater, getOrCreateDeviceId, getPeriodDate, getServicePath, getSubdomain, hasAstx2, imageUrlToFile, initASTX2, isClient, isDateAfter, isDspApp, isFpPlannerApp, isFutureDate, isPc, isPhone, isProductionApp, isSalesPortal, isStorybookEnv, isTablet, isValidDate, loadScript, objectUrlToBase64, objectUrlToBlob, setCookie, throttle, validateBirthdate };
979
+ export { MessageEventManager, addE2EObject, base64ToBlob, base64ToFile, blobToFile, checkUserAgentDspApp, convertDateFormat, convertDateString, convertTextToImg, debounce, deleteCookie, downloadBlob, drawImageResizeCentered, fileToBase64, getApiHostNameFromEnvironment, getBrowserName, getBrowserVersion, getBusinessWorkDivisionCode, getCdnHostNameFromEnvironment, getCookie, getCurrentBrowserName, getCurrentBrowserVersion, getCurrentOSName, getCurrentOSVersion, getDateDiff, getDeviceModel, getDspApiBasePathFromEnvironment, getDspExecutionEnvironment, getDudApiBasePathFromEnvironment, getE2EDataIDs, getEnvironmentFromHostname, getExt, getFormFactorFromUserAgent, getLastDay, getNlcHostFromEnvironment, getOSName, getOSVersion, getOneMonthLater, getOrCreateDeviceId, getPeriodDate, getServicePath, getSubdomain, hasAstx2, imageUrlToFile, initASTX2, isClient, isDate, isDateAfter, isDspApp, isFpPlannerApp, isFutureDate, isPc, isPhone, isProductionApp, isSalesPortal, isStorybookEnv, isTablet, isValidDate, loadScript, objectUrlToBase64, objectUrlToBlob, setCookie, throttle, validateBirthdate };
961
980
  //# sourceMappingURL=index.js.map
962
981
  //# sourceMappingURL=index.js.map