Auto Router, Discord Rules Page, & Vi18n lib (#52)
feat: Auto Router, Discord Rules Page, & Vi18n lib (#52)
This commit is contained in:
parent
262b8c578f
commit
8c59485898
51 changed files with 3479 additions and 782 deletions
1
apps/vdn-static/src/utils/css.ts
Normal file
1
apps/vdn-static/src/utils/css.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export type CssClass = string | false | null | undefined | CssClass[];
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
export type DeepPartial<T extends object> = {
|
||||
[K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
|
||||
};
|
||||
2
apps/vdn-static/src/utils/ignore.ts
Normal file
2
apps/vdn-static/src/utils/ignore.ts
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters, @typescript-eslint/no-unused-vars
|
||||
export function ignore<T>(_: T): void {}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
import type { Layout } from "@/i18n/locale";
|
||||
import type { DeepReadonly } from "vue";
|
||||
|
||||
export function localizeLayout<T>(
|
||||
layout: DeepReadonly<Layout<T>>,
|
||||
): T[keyof T][] {
|
||||
const sections: T[keyof T][] = [];
|
||||
for (const sectionId of layout.order ?? []) {
|
||||
const section = (layout.data as T)[sectionId as keyof T];
|
||||
if (section) {
|
||||
sections.push(section);
|
||||
}
|
||||
}
|
||||
|
||||
return sections;
|
||||
}
|
||||
11
apps/vdn-static/src/utils/smart-dest.ts
Normal file
11
apps/vdn-static/src/utils/smart-dest.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import type { RouteNamedMap } from "vue-router/auto-routes";
|
||||
|
||||
export type SmartDest =
|
||||
| { type: "internal"; internal: SmartInternalDest }
|
||||
| { type: "external"; external: SmartExternalDest };
|
||||
|
||||
export type SmartInternalDest =
|
||||
| { route: keyof RouteNamedMap; id?: string }
|
||||
| { route?: keyof RouteNamedMap; id: string };
|
||||
|
||||
export type SmartExternalDest = `https://${string}` | `http://${string}`;
|
||||
8
apps/vdn-static/src/utils/types.ts
Normal file
8
apps/vdn-static/src/utils/types.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
export type DeepPartial<T extends object> =
|
||||
T extends Function ? T
|
||||
: { [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K] };
|
||||
|
||||
export type Prettify<T> = T extends object ? { [K in keyof T]: T[K] } & {} : T;
|
||||
export type Value<T> = T[keyof T];
|
||||
|
||||
export type Result<T, E> = { type: "ok"; ok: T } | { type: "err"; err: E };
|
||||
11
apps/vdn-static/src/utils/unsafe.ts
Normal file
11
apps/vdn-static/src/utils/unsafe.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import type { Result } from "./types";
|
||||
|
||||
export async function unsafeAsync<R>(
|
||||
f: () => Promise<R>,
|
||||
): Promise<Result<R, unknown>> {
|
||||
try {
|
||||
return { type: "ok", ok: await f() };
|
||||
} catch (e) {
|
||||
return { type: "err", err: e };
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue