@itrocks/template 0.0.31 → 0.0.33

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 CHANGED
@@ -7,11 +7,14 @@ type BlockStackEntry = {
7
7
  iteration: number;
8
8
  iterations: number;
9
9
  };
10
+ type Close = ')' | '}';
11
+ type Final = '' | '-->';
12
+ type Open = '(' | '{';
10
13
  export type VariableParser = [parser: string, (variable: string, data: any) => any];
11
14
  export declare const frontScripts: SortedArray<string>;
12
15
  export declare class Template {
13
- data?: any;
14
- containerData?: any;
16
+ data?: any | undefined;
17
+ containerData?: any | undefined;
15
18
  blockBack: number;
16
19
  blockStack: BlockStackEntry[];
17
20
  doExpression: boolean;
@@ -49,7 +52,7 @@ export declare class Template {
49
52
  onTagClose?: (name: string) => void;
50
53
  parsers: VariableParser[];
51
54
  prefixes: string;
52
- constructor(data?: any, containerData?: any);
55
+ constructor(data?: any | undefined, containerData?: any | undefined);
53
56
  applyLiterals(text: string, parts?: string[]): string;
54
57
  closeTag(shouldInLiteral: boolean, targetIndex: number): boolean;
55
58
  combineLiterals(text: string, parts?: string[]): string;
@@ -93,7 +96,7 @@ export declare class Template {
93
96
  isContextClean(): boolean;
94
97
  literalTarget(index: number, isTitle?: boolean): void;
95
98
  parseBuffer(buffer: string): Promise<string>;
96
- parseExpression(data: any, close: string, finalClose?: string): Promise<boolean | undefined>;
99
+ parseExpression(data: any, open: Open | '<', close: Close, finalClose?: Final): Promise<boolean | undefined>;
97
100
  parseFile(fileName: string, containerFileName?: string): Promise<string>;
98
101
  parsePath(expression: string, data: any): Promise<any>;
99
102
  parseVariable(variable: string, data: any): Promise<any>;
@@ -101,7 +104,7 @@ export declare class Template {
101
104
  setSource(source: string, index?: number, start?: number, target?: string): void;
102
105
  skipBlock(): void;
103
106
  sourceToTarget(): void;
104
- startsExpression(char: string, open?: string, close?: string): boolean;
107
+ startsExpression(char: string, open?: Open, close?: Close): boolean;
105
108
  trimEndLine(string: string): string;
106
109
  }
107
110
  export {};
package/cjs/template.js CHANGED
@@ -164,15 +164,14 @@ class Template {
164
164
  template.onTagOpen = this.onTagOpen;
165
165
  template.onTagOpened = this.onTagOpened;
166
166
  template.parsers = this.parsers;
167
- template.prefixes = this.prefixes;
168
167
  const parsed = await template.parseFile(((path[0] === node_path_1.sep) || (path[1] === ':'))
169
168
  ? path
170
169
  : (this.filePath + node_path_1.sep + path));
171
170
  if (!this.doHeadLinks) {
172
171
  this.addLinks.push(...template.headLinks);
172
+ this.headTitle = template.headTitle;
173
173
  }
174
174
  this.headLinks.push(...template.headLinks);
175
- this.headTitle = template.headTitle;
176
175
  const beginPosition = parsed.indexOf('<!--BEGIN-->');
177
176
  const endPosition = parsed.indexOf('<!--END-->');
178
177
  return (beginPosition > -1)
@@ -233,9 +232,8 @@ class Template {
233
232
  }
234
233
  return this.target;
235
234
  }
236
- async parseExpression(data, close, finalClose = '') {
235
+ async parseExpression(data, open, close, finalClose = '') {
237
236
  const indexOut = this.index;
238
- let open = this.source[this.index];
239
237
  if (this.inLiteral && !this.literalParts.length) {
240
238
  this.targetStack.push(this.target);
241
239
  this.target = '';
@@ -428,7 +426,7 @@ class Template {
428
426
  let char = this.source[this.index];
429
427
  // expression
430
428
  if ((char === '{') && this.doExpression) {
431
- await this.parseExpression(data, '}');
429
+ await this.parseExpression(data, char, '}');
432
430
  continue;
433
431
  }
434
432
  // tag ?
@@ -495,7 +493,7 @@ class Template {
495
493
  this.index = tagIndex;
496
494
  this.target = '';
497
495
  this.inLiteral = false;
498
- const condition = await this.parseExpression(data, '}', '-->');
496
+ const condition = await this.parseExpression(data, '<', '}', '-->');
499
497
  this.blockStack.push({ blockStart, collection, condition, data, iteration, iterations });
500
498
  let blockData = condition ? (this.target ? data : undefined) : this.target;
501
499
  blockStart = this.index;
@@ -691,7 +689,7 @@ class Template {
691
689
  }
692
690
  // expression in attribute value
693
691
  if ((char === open) && this.doExpression) {
694
- await this.parseExpression(data, close);
692
+ await this.parseExpression(data, open, close);
695
693
  continue;
696
694
  }
697
695
  this.index++;
package/esm/template.d.ts CHANGED
@@ -7,11 +7,14 @@ type BlockStackEntry = {
7
7
  iteration: number;
8
8
  iterations: number;
9
9
  };
10
+ type Close = ')' | '}';
11
+ type Final = '' | '-->';
12
+ type Open = '(' | '{';
10
13
  export type VariableParser = [parser: string, (variable: string, data: any) => any];
11
14
  export declare const frontScripts: SortedArray<string>;
12
15
  export declare class Template {
13
- data?: any;
14
- containerData?: any;
16
+ data?: any | undefined;
17
+ containerData?: any | undefined;
15
18
  blockBack: number;
16
19
  blockStack: BlockStackEntry[];
17
20
  doExpression: boolean;
@@ -49,7 +52,7 @@ export declare class Template {
49
52
  onTagClose?: (name: string) => void;
50
53
  parsers: VariableParser[];
51
54
  prefixes: string;
52
- constructor(data?: any, containerData?: any);
55
+ constructor(data?: any | undefined, containerData?: any | undefined);
53
56
  applyLiterals(text: string, parts?: string[]): string;
54
57
  closeTag(shouldInLiteral: boolean, targetIndex: number): boolean;
55
58
  combineLiterals(text: string, parts?: string[]): string;
@@ -93,7 +96,7 @@ export declare class Template {
93
96
  isContextClean(): boolean;
94
97
  literalTarget(index: number, isTitle?: boolean): void;
95
98
  parseBuffer(buffer: string): Promise<string>;
96
- parseExpression(data: any, close: string, finalClose?: string): Promise<boolean | undefined>;
99
+ parseExpression(data: any, open: Open | '<', close: Close, finalClose?: Final): Promise<boolean | undefined>;
97
100
  parseFile(fileName: string, containerFileName?: string): Promise<string>;
98
101
  parsePath(expression: string, data: any): Promise<any>;
99
102
  parseVariable(variable: string, data: any): Promise<any>;
@@ -101,7 +104,7 @@ export declare class Template {
101
104
  setSource(source: string, index?: number, start?: number, target?: string): void;
102
105
  skipBlock(): void;
103
106
  sourceToTarget(): void;
104
- startsExpression(char: string, open?: string, close?: string): boolean;
107
+ startsExpression(char: string, open?: Open, close?: Close): boolean;
105
108
  trimEndLine(string: string): string;
106
109
  }
107
110
  export {};
package/esm/template.js CHANGED
@@ -161,15 +161,14 @@ export class Template {
161
161
  template.onTagOpen = this.onTagOpen;
162
162
  template.onTagOpened = this.onTagOpened;
163
163
  template.parsers = this.parsers;
164
- template.prefixes = this.prefixes;
165
164
  const parsed = await template.parseFile(((path[0] === sep) || (path[1] === ':'))
166
165
  ? path
167
166
  : (this.filePath + sep + path));
168
167
  if (!this.doHeadLinks) {
169
168
  this.addLinks.push(...template.headLinks);
169
+ this.headTitle = template.headTitle;
170
170
  }
171
171
  this.headLinks.push(...template.headLinks);
172
- this.headTitle = template.headTitle;
173
172
  const beginPosition = parsed.indexOf('<!--BEGIN-->');
174
173
  const endPosition = parsed.indexOf('<!--END-->');
175
174
  return (beginPosition > -1)
@@ -230,9 +229,8 @@ export class Template {
230
229
  }
231
230
  return this.target;
232
231
  }
233
- async parseExpression(data, close, finalClose = '') {
232
+ async parseExpression(data, open, close, finalClose = '') {
234
233
  const indexOut = this.index;
235
- let open = this.source[this.index];
236
234
  if (this.inLiteral && !this.literalParts.length) {
237
235
  this.targetStack.push(this.target);
238
236
  this.target = '';
@@ -425,7 +423,7 @@ export class Template {
425
423
  let char = this.source[this.index];
426
424
  // expression
427
425
  if ((char === '{') && this.doExpression) {
428
- await this.parseExpression(data, '}');
426
+ await this.parseExpression(data, char, '}');
429
427
  continue;
430
428
  }
431
429
  // tag ?
@@ -492,7 +490,7 @@ export class Template {
492
490
  this.index = tagIndex;
493
491
  this.target = '';
494
492
  this.inLiteral = false;
495
- const condition = await this.parseExpression(data, '}', '-->');
493
+ const condition = await this.parseExpression(data, '<', '}', '-->');
496
494
  this.blockStack.push({ blockStart, collection, condition, data, iteration, iterations });
497
495
  let blockData = condition ? (this.target ? data : undefined) : this.target;
498
496
  blockStart = this.index;
@@ -688,7 +686,7 @@ export class Template {
688
686
  }
689
687
  // expression in attribute value
690
688
  if ((char === open) && this.doExpression) {
691
- await this.parseExpression(data, close);
689
+ await this.parseExpression(data, open, close);
692
690
  continue;
693
691
  }
694
692
  this.index++;
package/package.json CHANGED
@@ -69,5 +69,5 @@
69
69
  "test": "jest"
70
70
  },
71
71
  "types": "./esm/template.d.ts",
72
- "version": "0.0.31"
72
+ "version": "0.0.33"
73
73
  }