@halleyassist/rule-templater 0.0.17 → 0.0.19

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/README.md CHANGED
@@ -121,6 +121,8 @@ const prepared = parsed.prepare({
121
121
  - **round**: Round number to nearest integer
122
122
  - **floor**: Round number down
123
123
  - **ceil**: Round number up
124
+ - **humanise_list**: Join array values into natural language, optionally with a custom joiner like `humanise_list("or")`
125
+ - **humanise_time**: Convert seconds into a single human-readable unit like `1 hour`; optionally round down to a minimum unit such as `humanise_time("minute")` or `humanise_time("min")`
124
126
  - **time_start**: Extract `from` from `time period` / `time period ago` and convert to `time value`
125
127
  - **time_end**: Extract `to` from `time period` / `time period ago` and convert to `time value`
126
128
 
@@ -140,6 +142,14 @@ const prepared = parsed.prepare({
140
142
  // Chaining filters
141
143
  '${text|trim|upper}' with text=' hello ' → HELLO
142
144
 
145
+ // Humanise arrays
146
+ '${names|humanise_list}' with names=['a','b','c'] → a, b and c
147
+ '${names|humanise_list("or")}' with names=['a','b','c'] → a, b or c
148
+
149
+ // Humanise time from seconds
150
+ '${duration|humanise_time}' with duration=3600 → 1 hour
151
+ '${duration|humanise_time("minute")}' with duration=71 → 1 minute
152
+
143
153
  // Time period conversion
144
154
  '${window|time_start}' with window={from:'08:00',to:'12:00'} → 08:00
145
155
  ```
@@ -232,7 +242,7 @@ This is useful for comparing against a hub's list of available functions to ensu
232
242
 
233
243
  ### `ruleTemplate.validate(variables)`
234
244
 
235
- Validates that all required variables are provided and have valid types.
245
+ Validates that all required variables are provided, have valid types, and reference only known template filters.
236
246
 
237
247
  **Parameters:**
238
248
  - `variables` (object): Object mapping variable names to their values and types
@@ -243,6 +253,7 @@ Validates that all required variables are provided and have valid types.
243
253
  **Returns:** Object with:
244
254
  - `valid` (boolean): Whether validation passed
245
255
  - `errors` (array): Array of error messages (empty if valid)
256
+ - `warnings` (array): Array of non-fatal warnings (empty if none)
246
257
 
247
258
  ### `ruleTemplate.prepare(variables)`
248
259
 
@@ -272,6 +283,10 @@ Extracts variables from a general string template.
272
283
 
273
284
  Prepares a general string template by replacing `${...}` placeholders with values and applying filters.
274
285
 
286
+ ### `generalTemplate.validate()`
287
+
288
+ Validates the template itself and reports any unknown filters used in `${...}` chains.
289
+
275
290
  ### `RuleTemplate.validateVariableNode(astNode, variableType)` (Static)
276
291
 
277
292
  Helper method to validate that an AST node matches the expected variable type.