@trustme24/flext 1.8.0 → 1.9.1

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/dist/lib.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import { AST } from '@handlebars/parser';
2
2
  import { Theme as Wind4Theme } from '@unocss/preset-wind4';
3
- import { Obj, Macro, MacroParam, DataModelNode, DataModel, Isset, Inarr } from './types';
3
+ import { Obj, Isset, IsNumber, IsObject, Has, Inarr, Macro, MacroParam, DataModel, DataModelNode, CollectorFilterHandler } from './types';
4
+ import { TemplateDataValidationError } from './errors';
4
5
  import striptags from 'striptags';
5
6
  import Handlebars, { TemplateDelegate } from 'handlebars';
7
+ import * as types from "./types";
6
8
  export declare const uno: Promise<import("unocss").UnoGenerator<Wind4Theme>>;
7
- export type CollectorFilterHandler<T = any> = (val?: T) => boolean;
8
9
  export declare const DEFAULT_MODEL_DEPTH = 10;
9
10
  export declare const stripHtml: typeof striptags;
10
11
  export declare class HandlebarsCollector<T = any> extends Handlebars.Visitor {
@@ -16,32 +17,44 @@ export declare class HandlebarsCollector<T = any> extends Handlebars.Visitor {
16
17
  setAst(ast: AST.Program): this;
17
18
  collect(ast: AST.Program): T[];
18
19
  }
19
- export declare function isNumber(val: any): boolean;
20
- export declare function isObject(val: any): boolean;
21
- export declare function has(obj: Obj, key: string): boolean;
22
20
  export declare function inarr<T extends any, A extends any[]>(val: T, ...arr: A): Inarr<T, A>;
21
+ export declare function has<T extends Obj, K extends keyof T>(obj: T, key: K): Has<T, K>;
23
22
  export declare function isset<T extends any>(val: T): Isset<T>;
23
+ export declare function isNumber<T extends any>(val: T): IsNumber<T>;
24
+ export declare function isObject<T extends any>(val: T): IsObject<T>;
24
25
  export declare function audit(val: any): string;
25
- export declare function defineModule(options?: any): any;
26
- export declare function unique<T = any>(arr: T[]): T[];
27
26
  export declare function getAst(val: string): AST.Program;
28
27
  export declare function getTemplate(val: string | AST.Program): TemplateDelegate;
29
28
  export declare function getHtml(template: TemplateDelegate, data?: Obj, helpers?: Obj): string;
30
29
  export declare function getCss(template: TemplateDelegate, data?: Obj, options?: Obj): Promise<string>;
30
+ export declare function unique<T = any>(arr: T[]): T[];
31
31
  export declare function getPaths(ast: AST.Program): string[];
32
32
  export declare function pathToDataModelNode(path: string, depth?: number): DataModelNode;
33
33
  export declare function pathToDataModel(path: string, depth?: number): DataModel;
34
34
  export declare function getDataModel(ast: AST.Program): DataModel;
35
+ export declare function dataModelNodeToMetadata(node: types.DataModelNode, fields: types.Field[], _options?: types.Obj, depth?: number): types.MetadataModelNode;
35
36
  export declare function getMacroParam(val: string): MacroParam | null;
36
37
  export declare function getMacroParams(val: string, doWarn?: boolean): MacroParam[];
37
38
  export declare function getMacros(ast: AST.Program, doWarn?: boolean): Macro[];
38
39
  export declare function getHtmlH1(ast: AST.Program, doWarn?: boolean): string[];
40
+ export declare function getTemplateValidationErrorsByMetadata(data: types.Obj, model: types.MetadataModelNode[], depth?: number): TemplateDataValidationError[];
39
41
  export declare function ensureString(val: any): string;
42
+ export declare function ensureNullableString(val: any): string | null;
40
43
  export declare function ensureDate(val: Date | string | number): Date;
41
44
  export declare function ensureTitle(val: string | number): string;
42
45
  export declare function ensureFieldName(val: string): string;
46
+ export declare function ensureNullableFieldMinMax(val: any): Date | number | null;
47
+ export declare function ensureNullableFieldMinMaxLength(val: any): number | null;
48
+ export declare function ensureNullableFieldOrder(val: any): number | null;
49
+ export declare function ensureFieldValue(val: any): types.FieldValue;
43
50
  export declare function filter(regex: RegExp, val: string | number): boolean;
44
51
  export declare function compare(a: number | null | undefined, b: number | null | undefined): number;
52
+ export declare function macroToModuleNames(val: types.Macro): string[];
53
+ export declare function macroToField(val: types.Macro): types.Field;
54
+ export declare function macroToFieldValueOption(val: types.Macro): types.FieldValueOption;
55
+ export declare function applyValueOptionsToFields(options: types.FieldValueOption[], fields: types.Field[]): void;
56
+ export declare function applyAbsoluteOrderToFields(fields: types.Field[]): void;
57
+ export declare function defineModule(options?: any): any;
45
58
  export declare class RegexHelper {
46
59
  static dbDateStr: RegExp;
47
60
  static macro: RegExp;
@@ -1,5 +1,6 @@
1
1
  import { DateTime } from 'luxon';
2
2
  import { SafeString } from 'handlebars';
3
+ export declare const DEFAULT_COLOR_OP = "text";
3
4
  export declare function op(state: any): DateTime | string | number | null;
4
5
  export declare function opWithColor(state: any): SafeString;
5
6
  export declare function now(state: any): DateTime;
@@ -1,5 +1,5 @@
1
- export declare function matchHelper(state: any): any;
2
- export declare function caseHelper(state: any): any;
3
- export declare function fallbackHelper(state: any): any;
1
+ export declare function _match(state: any): any;
2
+ export declare function _case(state: any): any;
3
+ export declare function _fallback(state: any): any;
4
4
  declare const _default: any;
5
5
  export default _default;
package/dist/types.d.ts CHANGED
@@ -1,13 +1,12 @@
1
+ import { AST } from '@handlebars/parser';
1
2
  export type Obj<T extends any = any> = Record<string, T>;
2
- export type Inarr<T extends any, A extends any[]> = T extends A[any] ? true : false;
3
3
  export type Isset<T extends any> = T extends null | undefined ? false : true;
4
- export type DataModelNode = {
5
- name: string;
6
- $?: DataModelNode[];
7
- };
8
- export type DataModel = DataModelNode & {
9
- addPath: (path: string, depth?: number) => void;
10
- };
4
+ export type IsNumber<T extends any> = T extends number ? true : false;
5
+ export type IsObject<T extends any, O extends Obj = Obj> = T extends O ? true : false;
6
+ export type Has<T extends Obj, K extends keyof T> = T[K];
7
+ export type Inarr<T extends any, A extends any[]> = T extends A[any] ? true : false;
8
+ export type FieldType = 'string' | 'number' | 'boolean' | 'object' | 'array' | 'date' | 'mixed';
9
+ export type FieldValue = string | number | boolean | Obj | FieldValue[] | null;
11
10
  export type MacroParam = {
12
11
  name: string;
13
12
  value: string | null;
@@ -16,3 +15,60 @@ export type Macro = {
16
15
  name: string;
17
16
  params: MacroParam[];
18
17
  };
18
+ export type FieldValueOption = {
19
+ type: string;
20
+ name: string;
21
+ fieldName: string;
22
+ label?: string | null;
23
+ descr?: string | null;
24
+ value?: FieldValue | null;
25
+ isDisabled: boolean;
26
+ };
27
+ export type Field = {
28
+ type: FieldType;
29
+ name: string;
30
+ label?: string | null;
31
+ descr?: string | null;
32
+ hint?: string | null;
33
+ min?: Date | number | null;
34
+ max?: Date | number | null;
35
+ minLength?: number | null;
36
+ maxLength?: number | null;
37
+ order?: number | null;
38
+ options?: FieldValueOption[] | null;
39
+ value?: FieldValue;
40
+ isRequired: boolean;
41
+ extra?: {
42
+ macroName?: string | null;
43
+ absoluteOrder?: number | null;
44
+ };
45
+ };
46
+ export type DataModelNode = {
47
+ name: string;
48
+ $?: DataModelNode[];
49
+ };
50
+ export type DataModel = DataModelNode & {
51
+ addPath: (path: string, depth?: number) => void;
52
+ };
53
+ export type MetadataModelNode = DataModelNode & {
54
+ type: FieldType;
55
+ label?: string | null;
56
+ descr?: string | null;
57
+ hint?: string | null;
58
+ min?: Date | number | null;
59
+ max?: Date | number | null;
60
+ minLength?: number | null;
61
+ maxLength?: number | null;
62
+ order?: number | null;
63
+ options?: FieldValueOption[] | null;
64
+ value?: string | null;
65
+ isRequired: boolean;
66
+ extra?: {
67
+ fieldName?: string | null;
68
+ };
69
+ };
70
+ export type CollectorFilterHandler<T = any> = (val?: T) => boolean;
71
+ export type GetProcessedTemplateHandler = (val: string) => string;
72
+ export type GetTemplateAstHandler = (val: string) => AST.Program;
73
+ export type GetTemplateTitleHandler = (ast: AST.Program) => string[];
74
+ export type GetTemplateMacroHandler = (ast: AST.Program) => Macro[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trustme24/flext",
3
- "version": "1.8.0",
3
+ "version": "1.9.1",
4
4
  "description": "A Powerful Templating Engine",
5
5
  "keywords": ["templates", "templating engine", "modular templates", "handlebars"],
6
6
  "type": "module",
@@ -35,22 +35,22 @@
35
35
  "@babel/core": "^7.28.5",
36
36
  "@babel/preset-env": "^7.28.5",
37
37
  "@babel/preset-typescript": "^7.28.5",
38
- "@handlebars/parser": "^2.2.1",
39
- "@tailwindcss/cli": "^4.1.17",
40
- "@types/node": "^24.10.1",
41
- "esbuild": "^0.27.0",
38
+ "@handlebars/parser": "^2.2.2",
39
+ "@tailwindcss/cli": "^4.1.18",
40
+ "@types/node": "^25.0.3",
41
+ "esbuild": "^0.27.2",
42
42
  "esbuild-plugin-import-glob": "^0.1.1",
43
- "tailwindcss": "^4.1.17",
43
+ "tailwindcss": "^4.1.18",
44
44
  "tsc-alias": "^1.8.16",
45
45
  "typescript": "^5.9.3",
46
- "vitest": "^4.0.14"
46
+ "vitest": "^4.0.16"
47
47
  },
48
48
  "dependencies": {
49
- "@unocss/preset-wind4": "^66.5.9",
49
+ "@unocss/preset-wind4": "^66.5.10",
50
50
  "handlebars": "^4.7.8",
51
51
  "luxon": "^3.7.2",
52
52
  "striptags": "^3.2.0",
53
- "unocss": "^66.5.9",
53
+ "unocss": "^66.5.10",
54
54
  "written-number": "^0.11.1"
55
55
  }
56
56
  }