@radiantabyss/vue 3.1.6 → 3.1.7

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/Support/Str.js +131 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radiantabyss/vue",
3
- "version": "3.1.6",
3
+ "version": "3.1.7",
4
4
  "author": "radiantabyss.com",
5
5
  "license": "ISC",
6
6
  "eslintConfig": {
@@ -204,6 +204,137 @@ let self = {
204
204
 
205
205
  return str;
206
206
  },
207
+
208
+ string_to_date(str) {
209
+ let match;
210
+ let months_short = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];
211
+
212
+ //trim spaces
213
+ str = str.trim();
214
+
215
+ //dash format: 23-10-2024
216
+ match = str.match(/(\d{2})-(\d{2})-(\d{4})/);
217
+ if ( match && match.length == 4 ) {
218
+ return new Date(`${match[3]}-${match[2]}-${match[1]}`);
219
+ }
220
+
221
+ //dot format: 23.10.2024
222
+ match = str.match(/(\d{2})\.(\d{2})\.(\d{4})/);
223
+ if ( match && match.length == 4 ) {
224
+ return new Date(`${match[3]}-${match[2]}-${match[1]}`);
225
+ }
226
+
227
+ //pretty format: 23 Oct
228
+ match = str.match(/(\d{2}) (\w{3})/i);
229
+ if ( match && match.length == 3 ) {
230
+ let date = new Date();
231
+ let month = months_short.indexOf(match[2].toLowerCase()) + 1;
232
+ return new Date(`${date.getFullYear()}-${self.leading_zero(month)}-${match[1]}`);
233
+ }
234
+
235
+ //pretty format with year: 23 Oct 2024
236
+ match = str.match(/(\d{2}) (\w{3}) (\d{4})/i);
237
+ if ( match && match.length == 4 ) {
238
+ let month = months_short.indexOf(months_short[match[2].toLowerCase()]) + 1;
239
+ return new Date(`${match[3]}-${self.leading_zero(month)}-${match[1]}`);
240
+ }
241
+
242
+ //today
243
+ if ( str.match(/^today$/i) ) {
244
+ return new Date();
245
+ }
246
+
247
+ //yesterday
248
+ if ( str.match(/^yesterday$/i) ) {
249
+ let date = new Date();
250
+ return date.setDate(date.getDate() - 1);
251
+ }
252
+
253
+ return new Date(str);
254
+ },
255
+
256
+ prettify_date(date) {
257
+ if ( !date ) {
258
+ return 'Never';
259
+ }
260
+
261
+ let mysql_date = date;
262
+ if ( typeof date == 'string' ) {
263
+ date = new Date(date);
264
+ }
265
+ else {
266
+ mysql_date = self.mysql_date(date);
267
+ }
268
+
269
+ if ( isNaN(date) ) {
270
+ return 'Invalid Date';
271
+ }
272
+
273
+ //check if is today
274
+ let today = new Date();
275
+ if ( self.mysql_date(today) == mysql_date ) {
276
+ return 'Today';
277
+ }
278
+
279
+ //check if is yesterday
280
+ today.setDate(-1);
281
+ if ( self.mysql_date(today) == mysql_date ) {
282
+ return 'Yesterday';
283
+ }
284
+
285
+ //check if is current year then don't display it
286
+ if ( new Date(date).getFullYear() == today.getFullYear() ) {
287
+ return `${self.leading_zero(date.getDate())} ${date.toLocaleString('default', { month: 'short' })}`;
288
+ }
289
+
290
+ return `${self.leading_zero(date.getDate())} ${date.toLocaleString('default', { month: 'short' })} ${date.getFullYear()}`;
291
+ },
292
+
293
+ prettify_datetime(date) {
294
+ const options = {};
295
+ const parsed_date = new Date(new Date(date + 'Z').toLocaleString('en-US', options)); // Add 'Z' for UTC handling
296
+ const now = new Date();
297
+
298
+ if (parsed_date.getFullYear() === now.getFullYear()) {
299
+ return parsed_date.toLocaleDateString('en-US', {
300
+ day: '2-digit',
301
+ month: 'short',
302
+ hour: '2-digit',
303
+ minute: '2-digit',
304
+ hour12: false,
305
+ }).replace(',', ' @');
306
+ }
307
+
308
+ return parsed_date.toLocaleDateString('en-US', {
309
+ day: '2-digit',
310
+ month: 'short',
311
+ year: 'numeric',
312
+ hour: '2-digit',
313
+ minute: '2-digit',
314
+ hour12: false,
315
+ }).replace(',', ' @');
316
+ },
317
+
318
+ prettify_time(date) {
319
+ const options = {};
320
+ const parsed_date = new Date(new Date(date + 'Z').toLocaleString('en-US', options)); // Add 'Z' for UTC handling
321
+
322
+ return parsed_date.toLocaleTimeString('en-US', {
323
+ hour: '2-digit',
324
+ minute: '2-digit',
325
+ hour12: false,
326
+ });
327
+ },
328
+
329
+ mysql_date(date = null) {
330
+ if ( !date ) {
331
+ date = new Date();
332
+ }
333
+
334
+ let month = date.getMonth() + 1;
335
+ let day = date.getDate();
336
+ return `${date.getFullYear()}-${self.leading_zero(month)}-${self.leading_zero(day)}`;
337
+ },
207
338
  }
208
339
 
209
340
  export default self;