@trustme24/flext 1.10.4 → 1.10.6

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.
@@ -2,5 +2,6 @@ import { SafeString } from 'handlebars';
2
2
  export declare const DEFAULT_COLOR = "text-blue-500";
3
3
  export declare function put(state: any): string;
4
4
  export declare function putWithColor(state: any): SafeString;
5
+ export declare function defaultGetContent(): null;
5
6
  declare const _default: any;
6
7
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trustme24/flext",
3
- "version": "1.10.4",
3
+ "version": "1.10.6",
4
4
  "description": "A technology for building reliable document templates",
5
5
  "keywords": ["templates", "templating engine", "documents", "document engine", "handlebars"],
6
6
  "repository": "https://github.com/TrustMe-kz/flext.git",
package/src/lib/index.ts CHANGED
@@ -628,8 +628,8 @@ export function ensureDate<T extends boolean = true>(val: Date | string | number
628
628
  const dbDate = <R extends boolean = true>(_val: string, _doWarn: R = true as R): R extends true ? Date : Date | null => {
629
629
  const [ year, month, day ] = _val?.split('-')?.map(Number) ?? [];
630
630
 
631
- if (year && month && day)
632
- return DateTime.fromtypes.Object({ year, month, day }).toJSDate();
631
+ if (isset(year) && isset(month) && isset(day))
632
+ return DateTime.fromObject({ year, month, day }).toJSDate();
633
633
  else if (_doWarn)
634
634
  throw new BaseError('Flext: Unable to get date: The date is invalid: ' + audit(_val));
635
635
  else
@@ -24,7 +24,7 @@ export function op(state: any): DateTime | string | number | null {
24
24
  let newDate: DateTime = DateTime.local();
25
25
 
26
26
  if (date !== 'now')
27
- newDate = DateTime.fromJSDate(ensureDate(date));
27
+ newDate = DateTime.fromJSDate(ensureDate(date, true));
28
28
 
29
29
  if (timeZone || flext?.timeZone)
30
30
  newDate = newDate.setZone(timeZone ?? flext?.timeZone);
@@ -12,14 +12,29 @@ export const DEFAULT_COLOR = 'text-blue-500';
12
12
  // Functions
13
13
 
14
14
  export function put(state: any): string {
15
+ const flext = state?.flext ?? {};
15
16
  const args = state?.args ?? [];
16
17
  const [ val, fallback ] = args;
18
+ const options = state?.options ?? {};
19
+ const namedArgs = state?.namedArgs ?? {};
20
+ const self = state?.self ?? {};
21
+ const getContent = state?.getContent ?? defaultGetContent;
17
22
  const date = ensureDate(val, false);
18
23
 
19
- if (date && !isNumber(val) && !inarr(val, true, false))
20
- return format(date);
21
- else
22
- return val ?? fallback ?? '';
24
+
25
+ // If the value is a valid date
26
+
27
+ if (date && !isNumber(val) && !inarr(val, true, false)) return format({
28
+ flext: flext,
29
+ args: [ date ],
30
+ options: options,
31
+ namedArgs: { ...namedArgs, fallback },
32
+ self: self,
33
+ getContent: getContent,
34
+ });
35
+
36
+
37
+ return val ?? fallback ?? '';
23
38
  }
24
39
 
25
40
  export function putWithColor(state: any): SafeString {
@@ -32,6 +47,11 @@ export function putWithColor(state: any): SafeString {
32
47
  return new SafeString(state);
33
48
  }
34
49
 
50
+ export function defaultGetContent(): null {
51
+ // The default 'getContent' function does nothing...
52
+ return null;
53
+ }
54
+
35
55
 
36
56
  export default defineModule({
37
57
  helpers: {