utils.ts — astro Source File
Architecture documentation for utils.ts, a typescript file in the astro codebase. 2 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 839dada7_8bd4_2ee4_9498_f38d21d2f7e9["utils.ts"] 5d635c24_aea1_c7f7_2c64_4fe0f5e4041b["../core/parseAstro.js"] 839dada7_8bd4_2ee4_9498_f38d21d2f7e9 --> 5d635c24_aea1_c7f7_2c64_4fe0f5e4041b 4e2ee814_ff7b_a348_0e3a_6e6d7b34afb6["vscode-html-languageservice"] 839dada7_8bd4_2ee4_9498_f38d21d2f7e9 --> 4e2ee814_ff7b_a348_0e3a_6e6d7b34afb6 b9e6df3b_0db3_5da0_196d_ad954be5a3bd["parseHTML.ts"] b9e6df3b_0db3_5da0_196d_ad954be5a3bd --> 839dada7_8bd4_2ee4_9498_f38d21d2f7e9 style 839dada7_8bd4_2ee4_9498_f38d21d2f7e9 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import type { HTMLDocument, Node, TextEdit } from 'vscode-html-languageservice';
import { Range } from 'vscode-html-languageservice';
import type { AstroMetadata, FrontmatterStatus } from '../core/parseAstro.js';
export function isJSDocument(languageId: string) {
return (
languageId === 'javascript' ||
languageId === 'typescript' ||
languageId === 'javascriptreact' ||
languageId === 'typescriptreact'
);
}
/**
* Return true if a specific node could be a component.
* This is not a 100% sure test as it'll return false for any component that does not match the standard format for a component
*/
export function isPossibleComponent(node: Node): boolean {
if (!node.tag) return false;
return !!/[A-Z]/.test(node.tag?.[0]) || !!/.+\.[A-Z]?/.test(node.tag);
}
/**
* Return if a given offset is inside the start tag of a component
*/
export function isInComponentStartTag(html: HTMLDocument, offset: number): boolean {
const node = html.findNodeAt(offset);
return isPossibleComponent(node) && (!node.startTagEnd || offset < node.startTagEnd);
}
/**
* Return if a given position is inside a JSX expression
*/
export function isInsideExpression(html: string, tagStart: number, position: number) {
const charactersInNode = html.substring(tagStart, position);
return charactersInNode.lastIndexOf('{') > charactersInNode.lastIndexOf('}');
}
/**
* Return if a given offset is inside the frontmatter
*/
export function isInsideFrontmatter(offset: number, frontmatter: FrontmatterStatus) {
switch (frontmatter.status) {
case 'closed':
return offset > frontmatter.position.start.offset && offset < frontmatter.position.end.offset;
case 'open':
return offset > frontmatter.position.start.offset;
case 'doesnt-exist':
return false;
}
}
type FrontmatterEditPosition = 'top' | 'bottom';
export function ensureProperEditForFrontmatter(
edit: TextEdit,
metadata: AstroMetadata,
newLine: string,
position: FrontmatterEditPosition = 'top',
): TextEdit {
// ... (102 more lines)
Domain
Subdomains
Functions
Dependencies
- ../core/parseAstro.js
- vscode-html-languageservice
Source
Frequently Asked Questions
What does utils.ts do?
utils.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 utils.ts?
utils.ts defines 10 function(s): editShouldBeInFrontmatter, ensureProperEditForFrontmatter, ensureRangeIsInFrontmatter, getNewFrontmatterEdit, getOpenFrontmatterEdit, isInComponentStartTag, isInsideExpression, isInsideFrontmatter, isJSDocument, isPossibleComponent.
What does utils.ts depend on?
utils.ts imports 2 module(s): ../core/parseAstro.js, vscode-html-languageservice.
What files import utils.ts?
utils.ts is imported by 1 file(s): parseHTML.ts.
Where is utils.ts in the architecture?
utils.ts is located at packages/language-tools/language-server/src/plugins/utils.ts (domain: CoreAstro, subdomain: CoreMiddleware, directory: packages/language-tools/language-server/src/plugins).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free