@kizmann/nano-ui 0.8.23 → 0.8.24

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kizmann/nano-ui",
3
- "version": "0.8.23",
3
+ "version": "0.8.24",
4
4
  "license": "MIT",
5
5
  "private": false,
6
6
  "author": "Eduard Kizmann <kizmann@protonmail.ch>",
@@ -88,6 +88,14 @@ export default {
88
88
  type: [String]
89
89
  },
90
90
 
91
+ negativeText: {
92
+ default()
93
+ {
94
+ return Locale.trans('Negative duration');
95
+ },
96
+ type: [String]
97
+ },
98
+
91
99
  boundary: {
92
100
  default()
93
101
  {
@@ -122,7 +130,7 @@ export default {
122
130
  days: {
123
131
  default()
124
132
  {
125
- return ':count Day|:count Days';
133
+ return Locale.trans(':count Day|:count Days');
126
134
  },
127
135
  type: [String]
128
136
  },
@@ -130,7 +138,7 @@ export default {
130
138
  hours: {
131
139
  default()
132
140
  {
133
- return ':count Hour|:count Hours';
141
+ return Locale.trans(':count Hour|:count Hours');
134
142
  },
135
143
  type: [String]
136
144
  },
@@ -138,7 +146,7 @@ export default {
138
146
  minutes: {
139
147
  default()
140
148
  {
141
- return ':count Minute|:count Minutes';
149
+ return Locale.trans(':count Minute|:count Minutes');
142
150
  },
143
151
  type: [String]
144
152
  },
@@ -146,7 +154,7 @@ export default {
146
154
  seconds: {
147
155
  default()
148
156
  {
149
- return ':count Second|:count Seconds';
157
+ return Locale.trans(':count Second|:count Seconds');
150
158
  },
151
159
  type: [String]
152
160
  }
@@ -174,12 +182,24 @@ export default {
174
182
 
175
183
  methods: {
176
184
 
185
+ findPattern(text, pattern)
186
+ {
187
+ pattern = pattern.replaceAll(':count', '([0-9\.\,]+)')
188
+ .replaceAll(' ', '\\s*');
189
+
190
+ return text.match(new RegExp(pattern, 'i'));
191
+ },
192
+
177
193
  humanizeValue(value)
178
194
  {
179
195
  if ( Any.isEmpty(value) ) {
180
196
  return '';
181
197
  }
182
198
 
199
+ if ( value < 0 ) {
200
+ return this.negativeText;
201
+ }
202
+
183
203
  let seconds = value;
184
204
 
185
205
  // Extract minutes
@@ -224,29 +244,25 @@ export default {
224
244
 
225
245
  let value = 0;
226
246
 
227
- let days = new RegExp(this.days.replaceAll(':count', '([0-9\.\,]+)'), 'i'),
228
- dmatch = text.match(days);
247
+ let dmatch = this.findPattern(text, this.days);
229
248
 
230
249
  if ( dmatch && dmatch.length === 3 ) {
231
250
  value += Any.float(dmatch[1].replace(',', '.')) * 24 * 60 * 60;
232
251
  }
233
252
 
234
- let hours = new RegExp(this.hours.replaceAll(':count', '([0-9\.\,]+)'), 'i'),
235
- hmatch = text.match(hours);
253
+ let hmatch = this.findPattern(text, this.hours);
236
254
 
237
255
  if ( hmatch && hmatch.length === 3 ) {
238
256
  value += Any.float(hmatch[1].replace(',', '.')) * 60 * 60;
239
257
  }
240
258
 
241
- let minutes = new RegExp(this.minutes.replaceAll(':count', '([0-9\.\,]+)'), 'i'),
242
- mmatch = text.match(minutes);
259
+ let mmatch = this.findPattern(text, this.minutes);
243
260
 
244
261
  if ( mmatch && mmatch.length === 3 ) {
245
262
  value += Any.float(mmatch[1].replace(',', '.')) * 60;
246
263
  }
247
264
 
248
- let seconds = new RegExp(this.seconds.replaceAll(':count', '([0-9\.\,]+)'), 'i'),
249
- smatch = text.match(seconds);
265
+ let smatch = this.findPattern(text, this.seconds);
250
266
 
251
267
  if ( smatch && smatch.length === 3 ) {
252
268
  value += Any.float(smatch[1].replace(',', '.'));