fortify-schema
Version:
A modern TypeScript validation library designed around familiar interface syntax and powerful conditional validation. Experience schema validation that feels natural to TypeScript developers while unlocking advanced runtime validation capabilities.
55 lines (52 loc) • 1.61 kB
JavaScript
;
/**
* Schema analyzer for extracting field information
*/
class SchemaAnalyzer {
constructor(schema) {
this.schema = schema;
}
analyze() {
const fields = [];
Object.entries(this.schema).forEach(([name, type]) => {
fields.push(this.analyzeField(name, type));
});
return {
fields,
totalFields: fields.length,
requiredFields: fields.filter(f => f.required).length,
optionalFields: fields.filter(f => !f.required).length
};
}
analyzeField(name, type) {
const typeStr = typeof type === "string" ? type : JSON.stringify(type);
const required = !typeStr.includes("?");
return {
name,
type: typeStr,
required,
description: this.generateFieldDescription(name, typeStr)
};
}
generateFieldDescription(name, type) {
if (type === "email")
return "Email address";
if (type === "uuid")
return "Unique identifier";
if (type === "url")
return "URL address";
if (type.includes("string"))
return "Text value";
if (type.includes("number"))
return "Numeric value";
if (type === "boolean")
return "True/false value";
if (type === "date")
return "Date and time";
if (type.includes("[]"))
return "Array of values";
return `${name} field`;
}
}
exports.SchemaAnalyzer = SchemaAnalyzer;
//# sourceMappingURL=SchemaAnalyzer.js.map