@ramathibodi/nuxt-commons 0.1.2 → 0.1.4

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/module.json CHANGED
@@ -4,5 +4,5 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.0.0"
6
6
  },
7
- "version": "0.1.2"
7
+ "version": "0.1.4"
8
8
  }
@@ -1,47 +1,59 @@
1
1
  <script setup lang="ts">
2
- import { ref } from 'vue';
2
+ import { ref } from 'vue'
3
3
  import { VCard } from 'vuetify/components/VCard'
4
- const isResizing = ref(false);
5
- const pane1Width = ref('50%');
4
+
5
+ const isResizing = ref(false)
6
+ const pane1Width = ref('50%')
6
7
  const containerRef = ref<HTMLElement>()
7
- interface Props extends /* @vue-ignore */ InstanceType<typeof VCard['$props']>{
8
- height? : number | string
8
+ interface Props extends /* @vue-ignore */ InstanceType<typeof VCard['$props']> {
9
+ height?: number | string
9
10
  }
10
11
  const props = defineProps<Props>()
11
12
 
12
13
  const startResize = () => {
13
- isResizing.value = true;
14
- };
14
+ isResizing.value = true
15
+ }
15
16
 
16
17
  const stopResize = () => {
17
- isResizing.value = false;
18
- };
18
+ isResizing.value = false
19
+ }
19
20
 
20
21
  const resize = (event: MouseEvent) => {
21
22
  if (isResizing.value && containerRef.value) {
22
- const containerRect = containerRef.value.getBoundingClientRect();
23
- const newWidth = event.clientX - containerRect.left;
24
- pane1Width.value = `${(newWidth / containerRect.width) * 100}%`;
23
+ const containerRect = containerRef.value.getBoundingClientRect()
24
+ const newWidth = event.clientX - containerRect.left
25
+ pane1Width.value = `${(newWidth / containerRect.width) * 100}%`
25
26
  }
26
- };
27
+ }
27
28
  </script>
28
29
 
29
30
  <template>
30
31
  <v-card :="$attrs">
31
- <v-sheet border :height="height">
32
- <div class="d-flex" ref="containerRef" @mouseup="stopResize" @mousemove="resize" >
33
- <v-sheet :width = "pane1Width">
34
- <slot name="left"></slot>
32
+ <v-sheet
33
+ border
34
+ :height="height"
35
+ >
36
+ <div
37
+ ref="containerRef"
38
+ class="d-flex"
39
+ @mouseup="stopResize"
40
+ @mousemove="resize"
41
+ >
42
+ <v-sheet :width="pane1Width">
43
+ <slot name="left" />
35
44
  </v-sheet>
36
- <v-divider :thickness="3" vertical class="cursor-move" @mousedown="startResize" ></v-divider>
37
- <v-sheet :width = "`calc(100% - ${pane1Width})`" >
38
- <slot name="right"></slot>
45
+ <v-divider
46
+ :thickness="3"
47
+ vertical
48
+ class="cursor-move"
49
+ @mousedown="startResize"
50
+ />
51
+ <v-sheet :width="`calc(100% - ${pane1Width})`">
52
+ <slot name="right" />
39
53
  </v-sheet>
40
54
  </div>
41
55
  </v-sheet>
42
-
43
56
  </v-card>
44
-
45
57
  </template>
46
58
 
47
59
  <style scoped>
@@ -1,8 +1,8 @@
1
1
  <script lang="ts" setup>
2
- import {computed, ref, watch} from 'vue'
2
+ import { computed, ref, watch } from 'vue'
3
3
  import * as prettier from 'prettier'
4
4
  import prettierPluginHtml from 'prettier/plugins/html'
5
- import {useDocumentTemplate, validationRulesRegex} from '../../composables/document/template'
5
+ import { useDocumentTemplate, validationRulesRegex } from '../../composables/document/template'
6
6
 
7
7
  interface Props {
8
8
  modelValue?: string
@@ -82,8 +82,8 @@ async function convertToAdvanceMode() {
82
82
  }
83
83
  }
84
84
 
85
- const inputTypeChoice = ref(['VTextField', 'VTextarea', 'VSelect','VAutocomplete','FormDate','FormTime','FormDateTime','VCombobox', 'VRadio', 'VRadioInline', 'VCheckbox','VSwitch', 'MasterAutocomplete', 'Header', 'Separator', 'CustomCode'])
86
- const requireOption = ref(['VSelect','VAutocomplete','VCombobox', 'VRadio', 'VRadioInline', 'MasterAutocomplete'])
85
+ const inputTypeChoice = ref(['VTextField', 'VTextarea', 'VSelect', 'VAutocomplete', 'FormDate', 'FormTime', 'FormDateTime', 'VCombobox', 'VRadio', 'VRadioInline', 'VCheckbox', 'VSwitch', 'MasterAutocomplete', 'Header', 'Separator', 'CustomCode'])
86
+ const requireOption = ref(['VSelect', 'VAutocomplete', 'VCombobox', 'VRadio', 'VRadioInline', 'MasterAutocomplete'])
87
87
  const notRequireVariable = ref(['Header', 'Separator', 'CustomCode'])
88
88
  const notRequireLabel = ref(['Separator', 'CustomCode'])
89
89
 
@@ -176,8 +176,8 @@ const ruleOptions = (inputType: string) => (value: any) => {
176
176
  </v-col>
177
177
  <v-col v-if="data.inputType!='Separator'">
178
178
  <v-text-field
179
- v-model="data.columnAttributes"
180
- label="Column Attributes"
179
+ v-model="data.columnAttributes"
180
+ label="Column Attributes"
181
181
  />
182
182
  </v-col>
183
183
  <v-col
@@ -1,10 +1,10 @@
1
1
  <script lang="ts" setup>
2
- import {VAutocomplete} from 'vuetify/components/VAutocomplete'
3
- import {concat, isEmpty} from 'lodash-es'
4
- import {computed, ref, watch} from 'vue'
5
- import {watchDebounced} from '@vueuse/core'
6
- import {useFuzzy} from '../../composables/utils/fuzzy'
7
- import {useGraphQl} from '../../composables/graphql'
2
+ import { VAutocomplete } from 'vuetify/components/VAutocomplete'
3
+ import { concat, isEmpty } from 'lodash-es'
4
+ import { computed, ref, watch } from 'vue'
5
+ import { watchDebounced } from '@vueuse/core'
6
+ import { useFuzzy } from '../../composables/utils/fuzzy'
7
+ import { useGraphQl } from '../../composables/graphql'
8
8
 
9
9
  interface Props extends /* @vue-ignore */ InstanceType<typeof VAutocomplete['$props']> {
10
10
  fuzzy?: boolean
@@ -23,8 +23,7 @@ export function createAlert() {
23
23
  },
24
24
  takeAlert(location = "default") {
25
25
  const item = head(items.value.filter((i) => i.alertLocation === location));
26
- if (item)
27
- remove(items.value, (i) => i === item);
26
+ if (item) remove(items.value, (i) => i === item);
28
27
  return item;
29
28
  },
30
29
  hasAlert(location = "default") {
@@ -5,16 +5,13 @@ export function useApi() {
5
5
  function urlBuilder(url) {
6
6
  let returnUrl = "";
7
7
  if (Array.isArray(url)) {
8
- if (url[0].toLowerCase() == "agent")
9
- url[0] = config?.public.WS_AGENT;
8
+ if (url[0].toLowerCase() == "agent") url[0] = config?.public.WS_AGENT;
10
9
  returnUrl = url.join("/");
11
10
  } else {
12
11
  returnUrl = url;
13
12
  }
14
- if (returnUrl.startsWith("http://") || returnUrl.startsWith("https://"))
15
- return returnUrl;
16
- else
17
- return trimEnd(config?.public.WS_API, "/") + "/" + trimStart(returnUrl, "/");
13
+ if (returnUrl.startsWith("http://") || returnUrl.startsWith("https://")) return returnUrl;
14
+ else return trimEnd(config?.public.WS_API, "/") + "/" + trimStart(returnUrl, "/");
18
15
  }
19
16
  function optionBuilder(method, body, params, options) {
20
17
  let returnOption = {
@@ -28,10 +25,8 @@ export function useApi() {
28
25
  };
29
26
  if (options) {
30
27
  options = Object.assign(options, returnOption);
31
- if (options.headers)
32
- options.headers = Object.assign(options.headers, headers);
33
- else
34
- options.headers = headers;
28
+ if (options.headers) options.headers = Object.assign(options.headers, headers);
29
+ else options.headers = headers;
35
30
  }
36
31
  returnOption = Object.assign(returnOption, options);
37
32
  return returnOption;
@@ -42,10 +37,8 @@ export function useApi() {
42
37
  function getPromise(url, body, params, options) {
43
38
  return new Promise(async (resolve, reject) => {
44
39
  const { data, error } = await get(url, body, params, options);
45
- if (!error.value)
46
- resolve(data.value);
47
- else
48
- reject(error.value);
40
+ if (!error.value) resolve(data.value);
41
+ else reject(error.value);
49
42
  });
50
43
  }
51
44
  function post(url, body, params, options) {
@@ -54,10 +47,8 @@ export function useApi() {
54
47
  function postPromise(url, body, params, options) {
55
48
  return new Promise(async (resolve, reject) => {
56
49
  const { data, error } = await post(url, body, params, options);
57
- if (!error.value)
58
- resolve(data.value);
59
- else
60
- reject(error.value);
50
+ if (!error.value) resolve(data.value);
51
+ else reject(error.value);
61
52
  });
62
53
  }
63
54
  return { urlBuilder, get, getPromise, post, postPromise };
@@ -1,7 +1,6 @@
1
1
  export const validationRulesRegex = /^(require(?:\([^)]*\))?|requireIf(?:\([^)]*\))?|requireTrue(?:\([^)]*\))?|requireTrueIf(?:\([^)]*\))?|numeric(?:\([^)]*\))?|range(?:\([^)]*\))?|integer(?:\([^)]*\))?|unique(?:\([^)]*\))?|length(?:\([^)]*\))?|lengthGreater(?:\([^)]*\))?|lengthLess(?:\([^)]*\))?|telephone(?:\([^)]*\))?|email(?:\([^)]*\))?|regex(?:\([^)]*\))?)(,(require(?:\([^)]*\))?|requireIf(?:\([^)]*\))?|requireTrue(?:\([^)]*\))?|requireTrueIf(?:\([^)]*\))?|numeric(?:\([^)]*\))?|range(?:\([^)]*\))?|integer(?:\([^)]*\))?|unique(?:\([^)]*\))?|length(?:\([^)]*\))?|lengthGreater(?:\([^)]*\))?|lengthLess(?:\([^)]*\))?|telephone(?:\([^)]*\))?|email(?:\([^)]*\))?|regex(?:\([^)]*\))?))*$/;
2
2
  export function useDocumentTemplate(items) {
3
- if (!items)
4
- return "";
3
+ if (!items) return "";
5
4
  if (typeof items === "string") {
6
5
  try {
7
6
  items = JSON.parse(items);
@@ -36,10 +35,8 @@ function templateItemToString(item) {
36
35
  optionString = item.inputOptions.split(",").join(" ");
37
36
  }
38
37
  }
39
- if (item.inputType == "FormDateTime" && !item.inputAttributes?.includes("dense"))
40
- item.inputAttributes = (item.inputAttributes?.trim() + " dense").trim();
41
- if (item.validationRules)
42
- validationRules = buildValidationRules(item.validationRules);
38
+ if (item.inputType == "FormDateTime" && !item.inputAttributes?.includes("dense")) item.inputAttributes = (item.inputAttributes?.trim() + " dense").trim();
39
+ if (item.validationRules) validationRules = buildValidationRules(item.validationRules);
43
40
  let templateString = "";
44
41
  switch (item.inputType) {
45
42
  case "CustomCode":
@@ -60,10 +57,8 @@ function templateItemToString(item) {
60
57
  default:
61
58
  templateString = `<${item.inputType} v-model="data.${item.variableName}" label="${item.inputLabel || item.variableName}"${item.inputAttributes ? " " + item.inputAttributes : ""}${optionString ? " " + optionString.trim() : ""}${validationRules ? " " + validationRules.trim() : ""}></${item.inputType}>`;
62
59
  }
63
- if (!["Separator", "Header"].includes(item.inputType))
64
- templateString = `<v-col${item.width ? ' cols="' + item.width + '"' : ""}${item.columnAttributes ? " " + item.columnAttributes : ""}>${templateString}</v-col>`;
65
- if (["Header"].includes(item.inputType))
66
- templateString = `</v-row><v-row dense><v-col${item.columnAttributes ? " " + item.columnAttributes : ""}>${templateString}</v-col></v-row><v-row dense>`;
60
+ if (!["Separator", "Header"].includes(item.inputType)) templateString = `<v-col${item.width ? ' cols="' + item.width + '"' : ""}${item.columnAttributes ? " " + item.columnAttributes : ""}>${templateString}</v-col>`;
61
+ if (["Header"].includes(item.inputType)) templateString = `</v-row><v-row dense><v-col${item.columnAttributes ? " " + item.columnAttributes : ""}>${templateString}</v-col></v-row><v-row dense>`;
67
62
  return templateString;
68
63
  }
69
64
  function optionStringToChoiceObject(option) {
@@ -84,12 +79,9 @@ function optionStringToChoiceObject(option) {
84
79
  }
85
80
  function buildValidationRules(validationString) {
86
81
  validationString = validationString.trim();
87
- if (validationString.startsWith("["))
88
- validationString = validationString.substring(1);
89
- if (validationString.endsWith("]"))
90
- validationString = validationString.substring(0, validationString.length - 1);
91
- if (!validationRulesRegex.test(validationString))
92
- return "";
82
+ if (validationString.startsWith("[")) validationString = validationString.substring(1);
83
+ if (validationString.endsWith("]")) validationString = validationString.substring(0, validationString.length - 1);
84
+ if (!validationRulesRegex.test(validationString)) return "";
93
85
  validationString = validationString.split(",").map((rule) => {
94
86
  rule = rule.trim();
95
87
  if (!rule.startsWith("rules.")) {
@@ -10,8 +10,8 @@ declare type VariableOptions = {
10
10
  };
11
11
  export declare function useGraphQl(): {
12
12
  query: <T>(operation: string, fields: Array<string | Object> | ClassConstructor<any>, variables?: VariableOptions, cache?: boolean) => any;
13
- queryPromise: <T_1>(operation: string, fields: Array<string | Object> | ClassConstructor<any>, variables?: VariableOptions, cache?: boolean) => Promise<T_1>;
14
- mutation: <T_2>(operation: string, fields: Array<string | Object> | ClassConstructor<any>, variables?: VariableOptions) => any;
15
- mutationPromise: <T_3>(operation: string, fields: Array<string | Object> | ClassConstructor<any>, variables?: VariableOptions) => Promise<T_3>;
13
+ queryPromise: <T>(operation: string, fields: Array<string | Object> | ClassConstructor<any>, variables?: VariableOptions, cache?: boolean) => Promise<T>;
14
+ mutation: <T>(operation: string, fields: Array<string | Object> | ClassConstructor<any>, variables?: VariableOptions) => any;
15
+ mutationPromise: <T>(operation: string, fields: Array<string | Object> | ClassConstructor<any>, variables?: VariableOptions) => Promise<T>;
16
16
  };
17
17
  export {};
@@ -4,8 +4,7 @@ import { classAttributes, isClassConstructor } from "../utils/object.mjs";
4
4
  import { gql, useAsyncQuery, useMutation } from "#imports";
5
5
  export function useGraphQl() {
6
6
  function query(operation, fields, variables, cache = false) {
7
- if (isClassConstructor(fields))
8
- fields = classAttributes(fields);
7
+ if (isClassConstructor(fields)) fields = classAttributes(fields);
9
8
  const builder = gqlQuery({ operation, fields, variables });
10
9
  const options = {
11
10
  query: gql(builder.query),
@@ -15,8 +14,7 @@ export function useGraphQl() {
15
14
  return useAsyncQuery(options);
16
15
  }
17
16
  function queryPromise(operation, fields, variables, cache = false) {
18
- if (isClassConstructor(fields))
19
- fields = classAttributes(fields);
17
+ if (isClassConstructor(fields)) fields = classAttributes(fields);
20
18
  const builder = gqlQuery({ operation, fields, variables });
21
19
  return new Promise((resolve, reject) => {
22
20
  const { onResult, onError } = useQuery(gql(builder.query), builder.variables, { fetchPolicy: cache ? "cache-first" : "no-cache" });
@@ -34,14 +32,12 @@ export function useGraphQl() {
34
32
  });
35
33
  }
36
34
  function mutation(operation, fields, variables) {
37
- if (isClassConstructor(fields))
38
- fields = classAttributes(fields);
35
+ if (isClassConstructor(fields)) fields = classAttributes(fields);
39
36
  const builder = gqlMutation({ operation, fields, variables });
40
37
  return useMutation(gql(builder.query), { variables: builder.variables });
41
38
  }
42
39
  function mutationPromise(operation, fields, variables) {
43
- if (isClassConstructor(fields))
44
- fields = classAttributes(fields);
40
+ if (isClassConstructor(fields)) fields = classAttributes(fields);
45
41
  const builder = gqlMutation({ operation, fields, variables });
46
42
  return new Promise(async (resolve, reject) => {
47
43
  const { mutate, error } = useMutation(gql(builder.query), { variables: builder.variables });
@@ -0,0 +1,11 @@
1
+ import { type ComputedRef, type InjectionKey, type Ref } from 'vue';
2
+ import { type RouteRecordNormalized, type RouteRecordRaw } from 'vue-router';
3
+ import { type MenuItem } from '../types/menu';
4
+ export interface MenuProvide {
5
+ menuAll: Ref<MenuItem[]>;
6
+ menuByRoute: ComputedRef<MenuItem[]>;
7
+ }
8
+ export declare const MenuKey: InjectionKey<MenuProvide>;
9
+ export declare function routeToMenuItem(route: RouteRecordRaw | RouteRecordNormalized): MenuItem | undefined;
10
+ export declare function createMenu(): void;
11
+ export declare function useMenu(): MenuProvide | null;
@@ -1,6 +1,6 @@
1
- import { inject, provide, ref } from "vue";
2
- import { useRoute, useRouter } from "vue-router";
1
+ import { computed, inject, provide, ref } from "vue";
3
2
  import { isUndefined } from "lodash-es";
3
+ import { useRoute, useRouter } from "#imports";
4
4
  export const MenuKey = Symbol.for("ramacare:menu");
5
5
  export function routeToMenuItem(route) {
6
6
  let menuItem = void 0;
@@ -21,8 +21,7 @@ export function routeToMenuItem(route) {
21
21
  const menuItems = new Array();
22
22
  for (const children of route.children) {
23
23
  const childMenuItem = routeToMenuItem(children);
24
- if (childMenuItem)
25
- menuItems.push(childMenuItem);
24
+ if (childMenuItem) menuItems.push(childMenuItem);
26
25
  menuItem.menuItems = menuItems;
27
26
  }
28
27
  }
@@ -37,13 +36,12 @@ export function createMenu() {
37
36
  if (paths.length == 2) {
38
37
  if (route.path != "/login" && route.path != "/") {
39
38
  const menuItem = routeToMenuItem(route);
40
- if (menuItem)
41
- menuAll.value.push(menuItem);
39
+ if (menuItem) menuAll.value.push(menuItem);
42
40
  }
43
41
  }
44
42
  }
45
43
  provide(MenuKey, {
46
- menuByRoute: () => {
44
+ menuByRoute: computed(() => {
47
45
  const route = useRoute();
48
46
  for (const menuItem of menuAll.value) {
49
47
  if (menuItem.name == route.path.split("/")[1]) {
@@ -51,7 +49,7 @@ export function createMenu() {
51
49
  }
52
50
  }
53
51
  return [];
54
- },
52
+ }),
55
53
  menuAll
56
54
  });
57
55
  }
@@ -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<import("fuse.js").default.FuseResult<any>[]>;
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,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
  });
@@ -22,4 +22,4 @@ declare global {
22
22
  }
23
23
  }
24
24
 
25
- export {}
25
+ export { MenuMeta, MenuItem }
@@ -3,3 +3,5 @@ declare module '@zxing/browser'
3
3
  declare module 'vue-signature-pad'
4
4
  declare module 'accounting'
5
5
  declare module 'pdf-vue3'
6
+ declare module "prettier"
7
+ declare module "prettier/plugins/html"
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramathibodi/nuxt-commons",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Ramathibodi Nuxt modules for common components",
5
5
  "repository": {
6
6
  "type": "git",
@@ -56,7 +56,7 @@
56
56
  "@zxing/browser": "^0.1.4",
57
57
  "cropperjs": "^1.6.2",
58
58
  "currency.js": "^2.0.4",
59
- "fuse.js": "^6.6.2",
59
+ "fuse.js": "^7.0.0",
60
60
  "gql-query-builder": "^3.8.0",
61
61
  "lodash": "^4.17.21",
62
62
  "luxon": "^3.4.4",