typescript-runtime-schemas
Version:
A TypeScript schema generation tool that extracts Zod schemas from TypeScript source files with runtime validation support. Generate validation schemas directly from your existing TypeScript types with support for computed types and constraint-based valid
51 lines • 1.5 kB
JavaScript
;
/**
* Utility functions for source code detection and path handling
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.isSourceCode = isSourceCode;
exports.looksLikePath = looksLikePath;
/**
* Check if input is TypeScript source code vs file path
*/
function isSourceCode(input) {
// First check for TypeScript keywords - if present, it's likely source code
const tsKeywords = [
"type ",
"interface ",
"export ",
"import ",
"declare ",
"const ",
"let ",
"var ",
"function ",
"class ",
];
const hasKeywords = tsKeywords.some((keyword) => input.includes(keyword));
// If it has TypeScript keywords, it's probably source code
if (hasKeywords) {
return true;
}
// If it looks like a path and has no keywords, it's probably a path
if (looksLikePath(input)) {
return false;
}
// Default to treating as source code if unclear
return false;
}
/**
* Check if input looks like a file path
*/
function looksLikePath(input) {
// Simple heuristics to detect file paths
return (input.includes("/") ||
input.includes("\\") ||
input.endsWith(".ts") ||
input.endsWith(".tsx") ||
input.startsWith("./") ||
input.startsWith("../") ||
(input.length < 100 && !input.includes("\n")) // Short strings without newlines that look like paths
);
}
//# sourceMappingURL=utils.js.map