@@ -33,67 +33,81 @@ const newFile = updateTemplates(oldFile, transform);
3333
3434## API
3535
36- ### preprocess
36+ ### findTemplateTags
3737
38- Processes a file with ` <template> ` tags into things that work with existing methods or libraries.
39-
40- ⚠️ Likely, you won't need this method but [ ` updateJavaScript ` ] ( #updatejavascript ) instead.
38+ Finds ` <template> ` tags in a file.
4139
4240<details >
4341
4442<summary >Example</summary >
4543
46- Analyze the JavaScript part of the file .
44+ Count the number of lines of code (LOC) in ` <template> ` tags .
4745
4846``` ts
49- const { javascript } = preprocess (file );
47+ function getLOC(code : string ): number {
48+ const matches = file .match (/ \r ? \n / g );
5049
51- // Some method that checks `*.{js,ts}` files
52- analyze (javascript );
50+ return (matches ?? []).length ;
51+ }
52+
53+ const templateTags = findTemplateTags (file );
54+
55+ let loc = 0 ;
56+
57+ templateTags .forEach (({ contents }) => {
58+ loc += getLOC (contents .trim ());
59+ });
5360```
5461
5562</details >
5663
64+
65+ ### replaceTemplateTag
66+
67+ Replaces a particular ` <template> ` tag.
68+
69+ ⚠️ Likely, you won't need this method but [ ` updateTemplates ` ] ( #updatetemplates ) instead.
70+
5771<details >
5872
5973<summary >Example</summary >
6074
61- Count the number of lines inside ` <template> ` tags .
75+ Update all template tags in a file .
6276
6377``` ts
64- const { templateTags } = preprocess (file );
78+ const templateTags = findTemplateTags (file );
6579
66- let numOfLines = 0 ;
80+ templateTags .reverse ().forEach (({ contents , range }) => {
81+ // Some method that can update `*.hbs` files
82+ const template = transform (contents );
6783
68- templateTags .forEach (({ contents }) => {
69- numOfLines += contents .trim ().split (' \n ' ).length ;
84+ file = replaceTemplateTag (file , {
85+ code: ` <template>${template }</template> ` ,
86+ range ,
87+ });
7088});
7189```
7290
7391</details >
7492
7593
76- ### replaceTemplate
94+ ### toEcma
7795
78- Replaces the template of a particular ` <template> ` tag .
96+ Converts a file with ` <template> ` tags to standard JavaScript .
7997
80- ⚠️ Likely, you won't need this method but [ ` updateTemplates ` ] ( #updatetemplates ) instead.
98+ ⚠️ Likely, you won't need this method but [ ` updateJavaScript ` ] ( #updatejavascript ) instead.
8199
82100<details >
83101
84102<summary >Example</summary >
85103
86- Update the template in each tag .
104+ Analyze the JavaScript part of the file .
87105
88106``` ts
89- const { templateTags } = preprocess (file );
107+ const ecma = toEcma (file );
90108
91- templateTags .reverse ().forEach (({ contents , range }) => {
92- // Some method that can update `*.hbs` files
93- const template = transform (contents );
94-
95- file = replaceTemplate (file , { range , template });
96- });
109+ // Some method that checks `*.{js,ts}` files
110+ analyze (ecma );
97111```
98112
99113</details >
0 commit comments