koishi-plugin-prism 0.5.2 → 0.6.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/README.md +20 -13
- package/lib/index.d.ts +104 -116
- package/lib/index.js +412 -1539
- package/package.json +1 -1
- package/lib/display-time.d.ts +0 -10
- package/lib/display-time.js +0 -36
package/package.json
CHANGED
package/lib/display-time.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/** Parsing preserves the absolute instant; formatting preserves the API's explicit offset. */
|
|
2
|
-
export declare function parseDateTime(value: unknown): Date | null;
|
|
3
|
-
export declare function apiOffsetLabel(value: unknown): string;
|
|
4
|
-
export declare function dateParts(value: unknown): {
|
|
5
|
-
date: string;
|
|
6
|
-
time: string;
|
|
7
|
-
} | null;
|
|
8
|
-
export declare const formatHM: (value: unknown) => string;
|
|
9
|
-
export declare const formatMD: (value: unknown) => string;
|
|
10
|
-
export declare function formatDateTime(value: unknown): string;
|
package/lib/display-time.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatMD = exports.formatHM = void 0;
|
|
4
|
-
exports.parseDateTime = parseDateTime;
|
|
5
|
-
exports.apiOffsetLabel = apiOffsetLabel;
|
|
6
|
-
exports.dateParts = dateParts;
|
|
7
|
-
exports.formatDateTime = formatDateTime;
|
|
8
|
-
/** Parsing preserves the absolute instant; formatting preserves the API's explicit offset. */
|
|
9
|
-
function parseDateTime(value) {
|
|
10
|
-
if (value instanceof Date)
|
|
11
|
-
return Number.isNaN(value.getTime()) ? null : value;
|
|
12
|
-
if (typeof value !== "string" || !value.trim())
|
|
13
|
-
return null;
|
|
14
|
-
const text = value.trim();
|
|
15
|
-
const normalized = /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?$/.test(text) ? `${text.replace(" ", "T")}Z` : text;
|
|
16
|
-
const date = new Date(normalized);
|
|
17
|
-
return Number.isNaN(date.getTime()) ? null : date;
|
|
18
|
-
}
|
|
19
|
-
function apiOffsetLabel(value) {
|
|
20
|
-
return `UTC${typeof value === "string" ? value.match(/[+-]\d{2}:\d{2}$/)?.[0] ?? "+00:00" : "+00:00"}`;
|
|
21
|
-
}
|
|
22
|
-
function dateParts(value) {
|
|
23
|
-
const date = parseDateTime(value);
|
|
24
|
-
if (!date)
|
|
25
|
-
return null;
|
|
26
|
-
const text = typeof value === "string" && /[+-]\d{2}:\d{2}$/.test(value) ? value : date.toISOString();
|
|
27
|
-
return { date: text.slice(0, 10), time: text.slice(11, 19) };
|
|
28
|
-
}
|
|
29
|
-
const formatHM = (value) => dateParts(value)?.time.slice(0, 5) ?? "—";
|
|
30
|
-
exports.formatHM = formatHM;
|
|
31
|
-
const formatMD = (value) => dateParts(value)?.date.slice(5) ?? "—";
|
|
32
|
-
exports.formatMD = formatMD;
|
|
33
|
-
function formatDateTime(value) {
|
|
34
|
-
const parts = dateParts(value);
|
|
35
|
-
return parts ? `${parts.date.replaceAll("-", "/")} ${parts.time}(${apiOffsetLabel(value)})` : value ? "时间无效" : "永不过期";
|
|
36
|
-
}
|