@itrocks/template 0.0.26 → 0.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/template.d.ts +4 -3
- package/cjs/template.js +14 -15
- package/esm/template.d.ts +4 -3
- package/esm/template.js +11 -9
- package/package.json +1 -1
    
        package/cjs/template.d.ts
    CHANGED
    
    | @@ -1,11 +1,12 @@ | |
| 1 1 | 
             
            import { SortedArray } from '@itrocks/sorted-array';
         | 
| 2 | 
            -
            type  | 
| 2 | 
            +
            type BlockStackEntry = {
         | 
| 3 3 | 
             
                blockStart: number;
         | 
| 4 4 | 
             
                collection: any[];
         | 
| 5 | 
            +
                condition?: boolean;
         | 
| 5 6 | 
             
                data: any;
         | 
| 6 7 | 
             
                iteration: number;
         | 
| 7 8 | 
             
                iterations: number;
         | 
| 8 | 
            -
            } | 
| 9 | 
            +
            };
         | 
| 9 10 | 
             
            export type VariableParser = [parser: string, (variable: string, data: any) => any];
         | 
| 10 11 | 
             
            export declare const frontScripts: SortedArray<string>;
         | 
| 11 12 | 
             
            export { Template };
         | 
| @@ -13,7 +14,7 @@ export default class Template { | |
| 13 14 | 
             
                data?: any;
         | 
| 14 15 | 
             
                containerData?: any;
         | 
| 15 16 | 
             
                blockBack: number;
         | 
| 16 | 
            -
                blockStack:  | 
| 17 | 
            +
                blockStack: BlockStackEntry[];
         | 
| 17 18 | 
             
                doExpression: boolean;
         | 
| 18 19 | 
             
                index: number;
         | 
| 19 20 | 
             
                length: number;
         | 
    
        package/cjs/template.js
    CHANGED
    
    | @@ -1,11 +1,8 @@ | |
| 1 1 | 
             
            "use strict";
         | 
| 2 | 
            -
            var __importDefault = (this && this.__importDefault) || function (mod) {
         | 
| 3 | 
            -
                return (mod && mod.__esModule) ? mod : { "default": mod };
         | 
| 4 | 
            -
            };
         | 
| 5 2 | 
             
            Object.defineProperty(exports, "__esModule", { value: true });
         | 
| 6 3 | 
             
            exports.Template = exports.frontScripts = void 0;
         | 
| 7 | 
            -
            const  | 
| 8 | 
            -
            const  | 
| 4 | 
            +
            const app_dir_1 = require("@itrocks/app-dir");
         | 
| 5 | 
            +
            const rename_1 = require("@itrocks/rename");
         | 
| 9 6 | 
             
            const sorted_array_1 = require("@itrocks/sorted-array");
         | 
| 10 7 | 
             
            const promises_1 = require("node:fs/promises");
         | 
| 11 8 | 
             
            const node_path_1 = require("node:path");
         | 
| @@ -16,7 +13,7 @@ class Template { | |
| 16 13 | 
             
                containerData;
         | 
| 17 14 | 
             
                // block stack
         | 
| 18 15 | 
             
                blockBack = 0;
         | 
| 19 | 
            -
                blockStack;
         | 
| 16 | 
            +
                blockStack = [];
         | 
| 20 17 | 
             
                // parser
         | 
| 21 18 | 
             
                doExpression = true;
         | 
| 22 19 | 
             
                index = 0;
         | 
| @@ -65,7 +62,6 @@ class Template { | |
| 65 62 | 
             
                    this.addLinks.distinct = true;
         | 
| 66 63 | 
             
                    this.doneLinks.distinct = true;
         | 
| 67 64 | 
             
                    this.headLinks.distinct = true;
         | 
| 68 | 
            -
                    this.blockStack = [];
         | 
| 69 65 | 
             
                    if (containerData) {
         | 
| 70 66 | 
             
                        this.blockStack.push({ blockStart: 0, collection: [], data: containerData, iteration: 0, iterations: 1 });
         | 
| 71 67 | 
             
                    }
         | 
| @@ -391,8 +387,12 @@ class Template { | |
| 391 387 | 
             
                        return variable.substring(1, variable.length - 1);
         | 
| 392 388 | 
             
                    }
         | 
| 393 389 | 
             
                    if (firstChar === '-') {
         | 
| 394 | 
            -
                         | 
| 395 | 
            -
                         | 
| 390 | 
            +
                        let dataBack;
         | 
| 391 | 
            +
                        do {
         | 
| 392 | 
            +
                            this.blockBack++;
         | 
| 393 | 
            +
                            dataBack = this.blockStack[this.blockStack.length - this.blockBack];
         | 
| 394 | 
            +
                        } while (dataBack.condition);
         | 
| 395 | 
            +
                        return dataBack.data;
         | 
| 396 396 | 
             
                    }
         | 
| 397 397 | 
             
                    for (const [prefix, callback] of this.parsers) {
         | 
| 398 398 | 
             
                        if (firstChar === prefix) {
         | 
| @@ -400,7 +400,7 @@ class Template { | |
| 400 400 | 
             
                        }
         | 
| 401 401 | 
             
                    }
         | 
| 402 402 | 
             
                    if (data[variable] === undefined) {
         | 
| 403 | 
            -
                        data = new rename_1. | 
| 403 | 
            +
                        data = new rename_1.Str(data);
         | 
| 404 404 | 
             
                    }
         | 
| 405 405 | 
             
                    let value = data[variable];
         | 
| 406 406 | 
             
                    return (((typeof value)[0] === 'f') && ((value + '')[0] !== 'c'))
         | 
| @@ -455,8 +455,7 @@ class Template { | |
| 455 455 | 
             
                                    continue;
         | 
| 456 456 | 
             
                                }
         | 
| 457 457 | 
             
                                // end condition / loop block
         | 
| 458 | 
            -
                                if (' | 
| 459 | 
            -
                                    && ['end-->', 'END-->'].includes(this.source.substring(this.index, this.index + 6))) {
         | 
| 458 | 
            +
                                if ((firstChar === 'e') && (this.source.substring(this.index, this.index + 6) === 'end-->')) {
         | 
| 460 459 | 
             
                                    this.target += this.trimEndLine(this.source.substring(this.start, tagIndex));
         | 
| 461 460 | 
             
                                    iteration++;
         | 
| 462 461 | 
             
                                    if (iteration < iterations) {
         | 
| @@ -487,7 +486,7 @@ class Template { | |
| 487 486 | 
             
                                this.target = '';
         | 
| 488 487 | 
             
                                this.inLiteral = false;
         | 
| 489 488 | 
             
                                const condition = await this.parseExpression(data, '}', '-->');
         | 
| 490 | 
            -
                                this.blockStack.push({ blockStart, collection, data, iteration, iterations });
         | 
| 489 | 
            +
                                this.blockStack.push({ blockStart, collection, condition, data, iteration, iterations });
         | 
| 491 490 | 
             
                                let blockData = condition ? (this.target ? data : undefined) : this.target;
         | 
| 492 491 | 
             
                                blockStart = this.index;
         | 
| 493 492 | 
             
                                iteration = 0;
         | 
| @@ -657,7 +656,7 @@ class Template { | |
| 657 656 | 
             
                                        }
         | 
| 658 657 | 
             
                                        if (inLinkHRef && attributeValue.endsWith('.css')) {
         | 
| 659 658 | 
             
                                            let frontStyle = (0, node_path_1.normalize)(this.filePath + node_path_1.sep + this.source.substring(this.start, this.index))
         | 
| 660 | 
            -
                                                .substring(app_dir_1. | 
| 659 | 
            +
                                                .substring(app_dir_1.appDir.length);
         | 
| 661 660 | 
             
                                            if (node_path_1.sep !== '/') {
         | 
| 662 661 | 
             
                                                frontStyle = frontStyle.replaceAll(node_path_1.sep, '/');
         | 
| 663 662 | 
             
                                            }
         | 
| @@ -666,7 +665,7 @@ class Template { | |
| 666 665 | 
             
                                        }
         | 
| 667 666 | 
             
                                        if (inScriptSrc && attributeValue.endsWith('.js')) {
         | 
| 668 667 | 
             
                                            let frontScript = (0, node_path_1.normalize)(this.filePath + node_path_1.sep + this.source.substring(this.start, this.index))
         | 
| 669 | 
            -
                                                .substring(app_dir_1. | 
| 668 | 
            +
                                                .substring(app_dir_1.appDir.length);
         | 
| 670 669 | 
             
                                            if (node_path_1.sep !== '/') {
         | 
| 671 670 | 
             
                                                frontScript = frontScript.replaceAll(node_path_1.sep, '/');
         | 
| 672 671 | 
             
                                            }
         | 
    
        package/esm/template.d.ts
    CHANGED
    
    | @@ -1,11 +1,12 @@ | |
| 1 1 | 
             
            import { SortedArray } from '@itrocks/sorted-array';
         | 
| 2 | 
            -
            type  | 
| 2 | 
            +
            type BlockStackEntry = {
         | 
| 3 3 | 
             
                blockStart: number;
         | 
| 4 4 | 
             
                collection: any[];
         | 
| 5 | 
            +
                condition?: boolean;
         | 
| 5 6 | 
             
                data: any;
         | 
| 6 7 | 
             
                iteration: number;
         | 
| 7 8 | 
             
                iterations: number;
         | 
| 8 | 
            -
            } | 
| 9 | 
            +
            };
         | 
| 9 10 | 
             
            export type VariableParser = [parser: string, (variable: string, data: any) => any];
         | 
| 10 11 | 
             
            export declare const frontScripts: SortedArray<string>;
         | 
| 11 12 | 
             
            export { Template };
         | 
| @@ -13,7 +14,7 @@ export default class Template { | |
| 13 14 | 
             
                data?: any;
         | 
| 14 15 | 
             
                containerData?: any;
         | 
| 15 16 | 
             
                blockBack: number;
         | 
| 16 | 
            -
                blockStack:  | 
| 17 | 
            +
                blockStack: BlockStackEntry[];
         | 
| 17 18 | 
             
                doExpression: boolean;
         | 
| 18 19 | 
             
                index: number;
         | 
| 19 20 | 
             
                length: number;
         | 
    
        package/esm/template.js
    CHANGED
    
    | @@ -1,5 +1,5 @@ | |
| 1 | 
            -
            import  | 
| 2 | 
            -
            import  | 
| 1 | 
            +
            import { appDir } from '@itrocks/app-dir';
         | 
| 2 | 
            +
            import { Str } from '@itrocks/rename';
         | 
| 3 3 | 
             
            import { SortedArray } from '@itrocks/sorted-array';
         | 
| 4 4 | 
             
            import { readFile } from 'node:fs/promises';
         | 
| 5 5 | 
             
            import { normalize, sep } from 'node:path';
         | 
| @@ -11,7 +11,7 @@ export default class Template { | |
| 11 11 | 
             
                containerData;
         | 
| 12 12 | 
             
                // block stack
         | 
| 13 13 | 
             
                blockBack = 0;
         | 
| 14 | 
            -
                blockStack;
         | 
| 14 | 
            +
                blockStack = [];
         | 
| 15 15 | 
             
                // parser
         | 
| 16 16 | 
             
                doExpression = true;
         | 
| 17 17 | 
             
                index = 0;
         | 
| @@ -60,7 +60,6 @@ export default class Template { | |
| 60 60 | 
             
                    this.addLinks.distinct = true;
         | 
| 61 61 | 
             
                    this.doneLinks.distinct = true;
         | 
| 62 62 | 
             
                    this.headLinks.distinct = true;
         | 
| 63 | 
            -
                    this.blockStack = [];
         | 
| 64 63 | 
             
                    if (containerData) {
         | 
| 65 64 | 
             
                        this.blockStack.push({ blockStart: 0, collection: [], data: containerData, iteration: 0, iterations: 1 });
         | 
| 66 65 | 
             
                    }
         | 
| @@ -386,8 +385,12 @@ export default class Template { | |
| 386 385 | 
             
                        return variable.substring(1, variable.length - 1);
         | 
| 387 386 | 
             
                    }
         | 
| 388 387 | 
             
                    if (firstChar === '-') {
         | 
| 389 | 
            -
                         | 
| 390 | 
            -
                         | 
| 388 | 
            +
                        let dataBack;
         | 
| 389 | 
            +
                        do {
         | 
| 390 | 
            +
                            this.blockBack++;
         | 
| 391 | 
            +
                            dataBack = this.blockStack[this.blockStack.length - this.blockBack];
         | 
| 392 | 
            +
                        } while (dataBack.condition);
         | 
| 393 | 
            +
                        return dataBack.data;
         | 
| 391 394 | 
             
                    }
         | 
| 392 395 | 
             
                    for (const [prefix, callback] of this.parsers) {
         | 
| 393 396 | 
             
                        if (firstChar === prefix) {
         | 
| @@ -450,8 +453,7 @@ export default class Template { | |
| 450 453 | 
             
                                    continue;
         | 
| 451 454 | 
             
                                }
         | 
| 452 455 | 
             
                                // end condition / loop block
         | 
| 453 | 
            -
                                if (' | 
| 454 | 
            -
                                    && ['end-->', 'END-->'].includes(this.source.substring(this.index, this.index + 6))) {
         | 
| 456 | 
            +
                                if ((firstChar === 'e') && (this.source.substring(this.index, this.index + 6) === 'end-->')) {
         | 
| 455 457 | 
             
                                    this.target += this.trimEndLine(this.source.substring(this.start, tagIndex));
         | 
| 456 458 | 
             
                                    iteration++;
         | 
| 457 459 | 
             
                                    if (iteration < iterations) {
         | 
| @@ -482,7 +484,7 @@ export default class Template { | |
| 482 484 | 
             
                                this.target = '';
         | 
| 483 485 | 
             
                                this.inLiteral = false;
         | 
| 484 486 | 
             
                                const condition = await this.parseExpression(data, '}', '-->');
         | 
| 485 | 
            -
                                this.blockStack.push({ blockStart, collection, data, iteration, iterations });
         | 
| 487 | 
            +
                                this.blockStack.push({ blockStart, collection, condition, data, iteration, iterations });
         | 
| 486 488 | 
             
                                let blockData = condition ? (this.target ? data : undefined) : this.target;
         | 
| 487 489 | 
             
                                blockStart = this.index;
         | 
| 488 490 | 
             
                                iteration = 0;
         | 
    
        package/package.json
    CHANGED