Skip to content

Commit

Permalink
feat(Settings): add getLocaleData method (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValeraS authored May 20, 2023
1 parent 0278321 commit 746383e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@
},
"nano-staged": {
"*.{js,ts}": [
"eslint --fix --quiet",
"prettier --write"
"eslint --fix --quiet"
],
"*.md": [
"prettier --write"
Expand Down
16 changes: 16 additions & 0 deletions src/settings/settings.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import cloneDeep from 'lodash/cloneDeep';
import dayjs from '../dayjs';
import type {UpdateLocaleConfig} from './types';

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 746383e

Please sign in to comment.