bfg-common 1.3.362 → 1.3.363

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.
@@ -1,4 +1,5 @@
1
1
  import type { UI_I_Localization } from '~/lib/models/interfaces'
2
+ import { UI_I_ArbitraryObject } from '~/lib/models/interfaces'
2
3
  import type { UI_I_OptionItem } from '~/components/atoms/lib/models/interfaces'
3
4
 
4
5
  export const timespanFunc = (
@@ -37,10 +38,16 @@ export const customTimeFunc = (
37
38
  ): UI_I_OptionItem[] => {
38
39
  const isLangRu = lang === 'ru_RU'
39
40
 
40
- const hourText = isLangRu ? getCorrectHourForm(hour) : localization.hours2
41
- const dayText = isLangRu ? getCorrectDayForm(hour) : localization.days2
42
- const weekText = isLangRu ? getCorrectWeekForm(hour) : localization.weeks2
43
- const monthText = isLangRu ? getCorrectMonthForm(hour) : localization.months2
41
+ const hourText = isLangRu
42
+ ? getCorrectRuForm(hour, 'hour')
43
+ : localization.hours2
44
+ const dayText = isLangRu ? getCorrectRuForm(hour, 'day') : localization.days2
45
+ const weekText = isLangRu
46
+ ? getCorrectRuForm(hour, 'week')
47
+ : localization.weeks2
48
+ const monthText = isLangRu
49
+ ? getCorrectRuForm(hour, 'month')
50
+ : localization.months2
44
51
 
45
52
  return [
46
53
  {
@@ -75,89 +82,30 @@ export const chartTypeFunc = (
75
82
  },
76
83
  ]
77
84
 
78
- const getCorrectHourForm = (hours: number): string => {
79
- let text: string
80
-
81
- if (!hours) {
82
- return getCorrectHourForm.text
83
- }
84
-
85
- if (hours % 10 === 1 && hours % 100 !== 11) {
86
- text = 'Час'
87
- } else if (
88
- [2, 3, 4].includes(hours % 10) &&
89
- ![12, 13, 14].includes(hours % 100)
90
- ) {
91
- text = 'Часа'
92
- } else {
93
- text = 'Часов'
94
- }
95
-
96
- getCorrectHourForm.text = text
97
- return text
98
- }
99
-
100
- const getCorrectDayForm = (days: number): string => {
101
- let text: string
102
-
103
- if (!days) {
104
- return getCorrectDayForm.text
105
- }
106
-
107
- if (days % 10 === 1 && days % 100 !== 11) {
108
- text = 'День'
109
- } else if (
110
- [2, 3, 4].includes(days % 10) &&
111
- ![12, 13, 14].includes(days % 100)
112
- ) {
113
- text = 'Дня'
114
- } else {
115
- text = 'Дней'
85
+ const getCorrectRuForm = (value: number, type: string): string => {
86
+ const forms: UI_I_ArbitraryObject<string[]> = {
87
+ hour: ['Час', 'Часа', 'Часов'],
88
+ day: ['День', 'Дня', 'Дней'],
89
+ week: ['Неделя', 'Недели', 'Недель'],
90
+ month: ['Месяц', 'Месяца', 'Месяцев'],
116
91
  }
117
92
 
118
- getCorrectDayForm.text = text
119
- return text
120
- }
121
- const getCorrectWeekForm = (weeks: number): string => {
122
93
  let text: string
123
94
 
124
- if (!weeks) {
125
- return getCorrectWeekForm.text
95
+ if (!value) {
96
+ return getCorrectRuForm[type]
126
97
  }
127
98
 
128
- if (weeks % 10 === 1 && weeks % 100 !== 11) {
129
- text = 'Неделя'
99
+ if (value % 10 === 1 && value % 100 !== 11) {
100
+ text = forms[type][0]
130
101
  } else if (
131
- [2, 3, 4].includes(weeks % 10) &&
132
- ![12, 13, 14].includes(weeks % 100)
102
+ [2, 3, 4].includes(value % 10) &&
103
+ ![12, 13, 14].includes(value % 100)
133
104
  ) {
134
- text = 'Недели'
105
+ text = forms[type][1]
135
106
  } else {
136
- text = 'Недель'
107
+ text = forms[type][2]
137
108
  }
138
-
139
- getCorrectWeekForm.text = text
140
- return text
141
- }
142
-
143
- const getCorrectMonthForm = (months: number): string => {
144
- let text: string
145
-
146
- if (!months) {
147
- return getCorrectMonthForm.text
148
- }
149
-
150
- if (months % 10 === 1 && months % 100 !== 11) {
151
- text = 'Месяц'
152
- } else if (
153
- [2, 3, 4].includes(months % 10) &&
154
- ![12, 13, 14].includes(months % 100)
155
- ) {
156
- text = 'Месяца'
157
- } else {
158
- text = 'Месяцев'
159
- }
160
-
161
- getCorrectMonthForm.text = text
109
+ getCorrectRuForm[type] = text
162
110
  return text
163
111
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bfg-common",
3
3
  "private": false,
4
- "version": "1.3.362",
4
+ "version": "1.3.363",
5
5
  "scripts": {
6
6
  "build": "nuxt build",
7
7
  "dev": "nuxt dev --port=3002",