@radiantabyss/vue 3.3.20 → 4.0.1

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,382 +0,0 @@
1
- let self = {
2
- /*helpers from https://github.com/validatorjs/validator.js*/
3
- ltrim(str, chars) {
4
- const pattern = chars ? new RegExp(`^[${chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}]+`, 'g') : /^\s+/g;
5
- return `${str}`.replace(pattern, '');
6
- },
7
-
8
- rtrim(str, chars) {
9
- const pattern = chars ? new RegExp(`[${chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}]+$`, 'g') : /(\s)+$/g;
10
- return `${str}`.replace(pattern, '');
11
- },
12
-
13
- trim(str, chars) {
14
- return self.rtrim(self.ltrim(`${str}`, chars), chars);
15
- },
16
- /*end helpers from https://github.com/validatorjs/validator.js*/
17
-
18
- urlencode(str) {
19
- return encodeURIComponent(str);
20
- },
21
-
22
- random(length) {
23
- const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
24
- let result = "";
25
- for ( let i = 0; i < length; i++ ) {
26
- result += chars.charAt(Math.floor(Math.random() * chars.length));
27
- }
28
- return result;
29
- },
30
-
31
- slug(str) {
32
- str = str.replace(/^\s+|\s+$/g, ''); // trim
33
- str = str.toLowerCase();
34
-
35
- // remove accents, swap ñ for n, etc
36
- var from = "àáãäâèéëêìíïîòóöôùúüûñç·/_,:;";
37
- var to = "aaaaaeeeeiiiioooouuuunc------";
38
-
39
- for (var i=0, l=from.length ; i<l ; i++) {
40
- str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
41
- }
42
-
43
- str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
44
- .replace(/\s+/g, '-') // collapse whitespace and replace by -
45
- .replace(/-+/g, '-'); // collapse dashes
46
-
47
- return str;
48
- },
49
-
50
- dash(str) {
51
- return str.split('').map((letter, idx) => {
52
- return letter.toUpperCase() === letter
53
- ? `${idx !== 0 ? '-' : ''}${letter.toLowerCase()}`
54
- : letter;
55
- }).join('');
56
- },
57
-
58
- snake(string) {
59
- return string
60
- .replace(/\s+(?=\d)/g, '')
61
- .replace(/\s+/g, '_')
62
- .replace(/([a-z])([A-Z])/g, '$1_$2')
63
- .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
64
- .toLowerCase();
65
- },
66
-
67
- camel(str) {
68
- return str.replace(/-/g, ' ').replace(/_/g, ' ').replace(/(^([a-zA-Z\p{M}]))|([ -][a-zA-Z\p{M}])/g,function(s) {
69
- return s.toUpperCase();
70
- }).replace(/\s+/g, '');
71
- },
72
-
73
- pascal(str) {
74
- return `${str}`
75
- .toLowerCase()
76
- .replace(new RegExp(/[-_]+/, 'g'), ' ')
77
- .replace(new RegExp(/[^\w\s]/, 'g'), '')
78
- .replace(new RegExp(/\s+(.)(\w*)/, 'g'), ($1, $2, $3) => `${$2.toUpperCase() + $3}`)
79
- .replace(new RegExp(/\w/), s => s.toUpperCase());
80
- },
81
-
82
- kebab(str) {
83
- return `${str}`.replace(/([a-z])([A-Z])/g, "$1-$2")
84
- .replace(/[\s_]+/g, '-')
85
- .toLowerCase();
86
- },
87
-
88
- camel2space(str) {
89
- if ( !str ) {
90
- return '';
91
- }
92
-
93
- return str.split('').map((letter, idx) => {
94
- return letter.toUpperCase() === letter
95
- ? `${idx !== 0 ? ' ' : ''}${letter}`
96
- : letter;
97
- }).join('');
98
- },
99
-
100
- ucfirst(string) {
101
- return string.charAt(0).toUpperCase() + string.slice(1);
102
- },
103
-
104
- ucwords(str) {
105
- if ( !str ) {
106
- str = '';
107
- }
108
-
109
- //ensure string
110
- str = str + '';
111
-
112
- return str.replace(/-/g, ' ').replace(/_/g, ' ').replace(/(^([a-zA-Z\p{M}]))|([ -][a-zA-Z\p{M}])/g,function(s) {
113
- return s.toUpperCase();
114
- });
115
- },
116
-
117
- ordinal_suffix(i) {
118
- var j = i % 10,
119
- k = i % 100;
120
- if (j == 1 && k != 11) {
121
- return i + "st";
122
- }
123
- if (j == 2 && k != 12) {
124
- return i + "nd";
125
- }
126
- if (j == 3 && k != 13) {
127
- return i + "rd";
128
- }
129
-
130
- return i + "th";
131
- },
132
-
133
- number_to_month(number) {
134
- let months = {
135
- 1: 'January',
136
- 2: 'February',
137
- 3: 'March',
138
- 4: 'April',
139
- 5: 'May',
140
- 6: 'June',
141
- 7: 'July',
142
- 8: 'August',
143
- 9: 'September',
144
- 10: 'October',
145
- 11: 'November',
146
- 12: 'December',
147
- };
148
-
149
- return months[`${number}`.replace(/^0/, '')];
150
- },
151
-
152
- nl2br(str) {
153
- if ( !str || !str.length ) {
154
- return '';
155
- }
156
-
157
- return str.replace(/(\r\n|\n\r|\r|\n)/g, '<br/>' + '$1');
158
- },
159
-
160
- strip_tags(str) {
161
- var div = document.createElement("div");
162
- div.innerHTML = str;
163
- var text = div.textContent || div.innerText || "";
164
- return text;
165
- },
166
-
167
- ensure_https(string) {
168
- if (!string.match(/^[a-zA-Z]+:\/\//)) {
169
- string = 'https://' + string;
170
- }
171
-
172
- return string;
173
- },
174
-
175
- add_commas(number) {
176
- if ( number === undefined || number === null ) {
177
- return '';
178
- }
179
-
180
- number = parseFloat(number).toFixed(2).toLocaleString('en-US');
181
-
182
- return number;
183
- },
184
-
185
- leading_zero(number) {
186
- number = parseInt(number);
187
- return number < 10 ? `0${number}` : number;
188
- },
189
-
190
- to_percetange(number) {
191
- if ( number === undefined || !number ) {
192
- return '0%';
193
- }
194
-
195
- return (number / 10)+'%';
196
- },
197
-
198
- plural(str) {
199
- if ( str.match(/y$/) ) {
200
- return str.replace(/y$/, 'ies');
201
- }
202
-
203
- if ( str.match(/s$/) ) {
204
- return `${str}es`;
205
- }
206
-
207
- return `${str}s`;
208
- },
209
-
210
- truncate(str, length) {
211
- if (str.length > length) {
212
- return str.slice(0, length) + '...';
213
- }
214
-
215
- return str;
216
- },
217
-
218
- string_to_date(str) {
219
- let match;
220
- let months_short = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];
221
-
222
- //trim spaces
223
- str = str.trim();
224
-
225
- //dash format: 23-10-2024
226
- match = str.match(/(\d{2})-(\d{2})-(\d{4})/);
227
- if ( match && match.length == 4 ) {
228
- return new Date(`${match[3]}-${match[2]}-${match[1]}`);
229
- }
230
-
231
- //dot format: 23.10.2024
232
- match = str.match(/(\d{2})\.(\d{2})\.(\d{4})/);
233
- if ( match && match.length == 4 ) {
234
- return new Date(`${match[3]}-${match[2]}-${match[1]}`);
235
- }
236
-
237
- //pretty format: 23 Oct
238
- match = str.match(/(\d{2}) (\w{3})/i);
239
- if ( match && match.length == 3 ) {
240
- let date = new Date();
241
- let month = months_short.indexOf(match[2].toLowerCase()) + 1;
242
- return new Date(`${date.getFullYear()}-${self.leading_zero(month)}-${match[1]}`);
243
- }
244
-
245
- //pretty format with year: 23 Oct 2024
246
- match = str.match(/(\d{2}) (\w{3}) (\d{4})/i);
247
- if ( match && match.length == 4 ) {
248
- let month = months_short.indexOf(months_short[match[2].toLowerCase()]) + 1;
249
- return new Date(`${match[3]}-${self.leading_zero(month)}-${match[1]}`);
250
- }
251
-
252
- //today
253
- if ( str.match(/^today$/i) ) {
254
- return new Date();
255
- }
256
-
257
- //yesterday
258
- if ( str.match(/^yesterday$/i) ) {
259
- let date = new Date();
260
- return date.setDate(date.getDate() - 1);
261
- }
262
-
263
- return new Date(str);
264
- },
265
-
266
- pretty_date(date) {
267
- if ( !date ) {
268
- return 'Never';
269
- }
270
-
271
- let mysql_date = date;
272
- if ( typeof date == 'string' ) {
273
- date = new Date(date);
274
- }
275
- else {
276
- mysql_date = self.mysql_date(date);
277
- }
278
-
279
- if ( isNaN(date) ) {
280
- return 'Invalid Date';
281
- }
282
-
283
- //check if is today
284
- let today = new Date();
285
- if ( self.mysql_date(today) == mysql_date ) {
286
- return 'Today';
287
- }
288
-
289
- //check if is yesterday
290
- today.setDate(today.getDate() - 1);
291
- if ( self.mysql_date(today) == mysql_date ) {
292
- return 'Yesterday';
293
- }
294
-
295
- //check if is current year then don't display it
296
- if ( new Date(date).getFullYear() == new Date().getFullYear() ) {
297
- return `${self.leading_zero(date.getDate())} ${date.toLocaleString('default', { month: 'short' })}`;
298
- }
299
-
300
- return `${self.leading_zero(date.getDate())} ${date.toLocaleString('default', { month: 'short' })} ${date.getFullYear()}`;
301
- },
302
-
303
- pretty_datetime(date) {
304
- const options = {};
305
- const parsed_date = new Date(new Date(date + 'Z').toLocaleString('en-US', options)); // Add 'Z' for UTC handling
306
- const now = new Date();
307
-
308
- if (parsed_date.getFullYear() === now.getFullYear()) {
309
- return parsed_date.toLocaleDateString('en-US', {
310
- day: '2-digit',
311
- month: 'short',
312
- hour: '2-digit',
313
- minute: '2-digit',
314
- hour12: false,
315
- }).replace(',', ' @');
316
- }
317
-
318
- return parsed_date.toLocaleDateString('en-US', {
319
- day: '2-digit',
320
- month: 'short',
321
- year: 'numeric',
322
- hour: '2-digit',
323
- minute: '2-digit',
324
- hour12: false,
325
- }).replace(',', ' @');
326
- },
327
-
328
- pretty_time(date) {
329
- const options = {};
330
- const parsed_date = new Date(new Date(date + 'Z').toLocaleString('en-US', options)); // Add 'Z' for UTC handling
331
-
332
- return parsed_date.toLocaleTimeString('en-US', {
333
- hour: '2-digit',
334
- minute: '2-digit',
335
- hour12: false,
336
- });
337
- },
338
-
339
- mysql_date(date = null) {
340
- if ( !date ) {
341
- date = new Date();
342
- }
343
-
344
- let month = date.getMonth() + 1;
345
- let day = date.getDate();
346
- return `${date.getFullYear()}-${self.leading_zero(month)}-${self.leading_zero(day)}`;
347
- },
348
-
349
- mask(str) {
350
- if ( !str.length ) {
351
- return;
352
- }
353
-
354
- let visible_chars_left = 0;
355
- let visible_chars_right = 0;
356
-
357
- if ( str.length > 6 ) {
358
- visible_chars_left = 2;
359
- }
360
-
361
- if ( str.length > 10 ) {
362
- visible_chars_right = 2;
363
- }
364
- if ( str.length > 20 ) {
365
- visible_chars_left = 3;
366
- visible_chars_left = 3;
367
- }
368
-
369
- let bullet_count = str.length - visible_chars_left - visible_chars_right;
370
- if ( bullet_count < 0 ) {
371
- bullet_count = str.length;
372
- }
373
-
374
- if ( bullet_count > 10 ) {
375
- bullet_count = 10;
376
- }
377
-
378
- return str.substring(0, visible_chars_left) + '⁕'.repeat(bullet_count) + str.substring(str.length - visible_chars_right);
379
- },
380
- }
381
-
382
- export default self;