@gofreego/tsutils 0.1.11 → 0.1.13
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.mts +15 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +96 -63
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +96 -64
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -120,6 +120,7 @@ interface ReadmeViewerProps {
|
|
|
120
120
|
content: string;
|
|
121
121
|
className?: string;
|
|
122
122
|
isDark?: boolean;
|
|
123
|
+
muiTheme?: any;
|
|
123
124
|
}
|
|
124
125
|
declare const ReadmeViewer: React.FC<ReadmeViewerProps>;
|
|
125
126
|
|
|
@@ -510,6 +511,15 @@ interface HttpResponse<T = any> {
|
|
|
510
511
|
statusText: string;
|
|
511
512
|
headers: Headers;
|
|
512
513
|
}
|
|
514
|
+
interface ErrorData {
|
|
515
|
+
code: number;
|
|
516
|
+
message: string;
|
|
517
|
+
}
|
|
518
|
+
interface HttpError extends Error {
|
|
519
|
+
status?: number;
|
|
520
|
+
statusText?: string;
|
|
521
|
+
data?: ErrorData;
|
|
522
|
+
}
|
|
513
523
|
|
|
514
524
|
declare class HttpClient {
|
|
515
525
|
private baseURL;
|
|
@@ -518,12 +528,16 @@ declare class HttpClient {
|
|
|
518
528
|
constructor(config?: HttpClientConfig);
|
|
519
529
|
private buildURL;
|
|
520
530
|
private request;
|
|
531
|
+
setDefaultHeader(key: string, value: string): void;
|
|
532
|
+
removeDefaultHeader(key: string): void;
|
|
533
|
+
getDefaultHeaders(): Record<string, string>;
|
|
521
534
|
get<T = any>(url: string, config?: RequestConfig): Promise<HttpResponse<T>>;
|
|
522
535
|
post<T = any>(url: string, data?: any, config?: RequestConfig): Promise<HttpResponse<T>>;
|
|
523
536
|
put<T = any>(url: string, data?: any, config?: RequestConfig): Promise<HttpResponse<T>>;
|
|
524
537
|
patch<T = any>(url: string, data?: any, config?: RequestConfig): Promise<HttpResponse<T>>;
|
|
525
538
|
delete<T = any>(url: string, config?: RequestConfig): Promise<HttpResponse<T>>;
|
|
526
539
|
}
|
|
540
|
+
declare function extractErrorMessage(error: any): string;
|
|
527
541
|
|
|
528
542
|
/**
|
|
529
543
|
* Merges class names together
|
|
@@ -650,4 +664,4 @@ declare class PermissionManager {
|
|
|
650
664
|
static hasPermission(permission: string): boolean;
|
|
651
665
|
}
|
|
652
666
|
|
|
653
|
-
export { type AuthContextType, AuthProvider, type AuthProviderProps, ConfirmDialog, type ConfirmDialogProps, HttpClient, type HttpClientConfig, type HttpResponse, LocalStorage, type MenuItem, type Notification, type NotificationContextType, NotificationProvider, type NotificationProviderProps, PermissionManager, ReadmeViewer, type RequestConfig, type ResolvedThemeMode, SidebarLayout, type SidebarLayoutProps, type Theme, type ThemeContextValue, type ThemeMode, ThemeProvider, ThemeToggle, borderRadius, cn, darkTheme, debounce, elevation, fontSize, fontWeight, formatDate, getHighlighter, lightTheme, lineHeight, spacing, throttle, tokens, transition, useAuth, useNotification, useTheme, zIndex };
|
|
667
|
+
export { type AuthContextType, AuthProvider, type AuthProviderProps, ConfirmDialog, type ConfirmDialogProps, type ErrorData, HttpClient, type HttpClientConfig, type HttpError, type HttpResponse, LocalStorage, type MenuItem, type Notification, type NotificationContextType, NotificationProvider, type NotificationProviderProps, PermissionManager, ReadmeViewer, type RequestConfig, type ResolvedThemeMode, SidebarLayout, type SidebarLayoutProps, type Theme, type ThemeContextValue, type ThemeMode, ThemeProvider, ThemeToggle, borderRadius, cn, darkTheme, debounce, elevation, extractErrorMessage, fontSize, fontWeight, formatDate, getHighlighter, lightTheme, lineHeight, spacing, throttle, tokens, transition, useAuth, useNotification, useTheme, zIndex };
|
package/dist/index.d.ts
CHANGED
|
@@ -120,6 +120,7 @@ interface ReadmeViewerProps {
|
|
|
120
120
|
content: string;
|
|
121
121
|
className?: string;
|
|
122
122
|
isDark?: boolean;
|
|
123
|
+
muiTheme?: any;
|
|
123
124
|
}
|
|
124
125
|
declare const ReadmeViewer: React.FC<ReadmeViewerProps>;
|
|
125
126
|
|
|
@@ -510,6 +511,15 @@ interface HttpResponse<T = any> {
|
|
|
510
511
|
statusText: string;
|
|
511
512
|
headers: Headers;
|
|
512
513
|
}
|
|
514
|
+
interface ErrorData {
|
|
515
|
+
code: number;
|
|
516
|
+
message: string;
|
|
517
|
+
}
|
|
518
|
+
interface HttpError extends Error {
|
|
519
|
+
status?: number;
|
|
520
|
+
statusText?: string;
|
|
521
|
+
data?: ErrorData;
|
|
522
|
+
}
|
|
513
523
|
|
|
514
524
|
declare class HttpClient {
|
|
515
525
|
private baseURL;
|
|
@@ -518,12 +528,16 @@ declare class HttpClient {
|
|
|
518
528
|
constructor(config?: HttpClientConfig);
|
|
519
529
|
private buildURL;
|
|
520
530
|
private request;
|
|
531
|
+
setDefaultHeader(key: string, value: string): void;
|
|
532
|
+
removeDefaultHeader(key: string): void;
|
|
533
|
+
getDefaultHeaders(): Record<string, string>;
|
|
521
534
|
get<T = any>(url: string, config?: RequestConfig): Promise<HttpResponse<T>>;
|
|
522
535
|
post<T = any>(url: string, data?: any, config?: RequestConfig): Promise<HttpResponse<T>>;
|
|
523
536
|
put<T = any>(url: string, data?: any, config?: RequestConfig): Promise<HttpResponse<T>>;
|
|
524
537
|
patch<T = any>(url: string, data?: any, config?: RequestConfig): Promise<HttpResponse<T>>;
|
|
525
538
|
delete<T = any>(url: string, config?: RequestConfig): Promise<HttpResponse<T>>;
|
|
526
539
|
}
|
|
540
|
+
declare function extractErrorMessage(error: any): string;
|
|
527
541
|
|
|
528
542
|
/**
|
|
529
543
|
* Merges class names together
|
|
@@ -650,4 +664,4 @@ declare class PermissionManager {
|
|
|
650
664
|
static hasPermission(permission: string): boolean;
|
|
651
665
|
}
|
|
652
666
|
|
|
653
|
-
export { type AuthContextType, AuthProvider, type AuthProviderProps, ConfirmDialog, type ConfirmDialogProps, HttpClient, type HttpClientConfig, type HttpResponse, LocalStorage, type MenuItem, type Notification, type NotificationContextType, NotificationProvider, type NotificationProviderProps, PermissionManager, ReadmeViewer, type RequestConfig, type ResolvedThemeMode, SidebarLayout, type SidebarLayoutProps, type Theme, type ThemeContextValue, type ThemeMode, ThemeProvider, ThemeToggle, borderRadius, cn, darkTheme, debounce, elevation, fontSize, fontWeight, formatDate, getHighlighter, lightTheme, lineHeight, spacing, throttle, tokens, transition, useAuth, useNotification, useTheme, zIndex };
|
|
667
|
+
export { type AuthContextType, AuthProvider, type AuthProviderProps, ConfirmDialog, type ConfirmDialogProps, type ErrorData, HttpClient, type HttpClientConfig, type HttpError, type HttpResponse, LocalStorage, type MenuItem, type Notification, type NotificationContextType, NotificationProvider, type NotificationProviderProps, PermissionManager, ReadmeViewer, type RequestConfig, type ResolvedThemeMode, SidebarLayout, type SidebarLayoutProps, type Theme, type ThemeContextValue, type ThemeMode, ThemeProvider, ThemeToggle, borderRadius, cn, darkTheme, debounce, elevation, extractErrorMessage, fontSize, fontWeight, formatDate, getHighlighter, lightTheme, lineHeight, spacing, throttle, tokens, transition, useAuth, useNotification, useTheme, zIndex };
|
package/dist/index.js
CHANGED
|
@@ -415,8 +415,10 @@ var getHighlighter = async () => {
|
|
|
415
415
|
var ReadmeViewer = ({
|
|
416
416
|
content,
|
|
417
417
|
className = "",
|
|
418
|
-
isDark
|
|
418
|
+
isDark: propIsDark,
|
|
419
|
+
muiTheme
|
|
419
420
|
}) => {
|
|
421
|
+
const isDark = propIsDark !== void 0 ? propIsDark : muiTheme?.palette?.mode === "dark";
|
|
420
422
|
const [highlighter, setHighlighter] = react.useState(null);
|
|
421
423
|
const [copiedBlocks, setCopiedBlocks] = react.useState(/* @__PURE__ */ new Set());
|
|
422
424
|
react.useEffect(() => {
|
|
@@ -437,74 +439,85 @@ var ReadmeViewer = ({
|
|
|
437
439
|
console.error("Failed to copy text: ", err);
|
|
438
440
|
}
|
|
439
441
|
};
|
|
440
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
442
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `readme-viewer markdown-body ${className}`, children: [
|
|
443
|
+
/* @__PURE__ */ jsxRuntime.jsx("style", { children: `
|
|
444
|
+
.shiki-wrapper pre.shiki {
|
|
445
|
+
padding: 16px !important;
|
|
446
|
+
border-radius: 8px !important;
|
|
447
|
+
overflow-x: auto;
|
|
448
|
+
margin-bottom: 16px;
|
|
449
|
+
border: 1px solid var(--md-sys-color-outline-variant, #e0e0e0);
|
|
450
|
+
}
|
|
451
|
+
` }),
|
|
452
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
453
|
+
ReactMarkdown__default.default,
|
|
454
|
+
{
|
|
455
|
+
remarkPlugins: [remarkGfm__default.default, remarkMath__default.default],
|
|
456
|
+
rehypePlugins: [rehypeKatex__default.default],
|
|
457
|
+
components: {
|
|
458
|
+
code({ className: className2, children, ...props }) {
|
|
459
|
+
const match = /language-(\w+)/.exec(className2 || "");
|
|
460
|
+
if (match && highlighter) {
|
|
461
|
+
const codeText = String(children).replace(/\n$/, "");
|
|
462
|
+
const blockId = `code-${Math.random().toString(36).substr(2, 9)}`;
|
|
463
|
+
let highlightedHtml = "";
|
|
458
464
|
try {
|
|
459
465
|
highlightedHtml = highlighter.codeToHtml(codeText, {
|
|
460
|
-
lang:
|
|
466
|
+
lang: match[1],
|
|
461
467
|
theme: isDark ? "github-dark" : "github-light"
|
|
462
468
|
});
|
|
463
|
-
} catch (
|
|
464
|
-
|
|
469
|
+
} catch (e) {
|
|
470
|
+
try {
|
|
471
|
+
highlightedHtml = highlighter.codeToHtml(codeText, {
|
|
472
|
+
lang: "text",
|
|
473
|
+
theme: isDark ? "github-dark" : "github-light"
|
|
474
|
+
});
|
|
475
|
+
} catch (fallbackError) {
|
|
476
|
+
highlightedHtml = `<pre><code>${codeText}</code></pre>`;
|
|
477
|
+
}
|
|
465
478
|
}
|
|
479
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { position: "relative" }, children: [
|
|
480
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "shiki-wrapper", dangerouslySetInnerHTML: { __html: highlightedHtml } }),
|
|
481
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
482
|
+
"button",
|
|
483
|
+
{
|
|
484
|
+
onClick: () => copyToClipboard(codeText, blockId),
|
|
485
|
+
style: {
|
|
486
|
+
position: "absolute",
|
|
487
|
+
top: "8px",
|
|
488
|
+
right: "8px",
|
|
489
|
+
backgroundColor: "var(--md-sys-color-surface-container-high)",
|
|
490
|
+
border: "1px solid var(--md-sys-color-outline-variant)",
|
|
491
|
+
borderRadius: "4px",
|
|
492
|
+
padding: "6px",
|
|
493
|
+
fontSize: "14px",
|
|
494
|
+
cursor: "pointer",
|
|
495
|
+
color: "var(--md-sys-color-on-surface-variant)",
|
|
496
|
+
alignItems: "center",
|
|
497
|
+
justifyContent: "center",
|
|
498
|
+
transition: "all 0.2s ease",
|
|
499
|
+
width: "32px",
|
|
500
|
+
height: "32px"
|
|
501
|
+
},
|
|
502
|
+
onMouseEnter: (e) => {
|
|
503
|
+
e.currentTarget.style.backgroundColor = isDark ? "var(--md-sys-color-surface-container-highest)" : "var(--md-sys-color-surface-container-high)";
|
|
504
|
+
},
|
|
505
|
+
onMouseLeave: (e) => {
|
|
506
|
+
e.currentTarget.style.backgroundColor = isDark ? "var(--md-sys-color-surface-container-high)" : "var(--md-sys-color-surface-container-highest)";
|
|
507
|
+
},
|
|
508
|
+
title: copiedBlocks.has(blockId) ? "Copied!" : "Copy code",
|
|
509
|
+
children: copiedBlocks.has(blockId) ? /* @__PURE__ */ jsxRuntime.jsx(CheckIcon__default.default, { style: { fontSize: "16px" } }) : /* @__PURE__ */ jsxRuntime.jsx(ContentCopyIcon__default.default, { style: { fontSize: "16px" } })
|
|
510
|
+
}
|
|
511
|
+
)
|
|
512
|
+
] });
|
|
466
513
|
}
|
|
467
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
468
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { dangerouslySetInnerHTML: { __html: highlightedHtml } }),
|
|
469
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
470
|
-
"button",
|
|
471
|
-
{
|
|
472
|
-
onClick: () => copyToClipboard(codeText, blockId),
|
|
473
|
-
style: {
|
|
474
|
-
position: "absolute",
|
|
475
|
-
top: "8px",
|
|
476
|
-
right: "8px",
|
|
477
|
-
backgroundColor: "var(--md-sys-color-surface-container-high)",
|
|
478
|
-
border: "1px solid var(--md-sys-color-outline-variant)",
|
|
479
|
-
borderRadius: "4px",
|
|
480
|
-
padding: "6px",
|
|
481
|
-
fontSize: "14px",
|
|
482
|
-
cursor: "pointer",
|
|
483
|
-
color: "var(--md-sys-color-on-surface-variant)",
|
|
484
|
-
alignItems: "center",
|
|
485
|
-
justifyContent: "center",
|
|
486
|
-
transition: "all 0.2s ease",
|
|
487
|
-
width: "32px",
|
|
488
|
-
height: "32px"
|
|
489
|
-
},
|
|
490
|
-
onMouseEnter: (e) => {
|
|
491
|
-
e.currentTarget.style.backgroundColor = isDark ? "var(--md-sys-color-surface-container-highest)" : "var(--md-sys-color-surface-container-high)";
|
|
492
|
-
},
|
|
493
|
-
onMouseLeave: (e) => {
|
|
494
|
-
e.currentTarget.style.backgroundColor = isDark ? "var(--md-sys-color-surface-container-high)" : "var(--md-sys-color-surface-container-highest)";
|
|
495
|
-
},
|
|
496
|
-
title: copiedBlocks.has(blockId) ? "Copied!" : "Copy code",
|
|
497
|
-
children: copiedBlocks.has(blockId) ? /* @__PURE__ */ jsxRuntime.jsx(CheckIcon__default.default, { style: { fontSize: "16px" } }) : /* @__PURE__ */ jsxRuntime.jsx(ContentCopyIcon__default.default, { style: { fontSize: "16px" } })
|
|
498
|
-
}
|
|
499
|
-
)
|
|
500
|
-
] });
|
|
514
|
+
return /* @__PURE__ */ jsxRuntime.jsx("code", { className: className2, ...props, children });
|
|
501
515
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
) });
|
|
516
|
+
},
|
|
517
|
+
children: content
|
|
518
|
+
}
|
|
519
|
+
)
|
|
520
|
+
] });
|
|
508
521
|
};
|
|
509
522
|
var ReadmeViewer_default = ReadmeViewer;
|
|
510
523
|
var NotificationContext = react.createContext(void 0);
|
|
@@ -1174,7 +1187,7 @@ var HttpClient = class {
|
|
|
1174
1187
|
try {
|
|
1175
1188
|
error.data = await response.json();
|
|
1176
1189
|
} catch {
|
|
1177
|
-
error.data = await response.text();
|
|
1190
|
+
error.data = { code: response.status, message: await response.text() };
|
|
1178
1191
|
}
|
|
1179
1192
|
throw error;
|
|
1180
1193
|
}
|
|
@@ -1193,6 +1206,15 @@ var HttpClient = class {
|
|
|
1193
1206
|
throw error;
|
|
1194
1207
|
}
|
|
1195
1208
|
}
|
|
1209
|
+
setDefaultHeader(key, value) {
|
|
1210
|
+
this.defaultHeaders[key] = value;
|
|
1211
|
+
}
|
|
1212
|
+
removeDefaultHeader(key) {
|
|
1213
|
+
delete this.defaultHeaders[key];
|
|
1214
|
+
}
|
|
1215
|
+
getDefaultHeaders() {
|
|
1216
|
+
return { ...this.defaultHeaders };
|
|
1217
|
+
}
|
|
1196
1218
|
get(url, config) {
|
|
1197
1219
|
return this.request(url, { ...config, method: "GET" });
|
|
1198
1220
|
}
|
|
@@ -1209,6 +1231,16 @@ var HttpClient = class {
|
|
|
1209
1231
|
return this.request(url, { ...config, method: "DELETE" });
|
|
1210
1232
|
}
|
|
1211
1233
|
};
|
|
1234
|
+
function extractErrorMessage(error) {
|
|
1235
|
+
if (error instanceof Error) {
|
|
1236
|
+
const httpError = error;
|
|
1237
|
+
if (httpError.data) {
|
|
1238
|
+
return httpError.data.message;
|
|
1239
|
+
}
|
|
1240
|
+
return error.message;
|
|
1241
|
+
}
|
|
1242
|
+
return "An unexpected error occurred";
|
|
1243
|
+
}
|
|
1212
1244
|
|
|
1213
1245
|
// src/utils/cn.ts
|
|
1214
1246
|
function cn(...classes) {
|
|
@@ -1420,6 +1452,7 @@ exports.cn = cn;
|
|
|
1420
1452
|
exports.darkTheme = darkTheme;
|
|
1421
1453
|
exports.debounce = debounce;
|
|
1422
1454
|
exports.elevation = elevation;
|
|
1455
|
+
exports.extractErrorMessage = extractErrorMessage;
|
|
1423
1456
|
exports.fontSize = fontSize;
|
|
1424
1457
|
exports.fontWeight = fontWeight;
|
|
1425
1458
|
exports.formatDate = formatDate;
|