@gtcx/utils 0.1.0
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.cjs +150 -0
- package/dist/index.d.cts +27 -0
- package/dist/index.d.mts +28 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +157 -0
- package/dist/index.mjs +120 -0
- package/package.json +38 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
cn: () => cn,
|
|
24
|
+
debounce: () => debounce,
|
|
25
|
+
formatDate: () => formatDate,
|
|
26
|
+
formatDateTime: () => formatDateTime,
|
|
27
|
+
getHeight: () => getHeight,
|
|
28
|
+
getInitials: () => getInitials,
|
|
29
|
+
noop: () => noop,
|
|
30
|
+
throttle: () => throttle,
|
|
31
|
+
timeAgo: () => timeAgo,
|
|
32
|
+
toAbsoluteUrl: () => toAbsoluteUrl,
|
|
33
|
+
uid: () => uid
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
|
|
37
|
+
// src/cn.ts
|
|
38
|
+
var import_clsx = require("clsx");
|
|
39
|
+
var import_tailwind_merge = require("tailwind-merge");
|
|
40
|
+
function cn(...inputs) {
|
|
41
|
+
return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// src/dom.ts
|
|
45
|
+
function getHeight(element) {
|
|
46
|
+
if (!element) return 0;
|
|
47
|
+
const styles = window.getComputedStyle(element);
|
|
48
|
+
const height = element.getBoundingClientRect().height;
|
|
49
|
+
const marginTop = parseFloat(styles.marginTop);
|
|
50
|
+
const marginBottom = parseFloat(styles.marginBottom);
|
|
51
|
+
return height + marginTop + marginBottom;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/helpers.ts
|
|
55
|
+
function throttle(func, limit) {
|
|
56
|
+
let lastFunc = null;
|
|
57
|
+
let lastRan = null;
|
|
58
|
+
return function(...args) {
|
|
59
|
+
if (lastRan === null) {
|
|
60
|
+
func.apply(this, args);
|
|
61
|
+
lastRan = Date.now();
|
|
62
|
+
} else {
|
|
63
|
+
if (lastFunc !== null) {
|
|
64
|
+
clearTimeout(lastFunc);
|
|
65
|
+
}
|
|
66
|
+
lastFunc = setTimeout(
|
|
67
|
+
() => {
|
|
68
|
+
if (Date.now() - lastRan >= limit) {
|
|
69
|
+
func.apply(this, args);
|
|
70
|
+
lastRan = Date.now();
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
limit - (Date.now() - lastRan)
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function debounce(func, wait) {
|
|
79
|
+
let timeout = null;
|
|
80
|
+
return function(...args) {
|
|
81
|
+
if (timeout) {
|
|
82
|
+
clearTimeout(timeout);
|
|
83
|
+
}
|
|
84
|
+
timeout = setTimeout(() => {
|
|
85
|
+
func.apply(this, args);
|
|
86
|
+
}, wait);
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function uid() {
|
|
90
|
+
return (Date.now() + Math.floor(Math.random() * 1e3)).toString();
|
|
91
|
+
}
|
|
92
|
+
function getInitials(name, count) {
|
|
93
|
+
if (!name || typeof name !== "string") {
|
|
94
|
+
return "";
|
|
95
|
+
}
|
|
96
|
+
const initials = name.split(" ").filter(Boolean).map((part) => part[0].toUpperCase());
|
|
97
|
+
return count && count > 0 ? initials.slice(0, count).join("") : initials.join("");
|
|
98
|
+
}
|
|
99
|
+
function toAbsoluteUrl(pathname) {
|
|
100
|
+
return pathname;
|
|
101
|
+
}
|
|
102
|
+
function timeAgo(date) {
|
|
103
|
+
const now = /* @__PURE__ */ new Date();
|
|
104
|
+
const inputDate = typeof date === "string" ? new Date(date) : date;
|
|
105
|
+
const diff = Math.floor((now.getTime() - inputDate.getTime()) / 1e3);
|
|
106
|
+
if (diff < 60) return "just now";
|
|
107
|
+
if (diff < 3600) return `${Math.floor(diff / 60)} minute${Math.floor(diff / 60) > 1 ? "s" : ""} ago`;
|
|
108
|
+
if (diff < 86400) return `${Math.floor(diff / 3600)} hour${Math.floor(diff / 3600) > 1 ? "s" : ""} ago`;
|
|
109
|
+
if (diff < 604800) return `${Math.floor(diff / 86400)} day${Math.floor(diff / 86400) > 1 ? "s" : ""} ago`;
|
|
110
|
+
if (diff < 2592e3) return `${Math.floor(diff / 604800)} week${Math.floor(diff / 604800) > 1 ? "s" : ""} ago`;
|
|
111
|
+
if (diff < 31536e3) return `${Math.floor(diff / 2592e3)} month${Math.floor(diff / 2592e3) > 1 ? "s" : ""} ago`;
|
|
112
|
+
return `${Math.floor(diff / 31536e3)} year${Math.floor(diff / 31536e3) > 1 ? "s" : ""} ago`;
|
|
113
|
+
}
|
|
114
|
+
function formatDate(input) {
|
|
115
|
+
const date = new Date(input);
|
|
116
|
+
return date.toLocaleDateString("en-US", {
|
|
117
|
+
month: "long",
|
|
118
|
+
day: "numeric",
|
|
119
|
+
year: "numeric"
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function formatDateTime(input) {
|
|
123
|
+
const date = new Date(input);
|
|
124
|
+
return date.toLocaleString("en-US", {
|
|
125
|
+
month: "long",
|
|
126
|
+
day: "numeric",
|
|
127
|
+
year: "numeric",
|
|
128
|
+
hour: "numeric",
|
|
129
|
+
minute: "numeric",
|
|
130
|
+
hour12: true
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/index.ts
|
|
135
|
+
function noop() {
|
|
136
|
+
}
|
|
137
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
138
|
+
0 && (module.exports = {
|
|
139
|
+
cn,
|
|
140
|
+
debounce,
|
|
141
|
+
formatDate,
|
|
142
|
+
formatDateTime,
|
|
143
|
+
getHeight,
|
|
144
|
+
getInitials,
|
|
145
|
+
noop,
|
|
146
|
+
throttle,
|
|
147
|
+
timeAgo,
|
|
148
|
+
toAbsoluteUrl,
|
|
149
|
+
uid
|
|
150
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ClassValue } from 'clsx';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Merges Tailwind class names, resolving any conflicts.
|
|
5
|
+
*/
|
|
6
|
+
declare function cn(...inputs: ClassValue[]): string;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* DOM utility functions.
|
|
10
|
+
*/
|
|
11
|
+
declare function getHeight(element: HTMLElement | null): number;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* General helper utility functions.
|
|
15
|
+
*/
|
|
16
|
+
declare function throttle<T extends (...args: unknown[]) => void>(func: T, limit: number): T;
|
|
17
|
+
declare function debounce<T extends (...args: unknown[]) => void>(func: T, wait: number): T;
|
|
18
|
+
declare function uid(): string;
|
|
19
|
+
declare function getInitials(name: string, count?: number): string;
|
|
20
|
+
declare function toAbsoluteUrl(pathname: string): string;
|
|
21
|
+
declare function timeAgo(date: string | Date): string;
|
|
22
|
+
declare function formatDate(input: string | Date): string;
|
|
23
|
+
declare function formatDateTime(input: string | Date): string;
|
|
24
|
+
|
|
25
|
+
declare function noop(): void;
|
|
26
|
+
|
|
27
|
+
export { cn, debounce, formatDate, formatDateTime, getHeight, getInitials, noop, throttle, timeAgo, toAbsoluteUrl, uid };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ClassValue } from 'clsx';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Merges Tailwind class names, resolving any conflicts.
|
|
5
|
+
*/
|
|
6
|
+
declare function cn(...inputs: ClassValue[]): string;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* DOM utility functions.
|
|
10
|
+
*/
|
|
11
|
+
declare function getHeight(element: HTMLElement | null): number;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* General helper utility functions.
|
|
15
|
+
*/
|
|
16
|
+
declare function throttle<T extends (...args: unknown[]) => void>(func: T, limit: number): T;
|
|
17
|
+
declare function debounce<T extends (...args: unknown[]) => void>(func: T, wait: number): T;
|
|
18
|
+
declare function uid(): string;
|
|
19
|
+
declare function getInitials(name: string, count?: number): string;
|
|
20
|
+
declare function toAbsoluteUrl(pathname: string): string;
|
|
21
|
+
|
|
22
|
+
declare function timeAgo(date: string | Date): string;
|
|
23
|
+
declare function formatDate(input: string | Date): string;
|
|
24
|
+
declare function formatDateTime(input: string | Date): string;
|
|
25
|
+
|
|
26
|
+
declare function noop(): void;
|
|
27
|
+
|
|
28
|
+
export { cn, debounce, formatDate, formatDateTime, getHeight, getInitials, noop, throttle, timeAgo, toAbsoluteUrl, uid };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ClassValue } from 'clsx';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Merges Tailwind class names, resolving any conflicts.
|
|
5
|
+
*/
|
|
6
|
+
declare function cn(...inputs: ClassValue[]): string;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* DOM utility functions.
|
|
10
|
+
*/
|
|
11
|
+
declare function getHeight(element: HTMLElement | null): number;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* General helper utility functions.
|
|
15
|
+
*/
|
|
16
|
+
declare function throttle<T extends (...args: unknown[]) => void>(func: T, limit: number): T;
|
|
17
|
+
declare function debounce<T extends (...args: unknown[]) => void>(func: T, wait: number): T;
|
|
18
|
+
declare function uid(): string;
|
|
19
|
+
declare function getInitials(name: string, count?: number): string;
|
|
20
|
+
declare function toAbsoluteUrl(pathname: string): string;
|
|
21
|
+
|
|
22
|
+
declare function timeAgo(date: string | Date): string;
|
|
23
|
+
declare function formatDate(input: string | Date): string;
|
|
24
|
+
declare function formatDateTime(input: string | Date): string;
|
|
25
|
+
|
|
26
|
+
declare function noop(): void;
|
|
27
|
+
|
|
28
|
+
export { cn, debounce, formatDate, formatDateTime, getHeight, getInitials, noop, throttle, timeAgo, toAbsoluteUrl, uid };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
cn: () => cn,
|
|
24
|
+
debounce: () => debounce,
|
|
25
|
+
formatDate: () => formatDate,
|
|
26
|
+
formatDateTime: () => formatDateTime,
|
|
27
|
+
getHeight: () => getHeight,
|
|
28
|
+
getInitials: () => getInitials,
|
|
29
|
+
noop: () => noop,
|
|
30
|
+
throttle: () => throttle,
|
|
31
|
+
timeAgo: () => timeAgo,
|
|
32
|
+
toAbsoluteUrl: () => toAbsoluteUrl,
|
|
33
|
+
uid: () => uid
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
|
|
37
|
+
// src/cn.ts
|
|
38
|
+
var import_clsx = require("clsx");
|
|
39
|
+
var import_tailwind_merge = require("tailwind-merge");
|
|
40
|
+
function cn(...inputs) {
|
|
41
|
+
return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// src/dom.ts
|
|
45
|
+
function getHeight(element) {
|
|
46
|
+
if (!element) return 0;
|
|
47
|
+
const styles = window.getComputedStyle(element);
|
|
48
|
+
const height = element.getBoundingClientRect().height;
|
|
49
|
+
const marginTop = parseFloat(styles.marginTop);
|
|
50
|
+
const marginBottom = parseFloat(styles.marginBottom);
|
|
51
|
+
return height + marginTop + marginBottom;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/helpers.ts
|
|
55
|
+
function throttle(func, limit) {
|
|
56
|
+
let lastFunc = null;
|
|
57
|
+
let lastRan = null;
|
|
58
|
+
return function(...args) {
|
|
59
|
+
if (lastRan === null) {
|
|
60
|
+
func.apply(this, args);
|
|
61
|
+
lastRan = Date.now();
|
|
62
|
+
} else {
|
|
63
|
+
if (lastFunc !== null) {
|
|
64
|
+
clearTimeout(lastFunc);
|
|
65
|
+
}
|
|
66
|
+
lastFunc = setTimeout(
|
|
67
|
+
() => {
|
|
68
|
+
if (Date.now() - lastRan >= limit) {
|
|
69
|
+
func.apply(this, args);
|
|
70
|
+
lastRan = Date.now();
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
limit - (Date.now() - lastRan)
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function debounce(func, wait) {
|
|
79
|
+
let timeout = null;
|
|
80
|
+
return function(...args) {
|
|
81
|
+
if (timeout) {
|
|
82
|
+
clearTimeout(timeout);
|
|
83
|
+
}
|
|
84
|
+
timeout = setTimeout(() => {
|
|
85
|
+
func.apply(this, args);
|
|
86
|
+
}, wait);
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function uid() {
|
|
90
|
+
return (Date.now() + Math.floor(Math.random() * 1e3)).toString();
|
|
91
|
+
}
|
|
92
|
+
function getInitials(name, count) {
|
|
93
|
+
if (!name || typeof name !== "string") {
|
|
94
|
+
return "";
|
|
95
|
+
}
|
|
96
|
+
const initials = name.split(" ").filter(Boolean).map((part) => part[0].toUpperCase());
|
|
97
|
+
return count && count > 0 ? initials.slice(0, count).join("") : initials.join("");
|
|
98
|
+
}
|
|
99
|
+
function toAbsoluteUrl(pathname) {
|
|
100
|
+
return pathname;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/date.ts
|
|
104
|
+
function timeAgo(date) {
|
|
105
|
+
const now = /* @__PURE__ */ new Date();
|
|
106
|
+
const inputDate = typeof date === "string" ? new Date(date) : date;
|
|
107
|
+
const diff = Math.floor((now.getTime() - inputDate.getTime()) / 1e3);
|
|
108
|
+
if (diff < 60) return "just now";
|
|
109
|
+
if (diff < 3600)
|
|
110
|
+
return `${Math.floor(diff / 60)} minute${Math.floor(diff / 60) > 1 ? "s" : ""} ago`;
|
|
111
|
+
if (diff < 86400)
|
|
112
|
+
return `${Math.floor(diff / 3600)} hour${Math.floor(diff / 3600) > 1 ? "s" : ""} ago`;
|
|
113
|
+
if (diff < 604800)
|
|
114
|
+
return `${Math.floor(diff / 86400)} day${Math.floor(diff / 86400) > 1 ? "s" : ""} ago`;
|
|
115
|
+
if (diff < 2592e3)
|
|
116
|
+
return `${Math.floor(diff / 604800)} week${Math.floor(diff / 604800) > 1 ? "s" : ""} ago`;
|
|
117
|
+
if (diff < 31536e3)
|
|
118
|
+
return `${Math.floor(diff / 2592e3)} month${Math.floor(diff / 2592e3) > 1 ? "s" : ""} ago`;
|
|
119
|
+
return `${Math.floor(diff / 31536e3)} year${Math.floor(diff / 31536e3) > 1 ? "s" : ""} ago`;
|
|
120
|
+
}
|
|
121
|
+
function formatDate(input) {
|
|
122
|
+
const date = new Date(input);
|
|
123
|
+
return date.toLocaleDateString("en-US", {
|
|
124
|
+
month: "long",
|
|
125
|
+
day: "numeric",
|
|
126
|
+
year: "numeric"
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function formatDateTime(input) {
|
|
130
|
+
const date = new Date(input);
|
|
131
|
+
return date.toLocaleString("en-US", {
|
|
132
|
+
month: "long",
|
|
133
|
+
day: "numeric",
|
|
134
|
+
year: "numeric",
|
|
135
|
+
hour: "numeric",
|
|
136
|
+
minute: "numeric",
|
|
137
|
+
hour12: true
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// src/noop.ts
|
|
142
|
+
function noop() {
|
|
143
|
+
}
|
|
144
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
145
|
+
0 && (module.exports = {
|
|
146
|
+
cn,
|
|
147
|
+
debounce,
|
|
148
|
+
formatDate,
|
|
149
|
+
formatDateTime,
|
|
150
|
+
getHeight,
|
|
151
|
+
getInitials,
|
|
152
|
+
noop,
|
|
153
|
+
throttle,
|
|
154
|
+
timeAgo,
|
|
155
|
+
toAbsoluteUrl,
|
|
156
|
+
uid
|
|
157
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// src/cn.ts
|
|
2
|
+
import { clsx } from "clsx";
|
|
3
|
+
import { twMerge } from "tailwind-merge";
|
|
4
|
+
function cn(...inputs) {
|
|
5
|
+
return twMerge(clsx(inputs));
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// src/dom.ts
|
|
9
|
+
function getHeight(element) {
|
|
10
|
+
if (!element) return 0;
|
|
11
|
+
const styles = window.getComputedStyle(element);
|
|
12
|
+
const height = element.getBoundingClientRect().height;
|
|
13
|
+
const marginTop = parseFloat(styles.marginTop);
|
|
14
|
+
const marginBottom = parseFloat(styles.marginBottom);
|
|
15
|
+
return height + marginTop + marginBottom;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// src/helpers.ts
|
|
19
|
+
function throttle(func, limit) {
|
|
20
|
+
let lastFunc = null;
|
|
21
|
+
let lastRan = null;
|
|
22
|
+
return function(...args) {
|
|
23
|
+
if (lastRan === null) {
|
|
24
|
+
func.apply(this, args);
|
|
25
|
+
lastRan = Date.now();
|
|
26
|
+
} else {
|
|
27
|
+
if (lastFunc !== null) {
|
|
28
|
+
clearTimeout(lastFunc);
|
|
29
|
+
}
|
|
30
|
+
lastFunc = setTimeout(
|
|
31
|
+
() => {
|
|
32
|
+
if (Date.now() - lastRan >= limit) {
|
|
33
|
+
func.apply(this, args);
|
|
34
|
+
lastRan = Date.now();
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
limit - (Date.now() - lastRan)
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function debounce(func, wait) {
|
|
43
|
+
let timeout = null;
|
|
44
|
+
return function(...args) {
|
|
45
|
+
if (timeout) {
|
|
46
|
+
clearTimeout(timeout);
|
|
47
|
+
}
|
|
48
|
+
timeout = setTimeout(() => {
|
|
49
|
+
func.apply(this, args);
|
|
50
|
+
}, wait);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function uid() {
|
|
54
|
+
return (Date.now() + Math.floor(Math.random() * 1e3)).toString();
|
|
55
|
+
}
|
|
56
|
+
function getInitials(name, count) {
|
|
57
|
+
if (!name || typeof name !== "string") {
|
|
58
|
+
return "";
|
|
59
|
+
}
|
|
60
|
+
const initials = name.split(" ").filter(Boolean).map((part) => part[0].toUpperCase());
|
|
61
|
+
return count && count > 0 ? initials.slice(0, count).join("") : initials.join("");
|
|
62
|
+
}
|
|
63
|
+
function toAbsoluteUrl(pathname) {
|
|
64
|
+
return pathname;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// src/date.ts
|
|
68
|
+
function timeAgo(date) {
|
|
69
|
+
const now = /* @__PURE__ */ new Date();
|
|
70
|
+
const inputDate = typeof date === "string" ? new Date(date) : date;
|
|
71
|
+
const diff = Math.floor((now.getTime() - inputDate.getTime()) / 1e3);
|
|
72
|
+
if (diff < 60) return "just now";
|
|
73
|
+
if (diff < 3600)
|
|
74
|
+
return `${Math.floor(diff / 60)} minute${Math.floor(diff / 60) > 1 ? "s" : ""} ago`;
|
|
75
|
+
if (diff < 86400)
|
|
76
|
+
return `${Math.floor(diff / 3600)} hour${Math.floor(diff / 3600) > 1 ? "s" : ""} ago`;
|
|
77
|
+
if (diff < 604800)
|
|
78
|
+
return `${Math.floor(diff / 86400)} day${Math.floor(diff / 86400) > 1 ? "s" : ""} ago`;
|
|
79
|
+
if (diff < 2592e3)
|
|
80
|
+
return `${Math.floor(diff / 604800)} week${Math.floor(diff / 604800) > 1 ? "s" : ""} ago`;
|
|
81
|
+
if (diff < 31536e3)
|
|
82
|
+
return `${Math.floor(diff / 2592e3)} month${Math.floor(diff / 2592e3) > 1 ? "s" : ""} ago`;
|
|
83
|
+
return `${Math.floor(diff / 31536e3)} year${Math.floor(diff / 31536e3) > 1 ? "s" : ""} ago`;
|
|
84
|
+
}
|
|
85
|
+
function formatDate(input) {
|
|
86
|
+
const date = new Date(input);
|
|
87
|
+
return date.toLocaleDateString("en-US", {
|
|
88
|
+
month: "long",
|
|
89
|
+
day: "numeric",
|
|
90
|
+
year: "numeric"
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
function formatDateTime(input) {
|
|
94
|
+
const date = new Date(input);
|
|
95
|
+
return date.toLocaleString("en-US", {
|
|
96
|
+
month: "long",
|
|
97
|
+
day: "numeric",
|
|
98
|
+
year: "numeric",
|
|
99
|
+
hour: "numeric",
|
|
100
|
+
minute: "numeric",
|
|
101
|
+
hour12: true
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/noop.ts
|
|
106
|
+
function noop() {
|
|
107
|
+
}
|
|
108
|
+
export {
|
|
109
|
+
cn,
|
|
110
|
+
debounce,
|
|
111
|
+
formatDate,
|
|
112
|
+
formatDateTime,
|
|
113
|
+
getHeight,
|
|
114
|
+
getInitials,
|
|
115
|
+
noop,
|
|
116
|
+
throttle,
|
|
117
|
+
timeAgo,
|
|
118
|
+
toAbsoluteUrl,
|
|
119
|
+
uid
|
|
120
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gtcx/utils",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "GTCX shared utilities — cn, DOM helpers, debounce, throttle, date formatting",
|
|
5
|
+
"main": "dist/index.cjs",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
18
|
+
"dev": "tsup src/index.ts --format esm,cjs --dts --watch",
|
|
19
|
+
"lint": "eslint src/",
|
|
20
|
+
"typecheck": "tsc --noEmit",
|
|
21
|
+
"test": "vitest run"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"clsx": "^2.1.0",
|
|
25
|
+
"tailwind-merge": "^2.2.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"tsup": "^8.0.0",
|
|
29
|
+
"typescript": "^5.0.0"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"README.md"
|
|
34
|
+
],
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
}
|
|
38
|
+
}
|