@nethru/kit 1.0.7 → 1.1.1

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.
@@ -0,0 +1,12 @@
1
+ let globalConfig = {
2
+ apiUrl: ''
3
+ };
4
+ export function configure(config) {
5
+ globalConfig = {
6
+ ...globalConfig,
7
+ ...config
8
+ };
9
+ }
10
+ export function getConfig() {
11
+ return globalConfig;
12
+ }
@@ -0,0 +1,78 @@
1
+ import dayjs from 'dayjs';
2
+ import isoWeek from 'dayjs/plugin/isoWeek';
3
+ import relativeTime from "dayjs/plugin/relativeTime";
4
+ import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
5
+ import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
6
+ dayjs.extend(relativeTime);
7
+ dayjs.extend(isoWeek);
8
+ dayjs.extend(isSameOrBefore);
9
+ dayjs.extend(isSameOrAfter);
10
+ dayjs.locale('ko');
11
+ export const isToday = (from, to) => {
12
+ const now = new Date();
13
+ const date = new Date(now.toLocaleString('en-US', {
14
+ timeZone: 'Asia/Seoul'
15
+ }));
16
+ const today = date.getFullYear() + String(date.getMonth() + 1).padStart(2, '0') + String(date.getDate()).padStart(2, '0');
17
+ return from === today && to === today;
18
+ };
19
+ export const isOneDay = (from, to) => {
20
+ return from === to;
21
+ };
22
+ export const formatDateRange = (from, to) => {
23
+ const fromDate = dayjs(from, 'YYYYMMDD');
24
+ const toDate = dayjs(to, 'YYYYMMDD');
25
+ const today = dayjs().startOf('day');
26
+ if (from === to) return formatSingleDate(fromDate, today);
27
+ return formatRange(fromDate, toDate, today);
28
+ };
29
+ const formatSingleDate = (date, today) => {
30
+ const diffDays = today.diff(date, 'day');
31
+ if (diffDays === 0) return '오늘';
32
+ if (diffDays === 1) return '어제';
33
+ if (diffDays === 2) return '그제';
34
+ return date.format('YYYY년 M월 D일');
35
+ };
36
+ const formatRange = (fromDate, toDate, today) => {
37
+ const thisWeekStart = today.startOf('week'); // 일요일
38
+ const thisWeekEnd = today.endOf('week'); // 토요일
39
+
40
+ if (fromDate.isSame(thisWeekStart, 'day') && (toDate.isSame(today, 'day') || toDate.isSame(thisWeekEnd, 'day'))) {
41
+ return '이번주';
42
+ }
43
+ const lastWeekStart = today.subtract(1, 'week').startOf('week');
44
+ const lastWeekEnd = today.subtract(1, 'week').endOf('week');
45
+ if (fromDate.isSame(lastWeekStart, 'day') && toDate.isSame(lastWeekEnd, 'day')) {
46
+ return '지난주';
47
+ }
48
+ const twoWeeksAgoStart = today.subtract(2, 'week').startOf('week');
49
+ const twoWeeksAgoEnd = today.subtract(2, 'week').endOf('week');
50
+ if (fromDate.isSame(twoWeeksAgoStart, 'day') && toDate.isSame(twoWeeksAgoEnd, 'day')) {
51
+ return '지지난주';
52
+ }
53
+ const thisMonthStart = today.startOf('month');
54
+ const thisMonthEnd = today.endOf('month');
55
+ if (fromDate.isSame(thisMonthStart, 'day') && (toDate.isSame(today, 'day') || toDate.isSame(thisMonthEnd, 'day'))) {
56
+ return '이번달';
57
+ }
58
+ const lastMonthStart = today.subtract(1, 'month').startOf('month');
59
+ const lastMonthEnd = today.subtract(1, 'month').endOf('month');
60
+ if (fromDate.isSame(lastMonthStart, 'day') && toDate.isSame(lastMonthEnd, 'day')) {
61
+ return '지난달';
62
+ }
63
+ const twoMonthsAgoStart = today.subtract(2, 'month').startOf('month');
64
+ const twoMonthsAgoEnd = today.subtract(2, 'month').endOf('month');
65
+ if (fromDate.isSame(twoMonthsAgoStart, 'day') && toDate.isSame(twoMonthsAgoEnd, 'day')) {
66
+ return '지지난달';
67
+ }
68
+ const fromFormatted = formatDateInRange(fromDate, today);
69
+ const toFormatted = formatDateInRange(toDate, today);
70
+ return `${fromFormatted} ~ ${toFormatted}`;
71
+ };
72
+ const formatDateInRange = (date, today) => {
73
+ const diffDays = today.diff(date, 'day');
74
+ if (diffDays === 0) return '오늘';
75
+ if (diffDays === 1) return '어제';
76
+ if (diffDays === 2) return '그제';
77
+ return date.format('YYYY년 M월 D일');
78
+ };
package/package.json CHANGED
@@ -1,24 +1,25 @@
1
1
  {
2
2
  "name": "@nethru/kit",
3
- "version": "1.0.7",
3
+ "version": "1.1.1",
4
4
  "description": "A React component library by Nethru",
5
- "type": "module",
6
- "main": "./dist/index.js",
7
- "module": "./dist/index.esm.js",
8
- "exports": {
9
- ".": {
10
- "require": "./dist/index.js",
11
- "import": "./dist/index.esm.js"
12
- }
13
- },
5
+ "main": "dist/index.js",
14
6
  "files": [
15
- "dist"
7
+ "/dist"
16
8
  ],
17
9
  "scripts": {
18
- "dev": "vite",
19
- "build": "rollup -c",
10
+ "build": "rm -rf dist && mkdir dist && babel src -d dist --copy-files",
20
11
  "prepublishOnly": "npm run build"
21
12
  },
13
+ "babel": {
14
+ "presets": [
15
+ [
16
+ "@babel/preset-react",
17
+ {
18
+ "runtime": "automatic"
19
+ }
20
+ ]
21
+ ]
22
+ },
22
23
  "keywords": [
23
24
  "react",
24
25
  "components",
@@ -32,21 +33,14 @@
32
33
  "react-dom": "^18.0.0"
33
34
  },
34
35
  "devDependencies": {
36
+ "@babel/cli": "^7.23.4",
35
37
  "@babel/core": "^7.23.0",
36
- "@babel/preset-react": "^7.23.0",
37
- "@rollup/plugin-babel": "^6.0.4",
38
- "@rollup/plugin-commonjs": "^29.0.0",
39
- "@rollup/plugin-node-resolve": "^15.2.3",
40
- "@vitejs/plugin-react": "^5.1.1",
41
- "react": "^18.2.0",
42
- "react-dom": "^18.2.0",
43
- "rollup": "^4.0.0",
44
- "rollup-plugin-postcss": "^4.0.2",
45
- "vite": "^7.2.6"
38
+ "@babel/preset-react": "^7.23.0"
46
39
  },
47
40
  "dependencies": {
48
41
  "@mui/icons-material": "^6.5.0",
49
42
  "@mui/material": "^6.0.1",
43
+ "@nethru/kit": "^1.1.0",
50
44
  "@nethru/ui": "^2.1.45",
51
45
  "highcharts": "^11.3.0",
52
46
  "highcharts-react-official": "^3.2.1",