You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
682 B
24 lines
682 B
import { z } from "zod";
|
|
|
|
export const hashConfigSchema = z.object({
|
|
defaultAlgorithm: z
|
|
.enum(["md5", "sha1", "sha256", "sha512"])
|
|
.default("sha256")
|
|
.describe("默认哈希算法"),
|
|
uppercase: z.boolean().default(false).describe("输出是否大写"),
|
|
});
|
|
|
|
export type HashToolConfig = z.infer<typeof hashConfigSchema>;
|
|
|
|
export const DEFAULT_HASH_CONFIG: HashToolConfig = {
|
|
defaultAlgorithm: "sha256",
|
|
uppercase: false,
|
|
};
|
|
|
|
export function parseHashConfig(raw: unknown): HashToolConfig {
|
|
const parsed = hashConfigSchema.safeParse(raw);
|
|
if (!parsed.success) {
|
|
throw new Error(`Invalid hash config: ${parsed.error.message}`);
|
|
}
|
|
return parsed.data;
|
|
}
|
|
|