mirror of
https://github.com/certd/certd.git
synced 2026-04-20 09:50:50 +08:00
38 lines
829 B
TypeScript
38 lines
829 B
TypeScript
import { importJsYaml } from "./async-import";
|
|
|
|
const jsonRule = {
|
|
validator: async (rule: any, value: any) => {
|
|
//校验value json的有效性
|
|
if (value) {
|
|
try {
|
|
JSON.parse(value);
|
|
} catch (e: any) {
|
|
console.error(e);
|
|
throw new Error("json格式错误:" + e.message);
|
|
}
|
|
}
|
|
},
|
|
message: "json格式错误",
|
|
};
|
|
|
|
const yamlRule = {
|
|
validator: async (rule: any, value: any) => {
|
|
//校验value yaml的有效性
|
|
if (value) {
|
|
try {
|
|
const yaml = await importJsYaml();
|
|
yaml.load(value, { schema: yaml.JSON_SCHEMA });
|
|
} catch (e: any) {
|
|
console.error(e);
|
|
throw new Error("yaml格式错误:" + e.message);
|
|
}
|
|
}
|
|
},
|
|
message: "yaml格式错误",
|
|
};
|
|
|
|
export const FsEditorCodeValidators = {
|
|
jsonRule,
|
|
yamlRule,
|
|
};
|