@@ -240,13 +240,15 @@ export class Ecto extends Hookified {
240240 }
241241
242242 /**
243- * Async render the source with the data
244- * @param {string } source - The source to render
245- * @param {Record<string, unknown } data - data to render with the source
246- * @param {string } [engineName] - The engine to use for rendering
247- * @param {string } [rootTemplatePath] - The root path to the template if using includes / partials
248- * @param {string } [filePathOutput] - The file path to write the output
249- * @returns {Promise<string> }
243+ * Asynchronously render a template source with data using the specified engine
244+ * @param {string } source - The template source string to render
245+ * @param {Record<string, unknown> } [data] - Data object to pass to the template engine
246+ * @param {string } [engineName] - Name of the engine to use (e.g., 'ejs', 'pug'). Defaults to defaultEngine
247+ * @param {string } [rootTemplatePath] - Root directory path for template includes/partials resolution
248+ * @param {string } [filePathOutput] - Optional file path to write the rendered output to
249+ * @returns {Promise<string> } The rendered template output as a string
250+ * @example
251+ * const result = await ecto.render('<%= name %>', { name: 'World' }, 'ejs');
250252 */
251253 public async render (
252254 source : string ,
@@ -304,13 +306,15 @@ export class Ecto extends Hookified {
304306 }
305307
306308 /**
307- * Synchronously render the source with the data
308- * @param {string } source - The source to render
309- * @param {Record<string, unknown } data - data to render with the source
310- * @param {string } [engineName] - The engine to use for rendering
311- * @param {string } [rootTemplatePath] - The root path to the template if using includes / partials
312- * @param {string } [filePathOutput] - The file path to write the output
313- * @returns {string }
309+ * Synchronously render a template source with data using the specified engine
310+ * @param {string } source - The template source string to render
311+ * @param {Record<string, unknown> } [data] - Data object to pass to the template engine
312+ * @param {string } [engineName] - Name of the engine to use (e.g., 'ejs', 'pug'). Defaults to defaultEngine
313+ * @param {string } [rootTemplatePath] - Root directory path for template includes/partials resolution
314+ * @param {string } [filePathOutput] - Optional file path to write the rendered output to
315+ * @returns {string } The rendered template output as a string
316+ * @example
317+ * const result = ecto.renderSync('<%= name %>', { name: 'World' }, 'ejs');
314318 */
315319 public renderSync (
316320 source : string ,
@@ -368,13 +372,15 @@ export class Ecto extends Hookified {
368372 }
369373
370374 /**
371- * Render from a file path
372- * @param {string } filePath - The file path to the source
373- * @param {Record<string, unknown> } data - The data to render with the source
374- * @param {string } [rootTemplatePath] - The root path to the template if using includes / partials
375- * @param {string } [filePathOutput] - The file path to write the output
376- * @param {string } [engineName] - The engine to use for rendering
377- * @returns
375+ * Asynchronously render a template from a file path
376+ * @param {string } filePath - Path to the template file to render
377+ * @param {Record<string, unknown> } [data] - Data object to pass to the template engine
378+ * @param {string } [rootTemplatePath] - Root directory for template includes. Defaults to file's directory
379+ * @param {string } [filePathOutput] - Optional file path to write the rendered output to
380+ * @param {string } [engineName] - Engine to use. If not specified, determined from file extension
381+ * @returns {Promise<string> } The rendered template output as a string
382+ * @example
383+ * const result = await ecto.renderFromFile('./templates/index.ejs', { title: 'Home' });
378384 */
379385 public async renderFromFile (
380386 filePath : string ,
@@ -405,13 +411,15 @@ export class Ecto extends Hookified {
405411 }
406412
407413 /**
408- * Sync render from a file path
409- * @param {string } filePath - The file path to the source
410- * @param {Record<string, unknown> } data - The data to render with the source
411- * @param {string } [rootTemplatePath] - The root path to the template if using includes / partials
412- * @param {string } [filePathOutput] - The file path to write the output
413- * @param {string } [engineName] - The engine to use for rendering
414- * @returns {string }
414+ * Synchronously render a template from a file path
415+ * @param {string } filePath - Path to the template file to render
416+ * @param {Record<string, unknown> } [data] - Data object to pass to the template engine
417+ * @param {string } [rootTemplatePath] - Root directory for template includes. Defaults to file's directory
418+ * @param {string } [filePathOutput] - Optional file path to write the rendered output to
419+ * @param {string } [engineName] - Engine to use. If not specified, determined from file extension
420+ * @returns {string } The rendered template output as a string
421+ * @example
422+ * const result = ecto.renderFromFileSync('./templates/index.ejs', { title: 'Home' });
415423 */
416424 public renderFromFileSync (
417425 filePath : string ,
@@ -442,9 +450,11 @@ export class Ecto extends Hookified {
442450 }
443451
444452 /**
445- * Ensure the file path exists or create it
446- * @param {string } path
453+ * Asynchronously ensure that the directory path for a file exists, creating it if necessary
454+ * @param {string } path - The full file path (directories will be extracted from this)
447455 * @returns {Promise<void> }
456+ * @example
457+ * await ecto.ensureFilePath('/path/to/file.txt');
448458 */
449459 public async ensureFilePath ( path : string ) {
450460 const pathList = path . split ( "/" ) ;
@@ -458,9 +468,11 @@ export class Ecto extends Hookified {
458468 }
459469
460470 /**
461- * Ensure the file path exists or create it synchronously
462- * @param {string } path
471+ * Synchronously ensure that the directory path for a file exists, creating it if necessary
472+ * @param {string } path - The full file path (directories will be extracted from this)
463473 * @returns {void }
474+ * @example
475+ * ecto.ensureFilePathSync('/path/to/file.txt');
464476 */
465477 public ensureFilePathSync ( path : string ) {
466478 const pathList = path . split ( "/" ) ;
@@ -474,9 +486,11 @@ export class Ecto extends Hookified {
474486 }
475487
476488 /**
477- * Get the Engine By File Path
478- * @param {string } filePath
479- * @returns {string } - will return the engine name such as 'ejs', 'markdown', 'pug', 'nunjucks', 'handlebars', 'liquid'
489+ * Determine the appropriate template engine based on a file's extension
490+ * @param {string } filePath - The file path to analyze
491+ * @returns {string } The engine name (e.g., 'ejs', 'markdown', 'pug', 'nunjucks', 'handlebars', 'liquid')
492+ * @example
493+ * const engine = ecto.getEngineByFilePath('template.ejs'); // Returns 'ejs'
480494 */
481495 public getEngineByFilePath ( filePath : string ) : string {
482496 let result = this . _defaultEngine ;
@@ -496,10 +510,12 @@ export class Ecto extends Hookified {
496510 }
497511
498512 /**
499- * Find the template without the extension. This will look in a directory for a file that starts with the template name
500- * @param {string } path - the path to look for the template file
501- * @param {string } templateName
502- * @returns {Promise<string> } - the path to the template file
513+ * Asynchronously find a template file in a directory by name, regardless of extension
514+ * @param {string } path - Directory path to search in
515+ * @param {string } templateName - Template name without extension
516+ * @returns {Promise<string> } Full path to the found template file, or empty string if not found
517+ * @example
518+ * const templatePath = await ecto.findTemplateWithoutExtension('./templates', 'index');
503519 */
504520 public async findTemplateWithoutExtension (
505521 path : string ,
@@ -520,10 +536,12 @@ export class Ecto extends Hookified {
520536 }
521537
522538 /**
523- * Syncronously find the template without the extension. This will look in a directory for a file that starts with the template name
524- * @param {string } path - the path to look for the template file
525- * @param {string } templateName
526- * @returns {string } - the path to the template file
539+ * Synchronously find a template file in a directory by name, regardless of extension
540+ * @param {string } path - Directory path to search in
541+ * @param {string } templateName - Template name without extension
542+ * @returns {string } Full path to the found template file, or empty string if not found
543+ * @example
544+ * const templatePath = ecto.findTemplateWithoutExtensionSync('./templates', 'index');
527545 */
528546 public findTemplateWithoutExtensionSync (
529547 path : string ,
@@ -544,9 +562,11 @@ export class Ecto extends Hookified {
544562 }
545563
546564 /**
547- * Is it a valid engine that is registered in ecto
548- * @param engineName
549- * @returns {boolean }
565+ * Check if the given engine name is valid and registered in Ecto
566+ * @param {string } [engineName] - The engine name to validate
567+ * @returns {boolean } True if the engine is valid and registered, false otherwise
568+ * @example
569+ * const isValid = ecto.isValidEngine('ejs'); // Returns true
550570 */
551571 public isValidEngine ( engineName ?: string ) : boolean {
552572 let result = false ;
@@ -562,8 +582,9 @@ export class Ecto extends Hookified {
562582 }
563583
564584 /**
565- * Register the engine mappings
585+ * Register all engine mappings between engine names and file extensions
566586 * @returns {void }
587+ * @private
567588 */
568589 public registerEngineMappings ( ) : void {
569590 for ( const eng of this . _engines ) {
@@ -574,9 +595,11 @@ export class Ecto extends Hookified {
574595 }
575596
576597 /**
577- * Get Render Engine by the engine name. Default is EJS
578- * @param {string } engineName
579- * @returns {EngineInterface }
598+ * Get the render engine instance by name
599+ * @param {string } engineName - The name of the engine to retrieve
600+ * @returns {EngineInterface } The engine instance (defaults to EJS if not found)
601+ * @example
602+ * const engine = ecto.getRenderEngine('pug');
580603 */
581604 public getRenderEngine ( engineName : string ) : EngineInterface {
582605 let result = this . _ejs ; // Setting default
@@ -623,9 +646,11 @@ export class Ecto extends Hookified {
623646 }
624647
625648 /**
626- * Checks if the source has front matter
627- * @param {string } source
628- * @returns {boolean }
649+ * Check if the source content contains front matter (YAML metadata)
650+ * @param {string } source - The source content to check
651+ * @returns {boolean } True if front matter is present, false otherwise
652+ * @example
653+ * const hasFM = ecto.hasFrontMatter('---\ntitle: Test\n---\nContent');
629654 */
630655 public hasFrontMatter ( source : string ) : boolean {
631656 const writr = new Writr ( source ) ;
@@ -637,20 +662,24 @@ export class Ecto extends Hookified {
637662 }
638663
639664 /**
640- * Get the Front Matter from the source
641- * @param {string } source
642- * @returns {Record<string, unknown> }
665+ * Extract front matter data from the source content
666+ * @param {string } source - The source content containing front matter
667+ * @returns {Record<string, unknown> } Parsed front matter as an object
668+ * @example
669+ * const data = ecto.getFrontMatter('---\ntitle: Test\n---\nContent');
643670 */
644671 public getFrontMatter ( source : string ) : Record < string , unknown > {
645672 const writr = new Writr ( source ) ;
646673 return writr . frontMatter ;
647674 }
648675
649676 /**
650- * Will set the front matter in the source and return the source
651- * @param {string } source - The source to set the front matter
652- * @param {Record<string, unknown> } data - The front matter data
653- * @returns {string } - The source with the front matter
677+ * Set or replace front matter in the source content
678+ * @param {string } source - The source content
679+ * @param {Record<string, unknown> } data - The front matter data to set
680+ * @returns {string } The source content with updated front matter
681+ * @example
682+ * const updated = ecto.setFrontMatter('Content', { title: 'New Title' });
654683 */
655684 public setFrontMatter ( source : string , data : Record < string , unknown > ) : string {
656685 const writr = new Writr ( source ) ;
@@ -659,22 +688,38 @@ export class Ecto extends Hookified {
659688 }
660689
661690 /**
662- * Remove the Front Matter from the source
663- * @param {string } source
664- * @returns {string }
691+ * Remove front matter from the source content, returning only the body
692+ * @param {string } source - The source content with front matter
693+ * @returns {string } The source content without front matter
694+ * @example
695+ * const body = ecto.removeFrontMatter('---\ntitle: Test\n---\nContent');
665696 */
666697 public removeFrontMatter ( source : string ) : string {
667698 const writr = new Writr ( source ) ;
668699 return writr . body ;
669700 }
670701
702+ /**
703+ * Write content to a file asynchronously, creating directories if needed
704+ * @private
705+ * @param {string } [filePath] - The path to write the file to
706+ * @param {string } [source] - The content to write to the file
707+ * @returns {Promise<void> }
708+ */
671709 private async writeFile ( filePath ?: string , source ?: string ) {
672710 if ( filePath && source ) {
673711 await this . ensureFilePath ( filePath ) ;
674712 await fs . promises . writeFile ( filePath , source ) ;
675713 }
676714 }
677715
716+ /**
717+ * Write content to a file synchronously, creating directories if needed
718+ * @private
719+ * @param {string } [filePath] - The path to write the file to
720+ * @param {string } [source] - The content to write to the file
721+ * @returns {void }
722+ */
678723 private writeFileSync ( filePath ?: string , source ?: string ) {
679724 if ( filePath && source ) {
680725 this . ensureFilePathSync ( filePath ) ;
0 commit comments