build: refactor & use handlebars for generate templating (#343)
This commit is contained in:
1 parent
b1f864c1c8
commit
f48eba6354
23 files changed
+681
-408
No files matched your search
@@ -0,0 +1,22 @@
|
||||
import Ajv, { Schema } from "ajv";
|
||||
import { parse } from "std/yaml/parse.ts";
|
||||
|
||||
/**
|
||||
* @param content A string of YAML content
|
||||
* @param schema A JSON schema
|
||||
* @returns A promise that resolves to the parsed YAML content, verified against the schema. Rejects if the content is invalid.
|
||||
*/
|
||||
export const validateYaml = <T>(
|
||||
content: string,
|
||||
schema: Schema,
|
||||
): Promise<T> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const ajv = new Ajv.default();
|
||||
const validate = ajv.compile<T>(schema);
|
||||
const data = parse(content);
|
||||
|
||||
if (!validate(data)) return reject(validate.errors);
|
||||
|
||||
return resolve(data);
|
||||
});
|
||||
};
|
||||
Reference in new issue
Block a user