refactor: use switch case instead
This commit is contained in:
parent
d8844e7599
commit
5e524ec91d
2 changed files with 23 additions and 22 deletions
|
|
@ -15,6 +15,9 @@ export function dateFormatJS(opts: {
|
||||||
dayStyle?: 'numeric' | '2-digit';
|
dayStyle?: 'numeric' | '2-digit';
|
||||||
monthStyle?: 'numeric' | '2-digit' | 'long' | 'short';
|
monthStyle?: 'numeric' | '2-digit' | 'long' | 'short';
|
||||||
timeStyle?: 'full' | 'long' | 'medium' | 'short';
|
timeStyle?: 'full' | 'long' | 'medium' | 'short';
|
||||||
|
noDay?: boolean;
|
||||||
|
noMonth?: boolean;
|
||||||
|
noYear?: boolean;
|
||||||
}) {
|
}) {
|
||||||
const dt = opts.date ? new Date(opts.date) : new Date();
|
const dt = opts.date ? new Date(opts.date) : new Date();
|
||||||
|
|
||||||
|
|
@ -25,10 +28,10 @@ export function dateFormatJS(opts: {
|
||||||
}
|
}
|
||||||
|
|
||||||
let formatted = new Intl.DateTimeFormat(opts.locale, {
|
let formatted = new Intl.DateTimeFormat(opts.locale, {
|
||||||
day: opts.dayStyle || 'numeric',
|
day: opts.noDay ? undefined : opts.dayStyle || 'numeric',
|
||||||
month: opts.monthStyle || 'short',
|
month: opts.noMonth ? undefined : opts.monthStyle || 'short',
|
||||||
timeStyle: opts.timeStyle,
|
timeStyle: opts.timeStyle,
|
||||||
year: 'numeric',
|
year: opts.noYear ? undefined : 'numeric',
|
||||||
}).format(dt);
|
}).format(dt);
|
||||||
|
|
||||||
switch (opts.locale) {
|
switch (opts.locale) {
|
||||||
|
|
@ -42,9 +45,8 @@ export function dateFormatJS(opts: {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Please use dateFormatJS.
|
* @deprecated use dateFormatJS instead.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function dateFormat(
|
export function dateFormat(
|
||||||
date?: string | Date | null,
|
date?: string | Date | null,
|
||||||
fullmonth = false,
|
fullmonth = false,
|
||||||
|
|
|
||||||
|
|
@ -25,17 +25,17 @@ export function initTheme(): Theme {
|
||||||
* **Warning:** Must be called after initialize vue and quasar.
|
* **Warning:** Must be called after initialize vue and quasar.
|
||||||
*/
|
*/
|
||||||
export function setTheme(theme: Theme): Theme {
|
export function setTheme(theme: Theme): Theme {
|
||||||
localStorage.setItem('currentTheme', theme);
|
switch (theme) {
|
||||||
|
case Theme.Light:
|
||||||
if (theme !== Theme.Auto) {
|
case Theme.Dark:
|
||||||
Dark.set(theme === Theme.Dark);
|
localStorage.setItem('currentTheme', theme);
|
||||||
|
Dark.set(theme !== Theme.Dark);
|
||||||
|
return theme;
|
||||||
|
default:
|
||||||
|
localStorage.setItem('currentTheme', Theme.Auto);
|
||||||
|
Dark.set(window.matchMedia('(prefers-color-scheme: dark)').matches);
|
||||||
|
return Theme.Auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (theme === Theme.Auto) {
|
|
||||||
Dark.set(window.matchMedia('(prefers-color-scheme: dark)').matches);
|
|
||||||
}
|
|
||||||
|
|
||||||
return theme;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum Lang {
|
export enum Lang {
|
||||||
|
|
@ -49,16 +49,15 @@ export enum Lang {
|
||||||
* **Warning:** Must be used after initialize vue and vue-i18n
|
* **Warning:** Must be used after initialize vue and vue-i18n
|
||||||
*/
|
*/
|
||||||
export function initLang(): Lang {
|
export function initLang(): Lang {
|
||||||
const { locale } = i18n.global;
|
|
||||||
const current = localStorage.getItem('currentLanguage') as Lang | null;
|
const current = localStorage.getItem('currentLanguage') as Lang | null;
|
||||||
|
|
||||||
if (current !== Lang.English && current !== Lang.Thai) {
|
switch (current) {
|
||||||
return setLang(Lang.Thai);
|
case Lang.English:
|
||||||
|
case Lang.Thai:
|
||||||
|
return setLang(current);
|
||||||
|
default:
|
||||||
|
return setLang(Lang.Thai);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!current) return setLang(locale.value as Lang);
|
|
||||||
|
|
||||||
return setLang(current);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue