@halleyassist/rule-templater 0.0.1 → 0.0.3

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/index.d.ts CHANGED
@@ -1,91 +1,91 @@
1
- export interface VariableInfo {
2
- name: string;
3
- filters: string[];
4
- }
5
-
6
- export interface VariableValue {
7
- value: string | number | boolean;
8
- type?: 'string' | 'number' | 'boolean' | 'object' | 'time period' | 'time value' | 'string array' | 'number array' | 'boolean array' | 'object array';
9
- }
10
-
11
- export interface Variables {
12
- [key: string]: VariableValue;
13
- }
14
-
15
- export interface ValidationResult {
16
- valid: boolean;
17
- errors: string[];
18
- }
19
-
20
- export interface ASTNode {
21
- type: string;
22
- text?: string;
23
- children?: ASTNode[];
24
- [key: string]: any;
25
- }
26
-
27
- export type FilterFunction = (value: any) => any;
28
-
29
- export interface TemplateFiltersType {
30
- string: FilterFunction;
31
- upper: FilterFunction;
32
- lower: FilterFunction;
33
- capitalize: FilterFunction;
34
- title: FilterFunction;
35
- trim: FilterFunction;
36
- number: FilterFunction;
37
- boolean: FilterFunction;
38
- abs: FilterFunction;
39
- round: FilterFunction;
40
- floor: FilterFunction;
41
- ceil: FilterFunction;
42
- default: FilterFunction;
43
- [key: string]: FilterFunction;
44
- }
45
-
46
- export default class RuleTemplate {
47
- ruleTemplateText: string;
48
- ast: ASTNode;
49
-
50
- constructor(ruleTemplateText: string, ast: ASTNode);
51
-
52
- /**
53
- * Parse a rule template string and return a RuleTemplate instance
54
- * @param ruleTemplate The template string to parse
55
- * @returns Instance with AST and template text
56
- */
57
- static parse(ruleTemplate: string): RuleTemplate;
58
-
59
- /**
60
- * Extract variables from the template using the AST
61
- * @returns Array of {name, filters} objects
62
- */
63
- extractVariables(): VariableInfo[];
64
-
65
- /**
66
- * Validate variable types against the AST
67
- * @param variables Object mapping variable names to {value, type} objects
68
- * @returns Object with validation results: {valid, errors}
69
- */
70
- validate(variables: Variables): ValidationResult;
71
-
72
- /**
73
- * Prepare the template by replacing variables with their values
74
- * Applies any filters specified in the template (e.g., ${var|upper|trim})
75
- * @param variables Object mapping variable names to {value, type} objects
76
- * @returns The prepared rule string
77
- */
78
- prepare(variables: Variables): string;
79
-
80
- /**
81
- * Helper method to validate if an AST node matches a variable type
82
- * @param astNode The AST node to validate
83
- * @param variableType The expected variable type
84
- * @returns True if valid, false otherwise
85
- */
86
- static validateVariableNode(astNode: ASTNode | null | undefined, variableType: string): boolean;
87
- }
88
-
89
- export const ParserRules: any[];
90
- export const VariableTypes: string[];
91
- export const TemplateFilters: TemplateFiltersType;
1
+ export interface VariableInfo {
2
+ name: string;
3
+ filters: string[];
4
+ }
5
+
6
+ export interface VariableValue {
7
+ value: string | number | boolean;
8
+ type?: 'string' | 'number' | 'boolean' | 'object' | 'time period' | 'time value' | 'string array' | 'number array' | 'boolean array' | 'object array';
9
+ }
10
+
11
+ export interface Variables {
12
+ [key: string]: VariableValue;
13
+ }
14
+
15
+ export interface ValidationResult {
16
+ valid: boolean;
17
+ errors: string[];
18
+ }
19
+
20
+ export interface ASTNode {
21
+ type: string;
22
+ text?: string;
23
+ children?: ASTNode[];
24
+ [key: string]: any;
25
+ }
26
+
27
+ export type FilterFunction = (value: any) => any;
28
+
29
+ export interface TemplateFiltersType {
30
+ string: FilterFunction;
31
+ upper: FilterFunction;
32
+ lower: FilterFunction;
33
+ capitalize: FilterFunction;
34
+ title: FilterFunction;
35
+ trim: FilterFunction;
36
+ number: FilterFunction;
37
+ boolean: FilterFunction;
38
+ abs: FilterFunction;
39
+ round: FilterFunction;
40
+ floor: FilterFunction;
41
+ ceil: FilterFunction;
42
+ default: FilterFunction;
43
+ [key: string]: FilterFunction;
44
+ }
45
+
46
+ export default class RuleTemplate {
47
+ ruleTemplateText: string;
48
+ ast: ASTNode;
49
+
50
+ constructor(ruleTemplateText: string, ast: ASTNode);
51
+
52
+ /**
53
+ * Parse a rule template string and return a RuleTemplate instance
54
+ * @param ruleTemplate The template string to parse
55
+ * @returns Instance with AST and template text
56
+ */
57
+ static parse(ruleTemplate: string): RuleTemplate;
58
+
59
+ /**
60
+ * Extract variables from the template using the AST
61
+ * @returns Array of {name, filters} objects
62
+ */
63
+ extractVariables(): VariableInfo[];
64
+
65
+ /**
66
+ * Validate variable types against the AST
67
+ * @param variables Object mapping variable names to {value, type} objects
68
+ * @returns Object with validation results: {valid, errors}
69
+ */
70
+ validate(variables: Variables): ValidationResult;
71
+
72
+ /**
73
+ * Prepare the template by replacing variables with their values
74
+ * Applies any filters specified in the template (e.g., ${var|upper|trim})
75
+ * @param variables Object mapping variable names to {value, type} objects
76
+ * @returns The prepared rule string
77
+ */
78
+ prepare(variables: Variables): string;
79
+
80
+ /**
81
+ * Helper method to validate if an AST node matches a variable type
82
+ * @param astNode The AST node to validate
83
+ * @param variableType The expected variable type
84
+ * @returns True if valid, false otherwise
85
+ */
86
+ static validateVariableNode(astNode: ASTNode | null | undefined, variableType: string): boolean;
87
+ }
88
+
89
+ export const ParserRules: any[];
90
+ export const VariableTypes: string[];
91
+ export const TemplateFilters: TemplateFiltersType;
package/index.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,47 +1,47 @@
1
- {
2
- "name": "@halleyassist/rule-templater",
3
- "version": "0.0.1",
4
- "description": "The grammar for HalleyAssist rules",
5
- "main": "index.js",
6
- "browser": "./dist/rule-templater.browser.js",
7
- "types": "index.d.ts",
8
- "scripts": {
9
- "test": "mocha",
10
- "build": "gulp build"
11
- },
12
- "repository": {
13
- "type": "git",
14
- "url": "git+https://github.com/HalleyAssist/rule-templater.git"
15
- },
16
- "author": "",
17
- "license": "ISC",
18
- "bugs": {
19
- "url": "https://github.com/HalleyAssist/rule-templater/issues"
20
- },
21
- "homepage": "https://github.com/HalleyAssist/rule-templater#readme",
22
- "dependencies": {
23
- "@halleyassist/rule-parser": "^1.0.19",
24
- "ebnf": "git+https://github.com/HalleyAssist/node-ebnf.git"
25
- },
26
- "devDependencies": {
27
- "@types/node": "^25.1.0",
28
- "browserify": "^17.0.1",
29
- "chai": "^4",
30
- "gulp": "^5.0.1",
31
- "mocha": "^10.8.2",
32
- "typescript": "^5.9.3",
33
- "unassertify": "^3.0.1",
34
- "vinyl-buffer": "^1.0.1",
35
- "vinyl-source-stream": "^2.0.0"
36
- },
37
- "publishConfig": {
38
- "access": "public",
39
- "registry": "https://registry.npmjs.org/"
40
- },
41
- "files": [
42
- "src/*",
43
- "index.js",
44
- "index.d.ts",
45
- "dist/*"
46
- ]
47
- }
1
+ {
2
+ "name": "@halleyassist/rule-templater",
3
+ "version": "0.0.3",
4
+ "description": "The grammar for HalleyAssist rules",
5
+ "main": "src/RuleTemplater.production.js",
6
+ "browser": "./dist/rule-templater.browser.js",
7
+ "types": "index.d.ts",
8
+ "scripts": {
9
+ "test": "mocha",
10
+ "build": "gulp build"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/HalleyAssist/rule-templater.git"
15
+ },
16
+ "author": "",
17
+ "license": "ISC",
18
+ "bugs": {
19
+ "url": "https://github.com/HalleyAssist/rule-templater/issues"
20
+ },
21
+ "homepage": "https://github.com/HalleyAssist/rule-templater#readme",
22
+ "dependencies": {
23
+ "@halleyassist/rule-parser": "^1.0.19",
24
+ "ebnf": "git+https://github.com/HalleyAssist/node-ebnf.git"
25
+ },
26
+ "devDependencies": {
27
+ "@types/node": "^25.1.0",
28
+ "browserify": "^17.0.1",
29
+ "chai": "^4",
30
+ "gulp": "^5.0.1",
31
+ "mocha": "^10.8.2",
32
+ "typescript": "^5.9.3",
33
+ "unassertify": "^3.0.1",
34
+ "vinyl-buffer": "^1.0.1",
35
+ "vinyl-source-stream": "^2.0.0"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public",
39
+ "registry": "https://registry.npmjs.org/"
40
+ },
41
+ "files": [
42
+ "src/*",
43
+ "index.js",
44
+ "index.d.ts",
45
+ "dist/*"
46
+ ]
47
+ }
@@ -1,27 +1,32 @@
1
- const {Grammars} = require('ebnf');
2
-
3
- const grammar = `
4
- TEMPLATE_BEGIN ::= "\${"
5
- TEMPLATE_END ::= "}"
6
- PIPE ::= "|"
7
- IDENT ::= [A-Za-z_][A-Za-z0-9_]*
8
- DOT ::= "."
9
-
10
- template_value ::= TEMPLATE_BEGIN WS* template_expr WS* TEMPLATE_END
11
-
12
- template_expr ::= template_path (WS* template_pipe WS* template_filter_call)*
13
-
14
- template_pipe ::= PIPE
15
-
16
- template_path ::= IDENT (WS* DOT WS* IDENT)*
17
-
18
- template_filter_call ::= template_filter_name (WS* BEGIN_ARGUMENT WS* template_filter_args? WS* END_ARGUMENT)?
19
-
20
- template_filter_name ::= IDENT
21
-
22
- template_filter_args ::= template_filter_arg (WS* "," WS* template_filter_arg)*
23
-
24
- template_filter_arg ::= value | template_value
25
- `
26
-
27
- module.exports = Grammars.W3C.getRules(grammar);
1
+ const {Grammars} = require('ebnf');
2
+
3
+ const grammar = `
4
+ TEMPLATE_BEGIN ::= "\${"
5
+ TEMPLATE_END ::= "}"
6
+ PIPE ::= "|"
7
+ IDENT ::= [A-Za-z_][A-Za-z0-9_]*
8
+ DOT ::= "."
9
+
10
+ template_value ::= TEMPLATE_BEGIN WS* template_expr WS* TEMPLATE_END
11
+
12
+ template_expr ::= template_path (WS* template_pipe WS* template_filter_call)*
13
+
14
+ template_pipe ::= PIPE
15
+
16
+ template_path ::= IDENT (WS* DOT WS* IDENT)*
17
+
18
+ template_filter_call ::= template_filter_name (WS* BEGIN_ARGUMENT WS* template_filter_args? WS* END_ARGUMENT)?
19
+
20
+ template_filter_name ::= IDENT
21
+
22
+ template_filter_args ::= template_filter_arg (WS* "," WS* template_filter_arg)*
23
+
24
+ template_filter_arg ::= value | template_value
25
+
26
+ number_atom ::= number | template_value
27
+ number_time_atom ::= number_time | template_value
28
+ tod_atom ::= number_tod | template_value
29
+ dow_atom ::= dow | template_value
30
+ `
31
+
32
+ module.exports = Grammars.W3C.getRules(grammar);
@@ -0,0 +1 @@
1
+ module.exports=[{"name":"TEMPLATE_BEGIN","bnf":[["\"${\""]]},{"name":"TEMPLATE_END","bnf":[["\"}\""]]},{"name":"PIPE","bnf":[["\"|\""]]},{"name":"%IDENT[2]","bnf":[[/[A-Za-z0-9_]/]]},{"name":"IDENT","bnf":[[/[A-Za-z_]/,"%IDENT[2]*"]]},{"name":"DOT","bnf":[["\".\""]]},{"name":"template_value","bnf":[["TEMPLATE_BEGIN","WS*","template_expr","WS*","TEMPLATE_END"]]},{"name":"%template_expr[2]","bnf":[["WS*","template_pipe","WS*","template_filter_call"]],"fragment":true},{"name":"template_expr","bnf":[["template_path","%template_expr[2]*"]]},{"name":"template_pipe","bnf":[["PIPE"]]},{"name":"%template_path[2]","bnf":[["WS*","DOT","WS*","IDENT"]],"fragment":true},{"name":"template_path","bnf":[["IDENT","%template_path[2]*"]]},{"name":"%template_filter_call[2]","bnf":[["WS*","BEGIN_ARGUMENT","WS*","template_filter_args?","WS*","END_ARGUMENT"]],"fragment":true},{"name":"template_filter_call","bnf":[["template_filter_name","%template_filter_call[2]?"]]},{"name":"template_filter_name","bnf":[["IDENT"]]},{"name":"%template_filter_args[2]","bnf":[["WS*","\",\"","WS*","template_filter_arg"]],"fragment":true},{"name":"template_filter_args","bnf":[["template_filter_arg","%template_filter_args[2]*"]]},{"name":"template_filter_arg","bnf":[["value"],["template_value"]]},{"name":"number_atom","bnf":[["number"],["template_value"]]},{"name":"number_time_atom","bnf":[["number_time"],["template_value"]]},{"name":"tod_atom","bnf":[["number_tod"],["template_value"]]},{"name":"dow_atom","bnf":[["dow"],["template_value"]]}]
File without changes