Total Complexity | 106 |
Complexity/F | 21.2 |
Lines of Code | 170 |
Function Count | 5 |
Duplicated Lines | 170 |
Ratio | 100 % |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like formio/node_modules/moment/locale/sl.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | //! moment.js locale configuration |
||
5 | View Code Duplication | ;(function (global, factory) { |
|
6 | typeof exports === 'object' && typeof module !== 'undefined' |
||
7 | && typeof require === 'function' ? factory(require('../moment')) : |
||
8 | typeof define === 'function' && define.amd ? define(['../moment'], factory) : |
||
9 | factory(global.moment) |
||
10 | }(this, (function (moment) { 'use strict'; |
||
11 | |||
12 | |||
13 | function processRelativeTime(number, withoutSuffix, key, isFuture) { |
||
14 | var result = number + ' '; |
||
15 | switch (key) { |
||
|
|||
16 | case 's': |
||
17 | return withoutSuffix || isFuture ? 'nekaj sekund' : 'nekaj sekundami'; |
||
18 | case 'ss': |
||
19 | if (number === 1) { |
||
20 | result += withoutSuffix ? 'sekundo' : 'sekundi'; |
||
21 | } else if (number === 2) { |
||
22 | result += withoutSuffix || isFuture ? 'sekundi' : 'sekundah'; |
||
23 | } else if (number < 5) { |
||
24 | result += withoutSuffix || isFuture ? 'sekunde' : 'sekundah'; |
||
25 | } else { |
||
26 | result += withoutSuffix || isFuture ? 'sekund' : 'sekund'; |
||
27 | } |
||
28 | return result; |
||
29 | case 'm': |
||
30 | return withoutSuffix ? 'ena minuta' : 'eno minuto'; |
||
31 | case 'mm': |
||
32 | if (number === 1) { |
||
33 | result += withoutSuffix ? 'minuta' : 'minuto'; |
||
34 | } else if (number === 2) { |
||
35 | result += withoutSuffix || isFuture ? 'minuti' : 'minutama'; |
||
36 | } else if (number < 5) { |
||
37 | result += withoutSuffix || isFuture ? 'minute' : 'minutami'; |
||
38 | } else { |
||
39 | result += withoutSuffix || isFuture ? 'minut' : 'minutami'; |
||
40 | } |
||
41 | return result; |
||
42 | case 'h': |
||
43 | return withoutSuffix ? 'ena ura' : 'eno uro'; |
||
44 | case 'hh': |
||
45 | if (number === 1) { |
||
46 | result += withoutSuffix ? 'ura' : 'uro'; |
||
47 | } else if (number === 2) { |
||
48 | result += withoutSuffix || isFuture ? 'uri' : 'urama'; |
||
49 | } else if (number < 5) { |
||
50 | result += withoutSuffix || isFuture ? 'ure' : 'urami'; |
||
51 | } else { |
||
52 | result += withoutSuffix || isFuture ? 'ur' : 'urami'; |
||
53 | } |
||
54 | return result; |
||
55 | case 'd': |
||
56 | return withoutSuffix || isFuture ? 'en dan' : 'enim dnem'; |
||
57 | case 'dd': |
||
58 | if (number === 1) { |
||
59 | result += withoutSuffix || isFuture ? 'dan' : 'dnem'; |
||
60 | } else if (number === 2) { |
||
61 | result += withoutSuffix || isFuture ? 'dni' : 'dnevoma'; |
||
62 | } else { |
||
63 | result += withoutSuffix || isFuture ? 'dni' : 'dnevi'; |
||
64 | } |
||
65 | return result; |
||
66 | case 'M': |
||
67 | return withoutSuffix || isFuture ? 'en mesec' : 'enim mesecem'; |
||
68 | case 'MM': |
||
69 | if (number === 1) { |
||
70 | result += withoutSuffix || isFuture ? 'mesec' : 'mesecem'; |
||
71 | } else if (number === 2) { |
||
72 | result += withoutSuffix || isFuture ? 'meseca' : 'mesecema'; |
||
73 | } else if (number < 5) { |
||
74 | result += withoutSuffix || isFuture ? 'mesece' : 'meseci'; |
||
75 | } else { |
||
76 | result += withoutSuffix || isFuture ? 'mesecev' : 'meseci'; |
||
77 | } |
||
78 | return result; |
||
79 | case 'y': |
||
80 | return withoutSuffix || isFuture ? 'eno leto' : 'enim letom'; |
||
81 | case 'yy': |
||
82 | if (number === 1) { |
||
83 | result += withoutSuffix || isFuture ? 'leto' : 'letom'; |
||
84 | } else if (number === 2) { |
||
85 | result += withoutSuffix || isFuture ? 'leti' : 'letoma'; |
||
86 | } else if (number < 5) { |
||
87 | result += withoutSuffix || isFuture ? 'leta' : 'leti'; |
||
88 | } else { |
||
89 | result += withoutSuffix || isFuture ? 'let' : 'leti'; |
||
90 | } |
||
91 | return result; |
||
92 | } |
||
93 | } |
||
94 | |||
95 | var sl = moment.defineLocale('sl', { |
||
96 | months : 'januar_februar_marec_april_maj_junij_julij_avgust_september_oktober_november_december'.split('_'), |
||
97 | monthsShort : 'jan._feb._mar._apr._maj._jun._jul._avg._sep._okt._nov._dec.'.split('_'), |
||
98 | monthsParseExact: true, |
||
99 | weekdays : 'nedelja_ponedeljek_torek_sreda_četrtek_petek_sobota'.split('_'), |
||
100 | weekdaysShort : 'ned._pon._tor._sre._čet._pet._sob.'.split('_'), |
||
101 | weekdaysMin : 'ne_po_to_sr_če_pe_so'.split('_'), |
||
102 | weekdaysParseExact : true, |
||
103 | longDateFormat : { |
||
104 | LT : 'H:mm', |
||
105 | LTS : 'H:mm:ss', |
||
106 | L : 'DD.MM.YYYY', |
||
107 | LL : 'D. MMMM YYYY', |
||
108 | LLL : 'D. MMMM YYYY H:mm', |
||
109 | LLLL : 'dddd, D. MMMM YYYY H:mm' |
||
110 | }, |
||
111 | calendar : { |
||
112 | sameDay : '[danes ob] LT', |
||
113 | nextDay : '[jutri ob] LT', |
||
114 | |||
115 | nextWeek : function () { |
||
116 | switch (this.day()) { |
||
117 | case 0: |
||
118 | return '[v] [nedeljo] [ob] LT'; |
||
119 | case 3: |
||
120 | return '[v] [sredo] [ob] LT'; |
||
121 | case 6: |
||
122 | return '[v] [soboto] [ob] LT'; |
||
123 | case 1: |
||
124 | case 2: |
||
125 | case 4: |
||
126 | case 5: |
||
127 | return '[v] dddd [ob] LT'; |
||
128 | } |
||
129 | }, |
||
130 | lastDay : '[včeraj ob] LT', |
||
131 | lastWeek : function () { |
||
132 | switch (this.day()) { |
||
133 | case 0: |
||
134 | return '[prejšnjo] [nedeljo] [ob] LT'; |
||
135 | case 3: |
||
136 | return '[prejšnjo] [sredo] [ob] LT'; |
||
137 | case 6: |
||
138 | return '[prejšnjo] [soboto] [ob] LT'; |
||
139 | case 1: |
||
140 | case 2: |
||
141 | case 4: |
||
142 | case 5: |
||
143 | return '[prejšnji] dddd [ob] LT'; |
||
144 | } |
||
145 | }, |
||
146 | sameElse : 'L' |
||
147 | }, |
||
148 | relativeTime : { |
||
149 | future : 'čez %s', |
||
150 | past : 'pred %s', |
||
151 | s : processRelativeTime, |
||
152 | ss : processRelativeTime, |
||
153 | m : processRelativeTime, |
||
154 | mm : processRelativeTime, |
||
155 | h : processRelativeTime, |
||
156 | hh : processRelativeTime, |
||
157 | d : processRelativeTime, |
||
158 | dd : processRelativeTime, |
||
159 | M : processRelativeTime, |
||
160 | MM : processRelativeTime, |
||
161 | y : processRelativeTime, |
||
162 | yy : processRelativeTime |
||
163 | }, |
||
164 | dayOfMonthOrdinalParse: /\d{1,2}\./, |
||
165 | ordinal : '%d.', |
||
166 | week : { |
||
167 | dow : 1, // Monday is the first day of the week. |
||
168 | doy : 7 // The week that contains Jan 1st is the first week of the year. |
||
169 | } |
||
170 | }); |
||
171 | |||
172 | return sl; |
||
173 | |||
174 | }))); |
||
175 |