@radiantabyss/vue 3.0.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.
@@ -0,0 +1,209 @@
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
+ slug(str) {
23
+ str = str.replace(/^\s+|\s+$/g, ''); // trim
24
+ str = str.toLowerCase();
25
+
26
+ // remove accents, swap ñ for n, etc
27
+ var from = "àáãäâèéëêìíïîòóöôùúüûñç·/_,:;";
28
+ var to = "aaaaaeeeeiiiioooouuuunc------";
29
+
30
+ for (var i=0, l=from.length ; i<l ; i++) {
31
+ str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
32
+ }
33
+
34
+ str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
35
+ .replace(/\s+/g, '-') // collapse whitespace and replace by -
36
+ .replace(/-+/g, '-'); // collapse dashes
37
+
38
+ return str;
39
+ },
40
+
41
+ dash(str) {
42
+ return str.split('').map((letter, idx) => {
43
+ return letter.toUpperCase() === letter
44
+ ? `${idx !== 0 ? '-' : ''}${letter.toLowerCase()}`
45
+ : letter;
46
+ }).join('');
47
+ },
48
+
49
+ snake(string) {
50
+ return string
51
+ .replace(/\s+(?=\d)/g, '')
52
+ .replace(/\s+/g, '_')
53
+ .replace(/([a-z])([A-Z])/g, '$1_$2')
54
+ .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
55
+ .toLowerCase();
56
+ },
57
+
58
+ camel(str) {
59
+ return str.replace(/-/g, ' ').replace(/_/g, ' ').replace(/(^([a-zA-Z\p{M}]))|([ -][a-zA-Z\p{M}])/g,function(s) {
60
+ return s.toUpperCase();
61
+ }).replace(/\s+/g, '');
62
+ },
63
+
64
+ pascal(str) {
65
+ return `${str}`
66
+ .toLowerCase()
67
+ .replace(new RegExp(/[-_]+/, 'g'), ' ')
68
+ .replace(new RegExp(/[^\w\s]/, 'g'), '')
69
+ .replace(new RegExp(/\s+(.)(\w*)/, 'g'), ($1, $2, $3) => `${$2.toUpperCase() + $3}`)
70
+ .replace(new RegExp(/\w/), s => s.toUpperCase());
71
+ },
72
+
73
+ kebab(str) {
74
+ return `${str}`.replace(/([a-z])([A-Z])/g, "$1-$2")
75
+ .replace(/[\s_]+/g, '-')
76
+ .toLowerCase();
77
+ },
78
+
79
+ camel2space(str) {
80
+ if ( !str ) {
81
+ return '';
82
+ }
83
+
84
+ return str.split('').map((letter, idx) => {
85
+ return letter.toUpperCase() === letter
86
+ ? `${idx !== 0 ? ' ' : ''}${letter}`
87
+ : letter;
88
+ }).join('');
89
+ },
90
+
91
+ ucfirst(string) {
92
+ return string.charAt(0).toUpperCase() + string.slice(1);
93
+ },
94
+
95
+ ucwords(str) {
96
+ if ( !str ) {
97
+ str = '';
98
+ }
99
+
100
+ //ensure string
101
+ str = str + '';
102
+
103
+ return str.replace(/-/g, ' ').replace(/_/g, ' ').replace(/(^([a-zA-Z\p{M}]))|([ -][a-zA-Z\p{M}])/g,function(s) {
104
+ return s.toUpperCase();
105
+ });
106
+ },
107
+
108
+ ordinal_suffix(i) {
109
+ var j = i % 10,
110
+ k = i % 100;
111
+ if (j == 1 && k != 11) {
112
+ return i + "st";
113
+ }
114
+ if (j == 2 && k != 12) {
115
+ return i + "nd";
116
+ }
117
+ if (j == 3 && k != 13) {
118
+ return i + "rd";
119
+ }
120
+
121
+ return i + "th";
122
+ },
123
+
124
+ number_to_month(number) {
125
+ let months = {
126
+ 1: 'January',
127
+ 2: 'February',
128
+ 3: 'March',
129
+ 4: 'April',
130
+ 5: 'May',
131
+ 6: 'June',
132
+ 7: 'July',
133
+ 8: 'August',
134
+ 9: 'September',
135
+ 10: 'October',
136
+ 11: 'November',
137
+ 12: 'December',
138
+ };
139
+
140
+ return months[`${number}`.replace(/^0/, '')];
141
+ },
142
+
143
+ nl2br(str) {
144
+ if ( !str || !str.length ) {
145
+ return '';
146
+ }
147
+
148
+ return str.replace(/(\r\n|\n\r|\r|\n)/g, '<br/>' + '$1');
149
+ },
150
+
151
+ strip_tags(str) {
152
+ var div = document.createElement("div");
153
+ div.innerHTML = str;
154
+ var text = div.textContent || div.innerText || "";
155
+ return text;
156
+ },
157
+
158
+ ensure_https(string) {
159
+ if (!string.match(/^[a-zA-Z]+:\/\//)) {
160
+ string = 'https://' + string;
161
+ }
162
+
163
+ return string;
164
+ },
165
+
166
+ add_commas(number) {
167
+ if ( number === undefined || number === null ) {
168
+ return '';
169
+ }
170
+
171
+ number = parseFloat(number).toFixed(2).toLocaleString('en-US');
172
+
173
+ return number;
174
+ },
175
+
176
+ leading_zero(number) {
177
+ return number < 10 ? `0${number}` : number;
178
+ },
179
+
180
+ to_percetange(number) {
181
+ if ( number === undefined || !number ) {
182
+ return '0%';
183
+ }
184
+
185
+ return (number / 10)+'%';
186
+ },
187
+
188
+ plural(str) {
189
+ if ( str.match(/y$/) ) {
190
+ return str.replace(/y$/, 'ies');
191
+ }
192
+
193
+ if ( str.match(/s$/) ) {
194
+ return `${str}es`;
195
+ }
196
+
197
+ return `${str}s`;
198
+ },
199
+
200
+ truncate(str, length) {
201
+ if (str.length > length) {
202
+ return str.slice(0, length) + '...';
203
+ }
204
+
205
+ return str;
206
+ },
207
+ }
208
+
209
+ export default self;
@@ -0,0 +1,16 @@
1
+ let self = {
2
+ error(messages) {
3
+ return {
4
+ success: false,
5
+ messages,
6
+ }
7
+ },
8
+
9
+ success() {
10
+ return {
11
+ success: true
12
+ }
13
+ }
14
+ }
15
+
16
+ export default self;
@@ -0,0 +1,27 @@
1
+ import * as ValidatorJS from 'validatorjs';
2
+
3
+ let self = {
4
+ make(data, rules, messages) {
5
+ //format messages
6
+ let formatted_messages = {};
7
+ for ( let key in messages ) {
8
+ let split = key.split('.');
9
+ let pop = Array.from(split);
10
+ pop.pop();
11
+ formatted_messages[`${split[split.length - 1]}.${pop.join('.')}`] = messages[key];
12
+ }
13
+
14
+ let validator = new ValidatorJS(data, rules, formatted_messages);
15
+
16
+ return {
17
+ passes() {
18
+ return validator.passes();
19
+ },
20
+ messages() {
21
+ return Object.values(validator.errors.all());
22
+ },
23
+ };
24
+ }
25
+ }
26
+
27
+ export default self;