@ramathibodi/nuxt-commons 0.1.21 → 0.1.23

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.
Files changed (46) hide show
  1. package/dist/module.d.mts +1 -1
  2. package/dist/module.d.ts +1 -1
  3. package/dist/module.json +5 -1
  4. package/dist/runtime/components/ExportCSV.vue +22 -13
  5. package/dist/runtime/components/FileBtn.vue +4 -2
  6. package/dist/runtime/components/ImportCSV.vue +24 -14
  7. package/dist/runtime/components/document/TemplateBuilder.vue +1 -1
  8. package/dist/runtime/components/form/SignPad.vue +30 -30
  9. package/dist/runtime/components/form/Table.vue +3 -20
  10. package/dist/runtime/components/form/images/Field.vue +187 -0
  11. package/dist/runtime/components/form/images/Pad.vue +43 -0
  12. package/dist/runtime/components/model/Table.vue +20 -12
  13. package/dist/runtime/components/model/iterator.vue +24 -14
  14. package/dist/runtime/composables/alert.d.ts +1 -1
  15. package/dist/runtime/composables/{alert.mjs → alert.js} +1 -2
  16. package/dist/runtime/composables/api.d.ts +4 -4
  17. package/dist/runtime/composables/api.js +52 -0
  18. package/dist/runtime/composables/document/{template.mjs → template.js} +8 -16
  19. package/dist/runtime/composables/graphql.d.ts +6 -5
  20. package/dist/runtime/composables/{graphql.mjs → graphql.js} +31 -40
  21. package/dist/runtime/composables/graphqlModel.d.ts +18 -17
  22. package/dist/runtime/composables/{graphqlModel.mjs → graphqlModel.js} +26 -36
  23. package/dist/runtime/composables/graphqlModelItem.d.ts +13 -13
  24. package/dist/runtime/composables/{graphqlModelItem.mjs → graphqlModelItem.js} +6 -9
  25. package/dist/runtime/composables/graphqlModelOperation.d.ts +7 -7
  26. package/dist/runtime/composables/{graphqlModelOperation.mjs → graphqlModelOperation.js} +6 -12
  27. package/dist/runtime/composables/graphqlOperation.d.ts +2 -2
  28. package/dist/runtime/composables/{graphqlOperation.mjs → graphqlOperation.js} +15 -28
  29. package/dist/runtime/composables/menu.d.ts +1 -1
  30. package/dist/runtime/composables/{menu.mjs → menu.js} +4 -5
  31. package/dist/runtime/composables/utils/fuzzy.d.ts +1 -1
  32. package/dist/runtime/composables/utils/validation.d.ts +32 -0
  33. package/dist/runtime/plugins/permission.d.ts +1 -1
  34. package/dist/runtime/plugins/{permission.mjs → permission.js} +2 -4
  35. package/dist/runtime/types/menu.d.ts +3 -0
  36. package/dist/runtime/utils/datetime.d.ts +214 -16
  37. package/dist/runtime/utils/{datetime.mjs → datetime.js} +22 -44
  38. package/dist/runtime/utils/{object.mjs → object.js} +1 -2
  39. package/dist/types.d.mts +1 -16
  40. package/dist/types.d.ts +1 -16
  41. package/package.json +35 -34
  42. package/dist/runtime/composables/api.mjs +0 -64
  43. package/dist/runtime/plugins/vueSignaturePad.d.ts +0 -2
  44. package/dist/runtime/plugins/vueSignaturePad.mjs +0 -5
  45. /package/dist/runtime/composables/utils/{fuzzy.mjs → fuzzy.js} +0 -0
  46. /package/dist/runtime/composables/utils/{validation.mjs → validation.js} +0 -0
@@ -13,8 +13,7 @@ export function useGraphqlModelOperation(props) {
13
13
  const operationCreate = computed(() => {
14
14
  if (props.operationCreate) {
15
15
  if (typeof props.operationCreate === "string") {
16
- if (graphqlOperation[props.operationCreate])
17
- return graphqlOperation[props.operationCreate];
16
+ if (graphqlOperation[props.operationCreate]) return graphqlOperation[props.operationCreate];
18
17
  } else {
19
18
  return props.operationCreate;
20
19
  }
@@ -24,8 +23,7 @@ export function useGraphqlModelOperation(props) {
24
23
  const operationUpdate = computed(() => {
25
24
  if (props.operationUpdate) {
26
25
  if (typeof props.operationUpdate === "string") {
27
- if (graphqlOperation[props.operationUpdate])
28
- return graphqlOperation[props.operationUpdate];
26
+ if (graphqlOperation[props.operationUpdate]) return graphqlOperation[props.operationUpdate];
29
27
  } else {
30
28
  return props.operationUpdate;
31
29
  }
@@ -35,8 +33,7 @@ export function useGraphqlModelOperation(props) {
35
33
  const operationDelete = computed(() => {
36
34
  if (props.operationDelete) {
37
35
  if (typeof props.operationDelete === "string") {
38
- if (graphqlOperation[props.operationDelete])
39
- return graphqlOperation[props.operationDelete];
36
+ if (graphqlOperation[props.operationDelete]) return graphqlOperation[props.operationDelete];
40
37
  } else {
41
38
  return props.operationDelete;
42
39
  }
@@ -46,8 +43,7 @@ export function useGraphqlModelOperation(props) {
46
43
  const operationRead = computed(() => {
47
44
  if (props.operationRead) {
48
45
  if (typeof props.operationRead === "string") {
49
- if (graphqlOperation[props.operationRead])
50
- return graphqlOperation[props.operationRead];
46
+ if (graphqlOperation[props.operationRead]) return graphqlOperation[props.operationRead];
51
47
  } else {
52
48
  return props.operationRead;
53
49
  }
@@ -57,8 +53,7 @@ export function useGraphqlModelOperation(props) {
57
53
  const operationReadPageable = computed(() => {
58
54
  if (props.operationReadPageable) {
59
55
  if (typeof props.operationReadPageable === "string") {
60
- if (graphqlOperation[props.operationReadPageable])
61
- return graphqlOperation[props.operationReadPageable];
56
+ if (graphqlOperation[props.operationReadPageable]) return graphqlOperation[props.operationReadPageable];
62
57
  } else {
63
58
  return props.operationReadPageable;
64
59
  }
@@ -68,8 +63,7 @@ export function useGraphqlModelOperation(props) {
68
63
  const operationSearch = computed(() => {
69
64
  if (props.operationSearch) {
70
65
  if (typeof props.operationSearch === "string") {
71
- if (graphqlOperation[props.operationSearch])
72
- return graphqlOperation[props.operationSearch];
66
+ if (graphqlOperation[props.operationSearch]) return graphqlOperation[props.operationSearch];
73
67
  } else {
74
68
  return props.operationSearch;
75
69
  }
@@ -1,5 +1,5 @@
1
- import { type ClassConstructor } from '../utils/object';
2
- import type { graphqlTypeObject, graphqlVariable } from '../types/graphqlOperation';
1
+ import { type ClassConstructor } from '../utils/object.js';
2
+ import type { graphqlTypeObject, graphqlVariable } from '../types/graphqlOperation.js';
3
3
  export declare function buildFields(operationFields: graphqlTypeObject, fields?: Array<string | Object> | ClassConstructor<any>, depth?: number): Array<string | Object>;
4
4
  export declare function buildVariables(outputVariables?: graphqlVariable[], inputVariables?: {
5
5
  [p: string]: any;
@@ -1,26 +1,19 @@
1
- import { classAttributes, isClassConstructor } from "../utils/object.mjs";
2
- import { useGraphQl } from "./graphql.mjs";
1
+ import { classAttributes, isClassConstructor } from "../utils/object.js";
2
+ import { useGraphQl } from "./graphql.js";
3
3
  import { graphqlInputType, graphqlOperation, graphqlType, scalarType } from "#imports";
4
4
  export function buildFields(operationFields, fields, depth = 0) {
5
- if (!operationFields)
6
- return [];
7
- if (isClassConstructor(fields))
8
- fields = classAttributes(fields);
9
- if (!fields || fields.length == 0)
10
- fields = [...operationFields.fields];
5
+ if (!operationFields) return [];
6
+ if (isClassConstructor(fields)) fields = classAttributes(fields);
7
+ if (!fields || fields.length == 0) fields = [...operationFields.fields];
11
8
  if (fields.includes("*")) {
12
9
  operationFields.fields.forEach((field) => {
13
- if (!fields.includes(field))
14
- fields.push(field);
10
+ if (!fields.includes(field)) fields.push(field);
15
11
  });
16
12
  fields.splice(fields.indexOf("*"), 1);
17
13
  }
18
- if (depth > 0)
19
- operationFields.relations.forEach((relation) => fields.push(relation.name));
20
- if (!fields.includes("timestampField") && operationFields.relations.find((relation) => relation.name == "timestampField"))
21
- fields.push("timestampField");
22
- if (!fields.includes("userstampField") && operationFields.relations.find((relation) => relation.name == "userstampField"))
23
- fields.push("userstampField");
14
+ if (depth > 0) operationFields.relations.forEach((relation) => fields.push(relation.name));
15
+ if (!fields.includes("timestampField") && operationFields.relations.find((relation) => relation.name == "timestampField")) fields.push("timestampField");
16
+ if (!fields.includes("userstampField") && operationFields.relations.find((relation) => relation.name == "userstampField")) fields.push("userstampField");
24
17
  return fields.map((field) => {
25
18
  if (typeof field == "string" && !operationFields?.fields?.includes(field)) {
26
19
  const relationField = operationFields?.relations?.find((relation) => relation.name == field);
@@ -42,8 +35,7 @@ export function buildFields(operationFields, fields, depth = 0) {
42
35
  }).filter((field) => !!field);
43
36
  }
44
37
  export function buildVariables(outputVariables, inputVariables, reject, isRoot = true) {
45
- if (!outputVariables)
46
- return void 0;
38
+ if (!outputVariables) return void 0;
47
39
  if (inputVariables) {
48
40
  outputVariables.map((variable) => {
49
41
  if (variable.type && !scalarType.includes(variable.type)) {
@@ -77,8 +69,7 @@ export function buildVariables(outputVariables, inputVariables, reject, isRoot =
77
69
  });
78
70
  const usedVariables = outputVariables.map((variable) => variable.name);
79
71
  const droppedVariable = Object.keys(inputVariables || {}).filter((key) => !usedVariables.includes(key));
80
- if (droppedVariable.length > 0)
81
- console.debug("There is data not appeared in schema and dropped before operation.", droppedVariable);
72
+ if (droppedVariable.length > 0) console.debug("There is data not appeared in schema and dropped before operation.", droppedVariable);
82
73
  return outputVariables.reduce((acc, item) => {
83
74
  acc[item.name] = isRoot ? item : item.value;
84
75
  return acc;
@@ -89,8 +80,7 @@ export function buildRequiredInputFields(variables, inputField = "input") {
89
80
  if (inputVariable) {
90
81
  const returnFields = [];
91
82
  graphqlInputType[inputVariable.type]?.variables?.forEach((variable) => {
92
- if (variable.required)
93
- returnFields.push(variable.name);
83
+ if (variable.required) returnFields.push(variable.name);
94
84
  });
95
85
  return returnFields;
96
86
  } else {
@@ -110,12 +100,9 @@ export function useGraphQlOperation(operationType, operation, fields, variables,
110
100
  }
111
101
  if (graphqlOperation[operation]?.fields) {
112
102
  fields = buildFields(graphqlOperation[operation]?.fields, fields, 0);
113
- if (operationType == "Query")
114
- useGraphQl().queryPromise(operation, fields, variables, cache).then((result) => resolve(result)).catch((error) => reject(error));
115
- else if (operationType == "Mutation")
116
- useGraphQl().mutationPromise(operation, fields, variables).then((result) => resolve(result)).catch((error) => reject(error));
117
- else
118
- reject("Invalid Operation Type");
103
+ if (operationType == "Query") useGraphQl().queryPromise(operation, fields, variables, cache).then((result) => resolve(result)).catch((error) => reject(error));
104
+ else if (operationType == "Mutation") useGraphQl().mutationPromise(operation, fields, variables).then((result) => resolve(result)).catch((error) => reject(error));
105
+ else reject("Invalid Operation Type");
119
106
  } else {
120
107
  reject("No schema of return data available");
121
108
  }
@@ -1,6 +1,6 @@
1
1
  import { type ComputedRef, type InjectionKey, type Ref } from 'vue';
2
2
  import { type RouteRecordNormalized, type RouteRecordRaw } from 'vue-router';
3
- import { type MenuItem } from '../types/menu';
3
+ import { type MenuItem } from '../types/menu.js';
4
4
  export interface MenuProvide {
5
5
  menuAll: Ref<MenuItem[]>;
6
6
  menuByRoute: ComputedRef<MenuItem[]>;
@@ -11,18 +11,18 @@ export function routeToMenuItem(route) {
11
11
  icon: menuMeta.icon,
12
12
  role: menuMeta.role,
13
13
  name: route.name,
14
+ image: menuMeta.image,
14
15
  menuItems: [],
15
16
  link: {
16
17
  name: route.name
17
18
  },
18
- active: true
19
+ active: menuMeta.active != void 0 ? menuMeta.active : true
19
20
  };
20
21
  if (route.children) {
21
22
  const menuItems = new Array();
22
23
  for (const children of route.children) {
23
24
  const childMenuItem = routeToMenuItem(children);
24
- if (childMenuItem)
25
- menuItems.push(childMenuItem);
25
+ if (childMenuItem) menuItems.push(childMenuItem);
26
26
  menuItem.menuItems = menuItems;
27
27
  }
28
28
  }
@@ -37,8 +37,7 @@ export function createMenu() {
37
37
  if (paths.length == 2) {
38
38
  if (route.path != "/login" && route.path != "/") {
39
39
  const menuItem = routeToMenuItem(route);
40
- if (menuItem)
41
- menuAll.value.push(menuItem);
40
+ if (menuItem) menuAll.value.push(menuItem);
42
41
  }
43
42
  }
44
43
  }
@@ -1,2 +1,2 @@
1
1
  import type { MaybeRefOrGetter } from 'vue';
2
- export declare function useFuzzy(searchTerm: MaybeRefOrGetter<string>, items: MaybeRefOrGetter<any[]>, fieldName: MaybeRefOrGetter<string[]>, options?: MaybeRefOrGetter<Record<string, any>>): import("vue").ComputedRef<Fuse.FuseResult<DataItem>[]>;
2
+ export declare function useFuzzy(searchTerm: MaybeRefOrGetter<string>, items: MaybeRefOrGetter<any[]>, fieldName: MaybeRefOrGetter<string[]>, options?: MaybeRefOrGetter<Record<string, any>>): import("vue").ComputedRef<import("fuse.js").FuseResult<any>[]>;
@@ -30,5 +30,37 @@ export declare function useRules(): {
30
30
  email: (customError?: string) => (value: any) => string | true;
31
31
  regex: (regex: RegExp | string, customError?: string) => (value: any) => string | true;
32
32
  idcard: (customError?: string) => (value: any) => string | true;
33
+ }, {
34
+ require: (customError?: string) => (value: any) => string | true;
35
+ requireIf: (conditionIf: boolean, customError?: string) => (value: any) => string | true;
36
+ requireTrue: (customError?: string) => (value: any) => string | true;
37
+ requireTrueIf: (conditionIf: boolean, customError?: string) => (value: any) => string | true;
38
+ numeric: (customError?: string) => (value: any) => string | true;
39
+ range: (minValue: number, maxValue: number, customError?: string) => (value: any) => string | true;
40
+ integer: (customError?: string) => (value: any) => string | true;
41
+ unique: (data: Array<any> | object, fieldName: string, customError?: string) => (value: any) => string | true;
42
+ length: (length: number, customError?: string) => (value: any) => string | true;
43
+ lengthGreater: (length: number, customError?: string) => (value: any) => string | true;
44
+ lengthLess: (length: number, customError?: string) => (value: any) => string | true;
45
+ telephone: (customError?: string) => (value: any) => string | true;
46
+ email: (customError?: string) => (value: any) => string | true;
47
+ regex: (regex: RegExp | string, customError?: string) => (value: any) => string | true;
48
+ idcard: (customError?: string) => (value: any) => string | true;
49
+ } | {
50
+ require: (customError?: string) => (value: any) => string | true;
51
+ requireIf: (conditionIf: boolean, customError?: string) => (value: any) => string | true;
52
+ requireTrue: (customError?: string) => (value: any) => string | true;
53
+ requireTrueIf: (conditionIf: boolean, customError?: string) => (value: any) => string | true;
54
+ numeric: (customError?: string) => (value: any) => string | true;
55
+ range: (minValue: number, maxValue: number, customError?: string) => (value: any) => string | true;
56
+ integer: (customError?: string) => (value: any) => string | true;
57
+ unique: (data: Array<any> | object, fieldName: string, customError?: string) => (value: any) => string | true;
58
+ length: (length: number, customError?: string) => (value: any) => string | true;
59
+ lengthGreater: (length: number, customError?: string) => (value: any) => string | true;
60
+ lengthLess: (length: number, customError?: string) => (value: any) => string | true;
61
+ telephone: (customError?: string) => (value: any) => string | true;
62
+ email: (customError?: string) => (value: any) => string | true;
63
+ regex: (regex: RegExp | string, customError?: string) => (value: any) => string | true;
64
+ idcard: (customError?: string) => (value: any) => string | true;
33
65
  }>;
34
66
  };
@@ -1,2 +1,2 @@
1
- declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
1
+ declare const _default: import("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
2
2
  export default _default;
@@ -2,8 +2,7 @@ import { defineNuxtPlugin } from "nuxt/app";
2
2
  import { useAuthentication } from "#imports";
3
3
  export default defineNuxtPlugin(async (nuxtApp) => {
4
4
  function permission(permissionId) {
5
- if (!permissionId || useAuthentication()?.hasPermission(permissionId) === void 0)
6
- return true;
5
+ if (!permissionId || useAuthentication()?.hasPermission(permissionId) === void 0) return true;
7
6
  return useAuthentication()?.hasPermission(permissionId);
8
7
  }
9
8
  nuxtApp.vueApp.config.globalProperties.$permission = permission;
@@ -15,8 +14,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
15
14
  um();
16
15
  });
17
16
  }
18
- if (el.parentElement)
19
- el.parentElement.removeChild(el);
17
+ if (el.parentElement) el.parentElement.removeChild(el);
20
18
  }
21
19
  }
22
20
  });
@@ -9,6 +9,8 @@ declare global {
9
9
  title: string
10
10
  icon: string
11
11
  role: string
12
+ image? : string
13
+ active? : boolean
12
14
  }
13
15
 
14
16
  interface MenuItem {
@@ -19,6 +21,7 @@ declare global {
19
21
  menuItems: Array<MenuItem>
20
22
  active: boolean
21
23
  name: string
24
+ image? : string
22
25
  }
23
26
  }
24
27
 
@@ -4,22 +4,220 @@ export type dateFormat = 'tinyDate' | 'monthShortDate' | 'shortDate' | 'longDate
4
4
  export type dateTimeFormat = 'tinyDateTime' | 'shortDateTime' | 'longDateTime';
5
5
  export declare const Datetime: () => {
6
6
  luxonDateTime: DateTime<false>;
7
- fromString: (dateTime: string | null, formatDate?: string, locale?: supportedLocale) => any;
8
- fromStringTime: (time: string | null, formatTime?: string, locale?: supportedLocale) => any;
9
- fromISO: (dateTime: string, locale?: supportedLocale) => any;
10
- fromObject: (dateTime: DateObjectUnits, locale?: supportedLocale) => any;
11
- setDateTime: (inputDate: DateTime, locale?: supportedLocale) => any;
12
- toFormat: (format: string, locale?: supportedLocale) => any;
13
- toISO: () => any;
14
- toLocaleFormat: (locale: supportedLocale, format: DateTimeFormatOptions) => any;
15
- toTinyDate: (locale?: supportedLocale) => any;
16
- toMonthShortDate: (locale?: supportedLocale) => any;
17
- toShortDate: (locale?: supportedLocale) => any;
18
- toLongDate: (locale?: supportedLocale) => any;
19
- toTinyDateTime: (locale?: supportedLocale) => any;
20
- toShortDateTime: (locale?: supportedLocale) => any;
21
- toLongDateTime: (locale?: supportedLocale) => any;
22
- now: () => any;
7
+ fromString: (dateTime: string | null, formatDate?: string, locale?: supportedLocale) => {
8
+ luxonDateTime: DateTime<false>;
9
+ fromString: any;
10
+ fromStringTime: (time: string | null, formatTime?: string, locale?: supportedLocale) => any;
11
+ fromISO: (dateTime: string, locale?: supportedLocale) => any;
12
+ fromObject: (dateTime: DateObjectUnits, locale?: supportedLocale) => any;
13
+ setDateTime: (inputDate: DateTime, locale?: supportedLocale) => any;
14
+ toFormat: (format: string, locale?: supportedLocale) => "Invalid DateTime";
15
+ toISO: () => null;
16
+ toLocaleFormat: (locale: supportedLocale, format: DateTimeFormatOptions) => "Invalid DateTime";
17
+ toTinyDate: (locale?: supportedLocale) => "Invalid DateTime";
18
+ toMonthShortDate: (locale?: supportedLocale) => "Invalid DateTime";
19
+ toShortDate: (locale?: supportedLocale) => "Invalid DateTime";
20
+ toLongDate: (locale?: supportedLocale) => "Invalid DateTime";
21
+ toTinyDateTime: (locale?: supportedLocale) => "Invalid DateTime";
22
+ toShortDateTime: (locale?: supportedLocale) => "Invalid DateTime";
23
+ toLongDateTime: (locale?: supportedLocale) => "Invalid DateTime";
24
+ now: () => any;
25
+ };
26
+ fromStringTime: (time: string | null, formatTime?: string, locale?: supportedLocale) => {
27
+ luxonDateTime: DateTime<false>;
28
+ fromString: (dateTime: string | null, formatDate?: string, locale?: supportedLocale) => any;
29
+ fromStringTime: any;
30
+ fromISO: (dateTime: string, locale?: supportedLocale) => any;
31
+ fromObject: (dateTime: DateObjectUnits, locale?: supportedLocale) => any;
32
+ setDateTime: (inputDate: DateTime, locale?: supportedLocale) => any;
33
+ toFormat: (format: string, locale?: supportedLocale) => "Invalid DateTime";
34
+ toISO: () => null;
35
+ toLocaleFormat: (locale: supportedLocale, format: DateTimeFormatOptions) => "Invalid DateTime";
36
+ toTinyDate: (locale?: supportedLocale) => "Invalid DateTime";
37
+ toMonthShortDate: (locale?: supportedLocale) => "Invalid DateTime";
38
+ toShortDate: (locale?: supportedLocale) => "Invalid DateTime";
39
+ toLongDate: (locale?: supportedLocale) => "Invalid DateTime";
40
+ toTinyDateTime: (locale?: supportedLocale) => "Invalid DateTime";
41
+ toShortDateTime: (locale?: supportedLocale) => "Invalid DateTime";
42
+ toLongDateTime: (locale?: supportedLocale) => "Invalid DateTime";
43
+ now: () => any;
44
+ };
45
+ fromISO: (dateTime: string, locale?: supportedLocale) => {
46
+ luxonDateTime: DateTime<false>;
47
+ fromString: (dateTime: string | null, formatDate?: string, locale?: supportedLocale) => any;
48
+ fromStringTime: (time: string | null, formatTime?: string, locale?: supportedLocale) => any;
49
+ fromISO: any;
50
+ fromObject: (dateTime: DateObjectUnits, locale?: supportedLocale) => any;
51
+ setDateTime: (inputDate: DateTime, locale?: supportedLocale) => any;
52
+ toFormat: (format: string, locale?: supportedLocale) => "Invalid DateTime";
53
+ toISO: () => null;
54
+ toLocaleFormat: (locale: supportedLocale, format: DateTimeFormatOptions) => "Invalid DateTime";
55
+ toTinyDate: (locale?: supportedLocale) => "Invalid DateTime";
56
+ toMonthShortDate: (locale?: supportedLocale) => "Invalid DateTime";
57
+ toShortDate: (locale?: supportedLocale) => "Invalid DateTime";
58
+ toLongDate: (locale?: supportedLocale) => "Invalid DateTime";
59
+ toTinyDateTime: (locale?: supportedLocale) => "Invalid DateTime";
60
+ toShortDateTime: (locale?: supportedLocale) => "Invalid DateTime";
61
+ toLongDateTime: (locale?: supportedLocale) => "Invalid DateTime";
62
+ now: () => any;
63
+ };
64
+ fromObject: (dateTime: DateObjectUnits, locale?: supportedLocale) => {
65
+ luxonDateTime: DateTime<false>;
66
+ fromString: (dateTime: string | null, formatDate?: string, locale?: supportedLocale) => any;
67
+ fromStringTime: (time: string | null, formatTime?: string, locale?: supportedLocale) => any;
68
+ fromISO: (dateTime: string, locale?: supportedLocale) => any;
69
+ fromObject: any;
70
+ setDateTime: (inputDate: DateTime, locale?: supportedLocale) => any;
71
+ toFormat: (format: string, locale?: supportedLocale) => "Invalid DateTime";
72
+ toISO: () => null;
73
+ toLocaleFormat: (locale: supportedLocale, format: DateTimeFormatOptions) => "Invalid DateTime";
74
+ toTinyDate: (locale?: supportedLocale) => "Invalid DateTime";
75
+ toMonthShortDate: (locale?: supportedLocale) => "Invalid DateTime";
76
+ toShortDate: (locale?: supportedLocale) => "Invalid DateTime";
77
+ toLongDate: (locale?: supportedLocale) => "Invalid DateTime";
78
+ toTinyDateTime: (locale?: supportedLocale) => "Invalid DateTime";
79
+ toShortDateTime: (locale?: supportedLocale) => "Invalid DateTime";
80
+ toLongDateTime: (locale?: supportedLocale) => "Invalid DateTime";
81
+ now: () => any;
82
+ };
83
+ setDateTime: (inputDate: DateTime, locale?: supportedLocale) => {
84
+ luxonDateTime: DateTime<false>;
85
+ fromString: (dateTime: string | null, formatDate?: string, locale?: supportedLocale) => any;
86
+ fromStringTime: (time: string | null, formatTime?: string, locale?: supportedLocale) => any;
87
+ fromISO: (dateTime: string, locale?: supportedLocale) => any;
88
+ fromObject: (dateTime: DateObjectUnits, locale?: supportedLocale) => any;
89
+ setDateTime: any;
90
+ toFormat: (format: string, locale?: supportedLocale) => "Invalid DateTime";
91
+ toISO: () => null;
92
+ toLocaleFormat: (locale: supportedLocale, format: DateTimeFormatOptions) => "Invalid DateTime";
93
+ toTinyDate: (locale?: supportedLocale) => "Invalid DateTime";
94
+ toMonthShortDate: (locale?: supportedLocale) => "Invalid DateTime";
95
+ toShortDate: (locale?: supportedLocale) => "Invalid DateTime";
96
+ toLongDate: (locale?: supportedLocale) => "Invalid DateTime";
97
+ toTinyDateTime: (locale?: supportedLocale) => "Invalid DateTime";
98
+ toShortDateTime: (locale?: supportedLocale) => "Invalid DateTime";
99
+ toLongDateTime: (locale?: supportedLocale) => "Invalid DateTime";
100
+ now: () => any;
101
+ };
102
+ toFormat: (format: string, locale?: supportedLocale) => "Invalid DateTime";
103
+ toISO: () => null;
104
+ toLocaleFormat: (locale: supportedLocale, format: DateTimeFormatOptions) => "Invalid DateTime";
105
+ toTinyDate: (locale?: supportedLocale) => "Invalid DateTime";
106
+ toMonthShortDate: (locale?: supportedLocale) => "Invalid DateTime";
107
+ toShortDate: (locale?: supportedLocale) => "Invalid DateTime";
108
+ toLongDate: (locale?: supportedLocale) => "Invalid DateTime";
109
+ toTinyDateTime: (locale?: supportedLocale) => "Invalid DateTime";
110
+ toShortDateTime: (locale?: supportedLocale) => "Invalid DateTime";
111
+ toLongDateTime: (locale?: supportedLocale) => "Invalid DateTime";
112
+ now: () => {
113
+ luxonDateTime: DateTime<false>;
114
+ fromString: (dateTime: string | null, formatDate?: string, locale?: supportedLocale) => {
115
+ luxonDateTime: DateTime<false>;
116
+ fromString: any;
117
+ fromStringTime: (time: string | null, formatTime?: string, locale?: supportedLocale) => any;
118
+ fromISO: (dateTime: string, locale?: supportedLocale) => any;
119
+ fromObject: (dateTime: DateObjectUnits, locale?: supportedLocale) => any;
120
+ setDateTime: (inputDate: DateTime, locale?: supportedLocale) => any;
121
+ toFormat: (format: string, locale?: supportedLocale) => "Invalid DateTime";
122
+ toISO: () => null;
123
+ toLocaleFormat: (locale: supportedLocale, format: DateTimeFormatOptions) => "Invalid DateTime";
124
+ toTinyDate: (locale?: supportedLocale) => "Invalid DateTime";
125
+ toMonthShortDate: (locale?: supportedLocale) => "Invalid DateTime";
126
+ toShortDate: (locale?: supportedLocale) => "Invalid DateTime";
127
+ toLongDate: (locale?: supportedLocale) => "Invalid DateTime";
128
+ toTinyDateTime: (locale?: supportedLocale) => "Invalid DateTime";
129
+ toShortDateTime: (locale?: supportedLocale) => "Invalid DateTime";
130
+ toLongDateTime: (locale?: supportedLocale) => "Invalid DateTime";
131
+ now: () => any;
132
+ };
133
+ fromStringTime: (time: string | null, formatTime?: string, locale?: supportedLocale) => {
134
+ luxonDateTime: DateTime<false>;
135
+ fromString: (dateTime: string | null, formatDate?: string, locale?: supportedLocale) => any;
136
+ fromStringTime: any;
137
+ fromISO: (dateTime: string, locale?: supportedLocale) => any;
138
+ fromObject: (dateTime: DateObjectUnits, locale?: supportedLocale) => any;
139
+ setDateTime: (inputDate: DateTime, locale?: supportedLocale) => any;
140
+ toFormat: (format: string, locale?: supportedLocale) => "Invalid DateTime";
141
+ toISO: () => null;
142
+ toLocaleFormat: (locale: supportedLocale, format: DateTimeFormatOptions) => "Invalid DateTime";
143
+ toTinyDate: (locale?: supportedLocale) => "Invalid DateTime";
144
+ toMonthShortDate: (locale?: supportedLocale) => "Invalid DateTime";
145
+ toShortDate: (locale?: supportedLocale) => "Invalid DateTime";
146
+ toLongDate: (locale?: supportedLocale) => "Invalid DateTime";
147
+ toTinyDateTime: (locale?: supportedLocale) => "Invalid DateTime";
148
+ toShortDateTime: (locale?: supportedLocale) => "Invalid DateTime";
149
+ toLongDateTime: (locale?: supportedLocale) => "Invalid DateTime";
150
+ now: () => any;
151
+ };
152
+ fromISO: (dateTime: string, locale?: supportedLocale) => {
153
+ luxonDateTime: DateTime<false>;
154
+ fromString: (dateTime: string | null, formatDate?: string, locale?: supportedLocale) => any;
155
+ fromStringTime: (time: string | null, formatTime?: string, locale?: supportedLocale) => any;
156
+ fromISO: any;
157
+ fromObject: (dateTime: DateObjectUnits, locale?: supportedLocale) => any;
158
+ setDateTime: (inputDate: DateTime, locale?: supportedLocale) => any;
159
+ toFormat: (format: string, locale?: supportedLocale) => "Invalid DateTime";
160
+ toISO: () => null;
161
+ toLocaleFormat: (locale: supportedLocale, format: DateTimeFormatOptions) => "Invalid DateTime";
162
+ toTinyDate: (locale?: supportedLocale) => "Invalid DateTime";
163
+ toMonthShortDate: (locale?: supportedLocale) => "Invalid DateTime";
164
+ toShortDate: (locale?: supportedLocale) => "Invalid DateTime";
165
+ toLongDate: (locale?: supportedLocale) => "Invalid DateTime";
166
+ toTinyDateTime: (locale?: supportedLocale) => "Invalid DateTime";
167
+ toShortDateTime: (locale?: supportedLocale) => "Invalid DateTime";
168
+ toLongDateTime: (locale?: supportedLocale) => "Invalid DateTime";
169
+ now: () => any;
170
+ };
171
+ fromObject: (dateTime: DateObjectUnits, locale?: supportedLocale) => {
172
+ luxonDateTime: DateTime<false>;
173
+ fromString: (dateTime: string | null, formatDate?: string, locale?: supportedLocale) => any;
174
+ fromStringTime: (time: string | null, formatTime?: string, locale?: supportedLocale) => any;
175
+ fromISO: (dateTime: string, locale?: supportedLocale) => any;
176
+ fromObject: any;
177
+ setDateTime: (inputDate: DateTime, locale?: supportedLocale) => any;
178
+ toFormat: (format: string, locale?: supportedLocale) => "Invalid DateTime";
179
+ toISO: () => null;
180
+ toLocaleFormat: (locale: supportedLocale, format: DateTimeFormatOptions) => "Invalid DateTime";
181
+ toTinyDate: (locale?: supportedLocale) => "Invalid DateTime";
182
+ toMonthShortDate: (locale?: supportedLocale) => "Invalid DateTime";
183
+ toShortDate: (locale?: supportedLocale) => "Invalid DateTime";
184
+ toLongDate: (locale?: supportedLocale) => "Invalid DateTime";
185
+ toTinyDateTime: (locale?: supportedLocale) => "Invalid DateTime";
186
+ toShortDateTime: (locale?: supportedLocale) => "Invalid DateTime";
187
+ toLongDateTime: (locale?: supportedLocale) => "Invalid DateTime";
188
+ now: () => any;
189
+ };
190
+ setDateTime: (inputDate: DateTime, locale?: supportedLocale) => {
191
+ luxonDateTime: DateTime<false>;
192
+ fromString: (dateTime: string | null, formatDate?: string, locale?: supportedLocale) => any;
193
+ fromStringTime: (time: string | null, formatTime?: string, locale?: supportedLocale) => any;
194
+ fromISO: (dateTime: string, locale?: supportedLocale) => any;
195
+ fromObject: (dateTime: DateObjectUnits, locale?: supportedLocale) => any;
196
+ setDateTime: any;
197
+ toFormat: (format: string, locale?: supportedLocale) => "Invalid DateTime";
198
+ toISO: () => null;
199
+ toLocaleFormat: (locale: supportedLocale, format: DateTimeFormatOptions) => "Invalid DateTime";
200
+ toTinyDate: (locale?: supportedLocale) => "Invalid DateTime";
201
+ toMonthShortDate: (locale?: supportedLocale) => "Invalid DateTime";
202
+ toShortDate: (locale?: supportedLocale) => "Invalid DateTime";
203
+ toLongDate: (locale?: supportedLocale) => "Invalid DateTime";
204
+ toTinyDateTime: (locale?: supportedLocale) => "Invalid DateTime";
205
+ toShortDateTime: (locale?: supportedLocale) => "Invalid DateTime";
206
+ toLongDateTime: (locale?: supportedLocale) => "Invalid DateTime";
207
+ now: () => any;
208
+ };
209
+ toFormat: (format: string, locale?: supportedLocale) => "Invalid DateTime";
210
+ toISO: () => null;
211
+ toLocaleFormat: (locale: supportedLocale, format: DateTimeFormatOptions) => "Invalid DateTime";
212
+ toTinyDate: (locale?: supportedLocale) => "Invalid DateTime";
213
+ toMonthShortDate: (locale?: supportedLocale) => "Invalid DateTime";
214
+ toShortDate: (locale?: supportedLocale) => "Invalid DateTime";
215
+ toLongDate: (locale?: supportedLocale) => "Invalid DateTime";
216
+ toTinyDateTime: (locale?: supportedLocale) => "Invalid DateTime";
217
+ toShortDateTime: (locale?: supportedLocale) => "Invalid DateTime";
218
+ toLongDateTime: (locale?: supportedLocale) => "Invalid DateTime";
219
+ now: any;
220
+ };
23
221
  };
24
222
  export declare function verifyDateFormat(date: string): string | null;
25
223
  export declare function returnVerifyDate(date: string): string | null;
@@ -2,13 +2,10 @@ import { DateTime } from "luxon";
2
2
  export const Datetime = () => ({
3
3
  luxonDateTime: DateTime.invalid("Uninitialized"),
4
4
  fromString: function(dateTime, formatDate, locale = "EN") {
5
- if (!dateTime)
6
- return this.setDateTime(DateTime.invalid("No datetime string provided"), locale);
5
+ if (!dateTime) return this.setDateTime(DateTime.invalid("No datetime string provided"), locale);
7
6
  let inputDate = void 0;
8
- if (formatDate)
9
- inputDate = DateTime.fromFormat(dateTime, formatDate, { locale });
10
- if (!inputDate?.isValid)
11
- inputDate = DateTime.fromISO(dateTime, { locale });
7
+ if (formatDate) inputDate = DateTime.fromFormat(dateTime, formatDate, { locale });
8
+ if (!inputDate?.isValid) inputDate = DateTime.fromISO(dateTime, { locale });
12
9
  if (!inputDate?.isValid) {
13
10
  const formats = [
14
11
  "ddMMyyyy",
@@ -26,18 +23,15 @@ export const Datetime = () => ({
26
23
  ];
27
24
  for (let i = 0; i < formats.length; ++i) {
28
25
  inputDate = DateTime.fromFormat(dateTime, formats[i], { locale });
29
- if (inputDate.isValid)
30
- break;
26
+ if (inputDate.isValid) break;
31
27
  }
32
28
  }
33
29
  return this.setDateTime(inputDate, locale);
34
30
  },
35
31
  fromStringTime: function(time, formatTime, locale = "EN") {
36
- if (!time)
37
- return this.setDateTime(DateTime.invalid("No datetime string provided"), locale);
32
+ if (!time) return this.setDateTime(DateTime.invalid("No datetime string provided"), locale);
38
33
  let inputTime = void 0;
39
- if (formatTime)
40
- inputTime = DateTime.fromFormat(time, formatTime, { locale });
34
+ if (formatTime) inputTime = DateTime.fromFormat(time, formatTime, { locale });
41
35
  if (!inputTime?.isValid) {
42
36
  const formats = [
43
37
  "HHmm",
@@ -49,12 +43,10 @@ export const Datetime = () => ({
49
43
  ];
50
44
  for (let i = 0; i < formats.length; ++i) {
51
45
  inputTime = DateTime.fromFormat(time, formats[i], { locale });
52
- if (inputTime.isValid)
53
- break;
46
+ if (inputTime.isValid) break;
54
47
  }
55
48
  }
56
- if (!inputTime?.isValid)
57
- inputTime = DateTime.fromISO(time, { locale });
49
+ if (!inputTime?.isValid) inputTime = DateTime.fromISO(time, { locale });
58
50
  return this.setDateTime(inputTime, locale);
59
51
  },
60
52
  fromISO: function(dateTime, locale = "EN") {
@@ -67,45 +59,31 @@ export const Datetime = () => ({
67
59
  },
68
60
  setDateTime: function(inputDate, locale = "EN") {
69
61
  if (inputDate.isValid) {
70
- if (inputDate.year - DateTime.now().year > 300)
71
- inputDate = inputDate.set({ year: inputDate.year - 543 });
62
+ if (inputDate.year - DateTime.now().year > 300) inputDate = inputDate.set({ year: inputDate.year - 543 });
72
63
  }
73
64
  this.luxonDateTime = inputDate;
74
- if (locale == "TH")
75
- this.luxonDateTime = this.luxonDateTime.setLocale(locale).reconfigure({ outputCalendar: "buddhist" });
76
- else
77
- this.luxonDateTime = this.luxonDateTime.setLocale(locale).reconfigure({ outputCalendar: "gregory" });
65
+ if (locale == "TH") this.luxonDateTime = this.luxonDateTime.setLocale(locale).reconfigure({ outputCalendar: "buddhist" });
66
+ else this.luxonDateTime = this.luxonDateTime.setLocale(locale).reconfigure({ outputCalendar: "gregory" });
78
67
  return this;
79
68
  },
80
69
  toFormat: function(format, locale = "EN") {
81
- if (format == "tinyDate")
82
- return this.toTinyDate(locale);
83
- if (format == "monthShortDate")
84
- return this.toMonthShortDate(locale);
85
- if (format == "shortDate")
86
- return this.toShortDate(locale);
87
- if (format == "longDate")
88
- return this.toLongDate(locale);
89
- if (format == "tinyDateTime")
90
- return this.toTinyDateTime(locale);
91
- if (format == "shortDateTime")
92
- return this.toShortDateTime(locale);
93
- if (format == "longDateTime")
94
- return this.toLongDateTime(locale);
95
- if (locale == "TH")
96
- this.luxonDateTime = this.luxonDateTime.setLocale(locale).reconfigure({ outputCalendar: "buddhist" });
97
- else
98
- this.luxonDateTime = this.luxonDateTime.setLocale(locale).reconfigure({ outputCalendar: "gregory" });
70
+ if (format == "tinyDate") return this.toTinyDate(locale);
71
+ if (format == "monthShortDate") return this.toMonthShortDate(locale);
72
+ if (format == "shortDate") return this.toShortDate(locale);
73
+ if (format == "longDate") return this.toLongDate(locale);
74
+ if (format == "tinyDateTime") return this.toTinyDateTime(locale);
75
+ if (format == "shortDateTime") return this.toShortDateTime(locale);
76
+ if (format == "longDateTime") return this.toLongDateTime(locale);
77
+ if (locale == "TH") this.luxonDateTime = this.luxonDateTime.setLocale(locale).reconfigure({ outputCalendar: "buddhist" });
78
+ else this.luxonDateTime = this.luxonDateTime.setLocale(locale).reconfigure({ outputCalendar: "gregory" });
99
79
  return this.luxonDateTime.toFormat(format);
100
80
  },
101
81
  toISO: function() {
102
82
  return this.luxonDateTime.toISO();
103
83
  },
104
84
  toLocaleFormat: function(locale, format) {
105
- if (locale == "TH")
106
- this.luxonDateTime = this.luxonDateTime.setLocale(locale).reconfigure({ outputCalendar: "buddhist" });
107
- else
108
- this.luxonDateTime = this.luxonDateTime.setLocale(locale).reconfigure({ outputCalendar: "gregory" });
85
+ if (locale == "TH") this.luxonDateTime = this.luxonDateTime.setLocale(locale).reconfigure({ outputCalendar: "buddhist" });
86
+ else this.luxonDateTime = this.luxonDateTime.setLocale(locale).reconfigure({ outputCalendar: "gregory" });
109
87
  return this.luxonDateTime.setLocale(locale).toLocaleString(format);
110
88
  },
111
89
  toTinyDate: function(locale = "EN") {
@@ -11,8 +11,7 @@ export function classAttributes(cls) {
11
11
  export function onlyAttributes(keys, object) {
12
12
  const returnObject = cloneDeep(object);
13
13
  Object.keys(object).forEach((localKey) => {
14
- if (!keys.includes(localKey))
15
- delete returnObject[localKey];
14
+ if (!keys.includes(localKey)) delete returnObject[localKey];
16
15
  });
17
16
  return returnObject;
18
17
  }