@a2zb/lib 1.0.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/fmt/hex.d.ts +3 -0
- package/dist/fmt/hex.js +2 -0
- package/dist/fmt/image.d.ts +2 -0
- package/dist/fmt/image.js +27 -0
- package/dist/fmt/string.d.ts +2 -0
- package/dist/fmt/string.js +5 -0
- package/dist/fmt/time.d.ts +9 -0
- package/dist/fmt/time.js +72 -0
- package/dist/http/page.d.ts +4 -0
- package/dist/http/page.js +1 -0
- package/dist/http/result.d.ts +8 -0
- package/dist/http/result.js +5 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/package.json +13 -0
package/dist/fmt/hex.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const isSvg = (src) => {
|
|
2
|
+
return !!src && src.startsWith('data:image/svg');
|
|
3
|
+
};
|
|
4
|
+
const inlineSvgToBlobUrl = (src) => {
|
|
5
|
+
// removes prefix so we only have raw <svg ...>
|
|
6
|
+
const svg = src.replace('data:image/svg+xml;utf8,', '');
|
|
7
|
+
const blob = new Blob([svg], { type: 'image/svg+xml' });
|
|
8
|
+
return URL.createObjectURL(blob);
|
|
9
|
+
};
|
|
10
|
+
export const resolveImage = async (src) => {
|
|
11
|
+
if (!src)
|
|
12
|
+
return '';
|
|
13
|
+
// ONLY convert inline SVGs
|
|
14
|
+
if (isSvg(src))
|
|
15
|
+
return inlineSvgToBlobUrl(src);
|
|
16
|
+
// EVERYTHING ELSE: DO NOT FETCH
|
|
17
|
+
return src;
|
|
18
|
+
};
|
|
19
|
+
export const getImageFromTokenURI = (tokenUri) => {
|
|
20
|
+
// remove: data:application/json;base64,
|
|
21
|
+
const base64 = tokenUri.split(',')[1];
|
|
22
|
+
// decode base64 → json string
|
|
23
|
+
const json = atob(base64);
|
|
24
|
+
// parse json
|
|
25
|
+
const metadata = JSON.parse(json);
|
|
26
|
+
return metadata.image;
|
|
27
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const months: string[];
|
|
2
|
+
export type TimeUnit = "hour" | "day" | "month" | "week";
|
|
3
|
+
export declare const tsShort: (ts: number) => string;
|
|
4
|
+
export declare const tsSuperShort: (ts: number) => string;
|
|
5
|
+
export declare const tsLong: (ts: number) => string;
|
|
6
|
+
export declare const tsMonthNameUTC: (ts: number) => string;
|
|
7
|
+
export declare const hhmm: (ts: number) => string;
|
|
8
|
+
export declare const timeAgo: (ts: number) => string;
|
|
9
|
+
export declare const timeKey: (ts: number, unit: "hour" | "day" | "month" | "week") => string | undefined;
|
package/dist/fmt/time.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export const months = [
|
|
2
|
+
"January",
|
|
3
|
+
"February",
|
|
4
|
+
"March",
|
|
5
|
+
"April",
|
|
6
|
+
"May",
|
|
7
|
+
"June",
|
|
8
|
+
"July",
|
|
9
|
+
"August",
|
|
10
|
+
"September",
|
|
11
|
+
"October",
|
|
12
|
+
"November",
|
|
13
|
+
"December",
|
|
14
|
+
];
|
|
15
|
+
export const tsShort = (ts) => {
|
|
16
|
+
const p = parts(ts);
|
|
17
|
+
return `${p.month} ${p.day} ${p.time}`;
|
|
18
|
+
};
|
|
19
|
+
export const tsSuperShort = (ts) => {
|
|
20
|
+
const p = parts(ts);
|
|
21
|
+
return `${p.month} ${p.day}`;
|
|
22
|
+
};
|
|
23
|
+
export const tsLong = (ts) => {
|
|
24
|
+
const p = parts(ts);
|
|
25
|
+
return `${p.yy}.${p.mm}.${p.dd} ${p.hh}:${p.min}`;
|
|
26
|
+
};
|
|
27
|
+
export const tsMonthNameUTC = (ts) => months[new Date(ts).getUTCMonth()];
|
|
28
|
+
export const hhmm = (ts) => {
|
|
29
|
+
return new Date(ts).toLocaleTimeString([], {
|
|
30
|
+
hour: "2-digit",
|
|
31
|
+
minute: "2-digit",
|
|
32
|
+
hour12: false,
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
const parts = (ts) => {
|
|
36
|
+
const d = new Date(ts);
|
|
37
|
+
return {
|
|
38
|
+
month: d.toLocaleString("en-US", { month: "short" }),
|
|
39
|
+
day: String(d.getDate()).padStart(2, "0"),
|
|
40
|
+
yy: String(d.getUTCFullYear()).slice(-2),
|
|
41
|
+
mm: String(d.getUTCMonth() + 1).padStart(2, "0"),
|
|
42
|
+
dd: String(d.getUTCDate()).padStart(2, "0"),
|
|
43
|
+
hh: String(d.getUTCHours()).padStart(2, "0"),
|
|
44
|
+
min: String(d.getUTCMinutes()).padStart(2, "0"),
|
|
45
|
+
time: d.toTimeString().slice(0, 5),
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
export const timeAgo = (ts) => {
|
|
49
|
+
const secs = Math.floor((Date.now() - ts) / 1000);
|
|
50
|
+
if (secs < 60)
|
|
51
|
+
return "just now";
|
|
52
|
+
const mins = Math.floor(secs / 60);
|
|
53
|
+
if (mins < 60)
|
|
54
|
+
return `${mins} min ago`;
|
|
55
|
+
const hours = Math.floor(mins / 60);
|
|
56
|
+
if (hours < 24)
|
|
57
|
+
return `${hours} hr ago`;
|
|
58
|
+
const days = Math.floor(hours / 24);
|
|
59
|
+
return `${days} day${days === 1 ? "" : "s"} ago`;
|
|
60
|
+
};
|
|
61
|
+
// never used for UI display only for charts => always UTC
|
|
62
|
+
export const timeKey = (ts, unit) => {
|
|
63
|
+
const d = new Date(ts);
|
|
64
|
+
switch (unit) {
|
|
65
|
+
case "hour":
|
|
66
|
+
return d.toISOString().slice(0, 13); // 2026-01-16T05
|
|
67
|
+
case "day":
|
|
68
|
+
return d.toISOString().slice(0, 10); // 2026-01-16
|
|
69
|
+
case "month":
|
|
70
|
+
return `${d.getUTCFullYear()}-${d.getUTCMonth()}`;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED