yaml2ts.ts — astro Source File
Architecture documentation for yaml2ts.ts, a typescript file in the astro codebase. 2 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 049255e0_f9ac_b050_4b5b_56c85d17f188["yaml2ts.ts"] 040ca79b_dadf_4383_efd2_c0b13744e9f1["language-core"] 049255e0_f9ac_b050_4b5b_56c85d17f188 --> 040ca79b_dadf_4383_efd2_c0b13744e9f1 96e15012_9aaf_3132_0577_b7a99d92865b["yaml"] 049255e0_f9ac_b050_4b5b_56c85d17f188 --> 96e15012_9aaf_3132_0577_b7a99d92865b style 049255e0_f9ac_b050_4b5b_56c85d17f188 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import type { CodeMapping, VirtualCode } from '@volar/language-core';
import type { YAMLError, YAMLMap, YAMLSeq } from 'yaml';
import YAML, { CST, isCollection, isMap, isScalar, isSeq, parseDocument } from 'yaml';
export const VIRTUAL_CODE_ID = 'frontmatter-ts';
export type YAML2TSResult = {
errors: YAMLError[];
virtualCode: VirtualCode;
};
const ONLY_NAV_CODE_INFO: CodeMapping['data'] = {
verification: false,
completion: false,
semantic: false,
navigation: true,
structure: false,
format: false,
};
export function yaml2ts(frontmatter: string, collection: string): YAML2TSResult {
const frontmatterMappings: CodeMapping[] = [];
const frontmatterContent = parseDocument(frontmatter, {
keepSourceTokens: true,
customTags: ['timestamp'], // Handle YAML timestamps
// Those two options prevent `yaml` from throwing errors when it encounters parsing errors, which is useful for handling incomplete content
strict: false,
logLevel: 'silent',
});
let fullResult = 'import type { InferEntrySchema } from "astro:content";\n\n(\n';
let objectContent = frontmatter.trim().length > 0 ? '' : '{}'; // If there's no content, provide an empty object so that there's no syntax error
YAML.visit(frontmatterContent, {
Value(key, value) {
if (isCollection(value)) {
if (isMap(value)) {
mapMap(value, key);
}
if (isSeq(value)) {
mapSeq(value);
}
}
// If we didn't hit any of the above, we have a scalar value which in almost all cases is a Pair that's just not fully written yet
if (isScalar(value)) {
const itemKey = mapScalarKey(value);
// We don't care about values, just keys, since we're only interested in the structure
objectContent += `${itemKey}: null\n`;
}
return YAML.visit.REMOVE;
},
});
function mapMap(map: YAMLMap, key?: string | number | null) {
objectContent += '{\n';
// Go through all the items in the map
// ... (95 more lines)
Domain
Subdomains
Functions
Types
Dependencies
- language-core
- yaml
Source
Frequently Asked Questions
What does yaml2ts.ts do?
yaml2ts.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, CoreMiddleware subdomain.
What functions are defined in yaml2ts.ts?
yaml2ts.ts defines 1 function(s): yaml2ts.
What does yaml2ts.ts depend on?
yaml2ts.ts imports 2 module(s): language-core, yaml.
Where is yaml2ts.ts in the architecture?
yaml2ts.ts is located at packages/language-tools/yaml2ts/src/yaml2ts.ts (domain: CoreAstro, subdomain: CoreMiddleware, directory: packages/language-tools/yaml2ts/src).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free