From 746383eaff6e1e5dfb1fd0f7005dd5e9be0a4f86 Mon Sep 17 00:00:00 2001 From: Valerii Sidorenko Date: Sat, 20 May 2023 17:19:59 +0200 Subject: [PATCH] feat(Settings): add getLocaleData method (#28) --- package.json | 3 +-- src/settings/settings.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5baaade..f4954b6 100644 --- a/package.json +++ b/package.json @@ -46,8 +46,7 @@ }, "nano-staged": { "*.{js,ts}": [ - "eslint --fix --quiet", - "prettier --write" + "eslint --fix --quiet" ], "*.md": [ "prettier --write" diff --git a/src/settings/settings.ts b/src/settings/settings.ts index ba3680e..65ff1fb 100644 --- a/src/settings/settings.ts +++ b/src/settings/settings.ts @@ -1,3 +1,4 @@ +import cloneDeep from 'lodash/cloneDeep'; import dayjs from '../dayjs'; import type {UpdateLocaleConfig} from './types'; @@ -28,6 +29,21 @@ class Settings { return dayjs.locale(); } + getLocaleData() { + const locales = dayjs.Ls; + + let localeObject = locales[this.getLocale()]; + if (!localeObject) { + localeObject = locales.en; + } + + if (!localeObject) { + throw new Error('There is something really wrong happening. Locale data is absent.'); + } + + return cloneDeep(localeObject); + } + setLocale(locale: string) { if (!this.isLocaleLoaded(locale)) { throw new Error(