@inriver/inri 1.13.0 → 1.15.0
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/.changeset/README.md +8 -0
- package/.changeset/config.json +11 -0
- package/.eslintrc.js +5 -5
- package/azure/pipelines/single-build-release.yml +6 -0
- package/azure/pipelines/templates/deployFramework.yml +50 -0
- package/componentProperties.d.ts +8 -8
- package/configs/base-eslint-config.js +36 -36
- package/configs/base-tailwind-config.js +149 -149
- package/i18n.ts +11 -11
- package/index.ts +29 -29
- package/package.json +7 -2
- package/src/components/CAutoBreadcrumbs.vue +72 -72
- package/src/components/CBtn.vue +98 -98
- package/src/components/CColorPicker.vue +55 -55
- package/src/components/CContextMenu.vue +29 -29
- package/src/components/CDatePicker.vue +51 -51
- package/src/components/CDeleteTileBtn.vue +52 -52
- package/src/components/CDialog.vue +253 -253
- package/src/components/CDialogCloseBtn.vue +9 -9
- package/src/components/CDirtyCheck.vue +68 -68
- package/src/components/CDrawer.vue +44 -44
- package/src/components/CDrawerButton.vue +91 -91
- package/src/components/CExpansionItem.vue +57 -57
- package/src/components/CExpansionItemWithCheckbox.vue +41 -41
- package/src/components/CFileDropzone.vue +114 -114
- package/src/components/CGrid.vue +101 -101
- package/src/components/CHeader.vue +10 -10
- package/src/components/CHeaderLinks.vue +61 -61
- package/src/components/CHeaderMenuLink.vue +51 -51
- package/src/components/CHeaderSearch.vue +142 -142
- package/src/components/CIconBtn.vue +70 -70
- package/src/components/CMenuItem.vue +66 -66
- package/src/components/CPageContainer.vue +11 -11
- package/src/components/CPageError.vue +24 -24
- package/src/components/CPageSpinner.vue +18 -18
- package/src/components/CSearch.vue +45 -45
- package/src/components/CSection.vue +29 -29
- package/src/components/CSectionTitle.vue +8 -8
- package/src/components/CSelect.vue +208 -208
- package/src/components/CSlideEffect.vue +62 -62
- package/src/components/CSpinner.vue +107 -107
- package/src/components/CTableActions.vue +16 -16
- package/src/components/CTileBtn.vue +178 -178
- package/src/components/CTimePicker.vue +42 -42
- package/src/components/CToggleGridView.vue +26 -26
- package/src/components/CToggleSidebarBtn.vue +19 -19
- package/src/components/CTooltip.vue +44 -44
- package/src/components/CTreeNode.vue +39 -39
- package/src/components/cards/CBannerCard.vue +103 -103
- package/src/components/cards/CSmallCard.vue +149 -149
- package/src/components/internal-components/ConfirmDialog.vue +78 -78
- package/src/composables/useDialog.ts +46 -46
- package/src/composables/useDirtyCheck.ts +25 -25
- package/src/composables/useDoubleClickListener.ts +28 -28
- package/src/composables/useSelectable.ts +62 -62
- package/src/composables/useTruncateChips.ts +46 -46
- package/src/i18n/de/index.ts +17 -17
- package/src/i18n/en/index.ts +84 -84
- package/src/i18n/es/index.ts +7 -7
- package/src/i18n/fr/index.ts +7 -7
- package/src/init/initInriFramework.ts +37 -37
- package/src/init/useInriApp.ts +55 -55
- package/src/layouts/CLayoutBlank.vue +7 -7
- package/src/layouts/CLayoutWithBackButton.vue +50 -50
- package/src/layouts/CLayoutWithSidebars.vue +46 -46
- package/src/layouts/layout-fragments/CPageAutoBreadcrumbs.vue +6 -6
- package/src/layouts/layout-fragments/CPageBackButton.vue +18 -18
- package/src/layouts/layout-fragments/CPageBlank.vue +20 -20
- package/src/layouts/layout-fragments/CPageFlexCol.vue +5 -5
- package/src/layouts/layout-fragments/CPageLeftSidebar.vue +5 -5
- package/src/layouts/layout-fragments/CPageMainContent.vue +5 -5
- package/src/layouts/layout-fragments/CPageOuterWrapper.vue +5 -5
- package/src/layouts/layout-fragments/CPageRightSidebar.vue +5 -5
- package/src/layouts/layout-fragments/CPageTitle.vue +34 -34
- package/src/plugins/dialog.ts +45 -45
- package/src/plugins/errors/ErrorFactories.ts +59 -59
- package/src/plugins/errors/Errors.ts +156 -156
- package/src/plugins/errors/Exception.ts +6 -6
- package/src/plugins/errors/globalErrorHandler.ts +21 -21
- package/src/plugins/errors/handleError.ts +34 -34
- package/src/plugins/errors/logger.ts +16 -16
- package/src/plugins/errors/vueErrorHandler.ts +26 -26
- package/src/plugins/globalAppConfig.ts +25 -25
- package/src/plugins/i18n.ts +46 -46
- package/src/plugins/inriIcons.ts +58 -58
- package/src/plugins/inriverQuasarComponentConfigurations.ts +67 -67
- package/src/plugins/library.ts +119 -119
- package/src/plugins/notify.ts +153 -153
- package/src/plugins/quasar-user-options.ts +19 -19
- package/src/plugins/validationRules.ts +292 -292
- package/src/shims-vue.d.ts +6 -6
- package/src/stores/inriStore.ts +54 -54
- package/src/stores/interfaceLanguageStore.ts +27 -27
- package/src/styles/_css-variables.scss +101 -101
- package/src/styles/_reset.scss +67 -67
- package/src/styles/_transitions.scss +9 -9
- package/src/styles/_utils.scss +15 -15
- package/src/styles/components/_breadcrumbs.scss +3 -3
- package/src/styles/components/_checkboxes.scss +17 -17
- package/src/styles/components/_chips.scss +17 -17
- package/src/styles/components/_forms.scss +203 -203
- package/src/styles/components/_menu.scss +12 -12
- package/src/styles/components/_notifications.scss +24 -24
- package/src/styles/components/_q-editor.scss +14 -14
- package/src/styles/components/_radio-buttons.scss +17 -17
- package/src/styles/components/_tables.scss +92 -92
- package/src/styles/components/_tooltips.scss +5 -5
- package/src/styles/components/_tree.scss +86 -86
- package/src/styles/components/_truncated-chips.scss +39 -39
- package/src/styles/main.scss +45 -45
- package/src/styles/quasar.variables.scss +50 -50
- package/src/styles/tailwind/index.css +2 -2
- package/src/typings.d.ts +70 -70
- package/src/utils/colorUtils.ts +73 -73
- package/src/utils/errorUtils.ts +37 -37
- package/src/utils/fileUtils.ts +57 -57
- package/src/utils/helpers.ts +6 -6
- package/src/utils/routeUtils.ts +23 -23
- package/tsconfig.json +34 -34
|
@@ -1,292 +1,292 @@
|
|
|
1
|
-
import { i18n } from './i18n'
|
|
2
|
-
|
|
3
|
-
const $t = i18n.global.t
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* The value is required.
|
|
7
|
-
* @param {string} [msg] - Override the default error message
|
|
8
|
-
*/
|
|
9
|
-
export function required (msg?: string) {
|
|
10
|
-
return (value): true | string => {
|
|
11
|
-
return !!value || msg || $t('inri.validation.required')
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* The value must have a minimum length.
|
|
17
|
-
* @param {string | number} length - Min length
|
|
18
|
-
* @param {string} [msg] - Override the default error message
|
|
19
|
-
*/
|
|
20
|
-
export function minLength (length: string | number, msg?: string) {
|
|
21
|
-
const parsedLength = typeof length === 'number' ? length : parseInt(length, 10)
|
|
22
|
-
return (value): true | string => {
|
|
23
|
-
if (!value) {
|
|
24
|
-
return true
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return value.length >= parsedLength || msg || $t('inri.validation.minLength', { parsedLength: parsedLength })
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* The value can not exceed maximum length.
|
|
33
|
-
* @param {string | number} length - Max length
|
|
34
|
-
* @param {string} [msg] - Override the default error message
|
|
35
|
-
*/
|
|
36
|
-
export function maxLength (length: string | number, msg?: string) {
|
|
37
|
-
const parsedLength = typeof length === 'number' ? length : parseInt(length, 10)
|
|
38
|
-
return (value): true | string => {
|
|
39
|
-
if (!value) {
|
|
40
|
-
return true
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return value.length <= parsedLength || msg || $t('inri.validation.maxLength', { parsedLength: parsedLength })
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* The value must be a valid email.
|
|
49
|
-
* @param {string} [msg] - Override the default error message
|
|
50
|
-
*/
|
|
51
|
-
export function email (msg?: string) {
|
|
52
|
-
// eslint-disable-next-line no-useless-escape
|
|
53
|
-
const regExp = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
|
54
|
-
return (value): true | string => {
|
|
55
|
-
if (!value) {
|
|
56
|
-
return true
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return regExp.test(String(value).toLowerCase()) || msg || $t('inri.validation.email')
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* The value must be a valid url.
|
|
65
|
-
* @param {string} [msg] - Override the default error message
|
|
66
|
-
*/
|
|
67
|
-
export function url (msg?: string) {
|
|
68
|
-
// eslint-disable-next-line no-useless-escape
|
|
69
|
-
const regExp = /^(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*))$/
|
|
70
|
-
return (value): true | string => {
|
|
71
|
-
if (!value) {
|
|
72
|
-
return true
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return regExp.test(String(value).toLowerCase()) || msg || $t('inri.validation.url')
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* The value must be a valid url using https.
|
|
81
|
-
* @param {string} [msg] - Override the default error message
|
|
82
|
-
*/
|
|
83
|
-
export function https (msg?: string) {
|
|
84
|
-
// eslint-disable-next-line no-useless-escape
|
|
85
|
-
const regExp = /^(https:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*))$/
|
|
86
|
-
return (value): true | string => {
|
|
87
|
-
if (!value) {
|
|
88
|
-
return true
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return regExp.test(String(value).toLowerCase()) || msg || $t('inri.validation.https')
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Validate file extensions. Supports single and multiple files.
|
|
97
|
-
* @param {string} fileExtensions - A string containing a single file extension, "jpg", or a comma separated string, "jpg,png".
|
|
98
|
-
* @param {string} [msg] - Override the default error message
|
|
99
|
-
*/
|
|
100
|
-
export function extension (fileExtensions: string, msg?: string) {
|
|
101
|
-
// Extension string cleanup and convert to array
|
|
102
|
-
const extensions = fileExtensions
|
|
103
|
-
.toLowerCase()
|
|
104
|
-
.replaceAll(' ', '')
|
|
105
|
-
.replaceAll('.', '')
|
|
106
|
-
.split(',')
|
|
107
|
-
|
|
108
|
-
return (value): true | string => {
|
|
109
|
-
if (!value) {
|
|
110
|
-
return true
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
let files: any[] = []
|
|
114
|
-
let isValid = true
|
|
115
|
-
|
|
116
|
-
// If single file then push it into an array for consistency
|
|
117
|
-
if (!value.length) {
|
|
118
|
-
files.push(value)
|
|
119
|
-
} else {
|
|
120
|
-
files = value
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
for (const file of files) {
|
|
124
|
-
const fileExt = file.name.substring(file.name.lastIndexOf('.') + 1).toLowerCase()
|
|
125
|
-
if (!extensions.includes(fileExt)) {
|
|
126
|
-
isValid = false
|
|
127
|
-
break
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return isValid || msg || $t('inri.validation.extension', { extensions: extensions.join(', .') })
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* The value must contain all the strings in the array.
|
|
137
|
-
* @param {string[]} arr - Array of strings.
|
|
138
|
-
* @param {boolean} caseSensitive
|
|
139
|
-
* @param {string} [msg] - Override the default error message
|
|
140
|
-
*/
|
|
141
|
-
export function contains (arr: string[], caseSensitive = false, msg?: string) {
|
|
142
|
-
return (value): true | string => {
|
|
143
|
-
if (!value) {
|
|
144
|
-
return true
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
let foundItems
|
|
148
|
-
|
|
149
|
-
if (!caseSensitive) {
|
|
150
|
-
foundItems = arr.filter(item => !value.toUpperCase().includes(('' + item).toUpperCase()))
|
|
151
|
-
} else {
|
|
152
|
-
foundItems = arr.filter(item => !value.includes('' + item))
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
if (!foundItems.length) {
|
|
156
|
-
return true
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return msg || $t('inri.validation.contains', { match: foundItems.join(', ') })
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* The value must not contain any of the strings in the array.
|
|
165
|
-
* @param {string[]} arr - Array of strings.
|
|
166
|
-
* @param {boolean} caseSensitive
|
|
167
|
-
* @param {string} [msg] - Override the default error message
|
|
168
|
-
*/
|
|
169
|
-
export function notContains (arr: string[], caseSensitive = false, msg?: string) {
|
|
170
|
-
return (value): true | string => {
|
|
171
|
-
if (!value) {
|
|
172
|
-
return true
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const comparisonValue = value instanceof File ? value.name : value
|
|
176
|
-
|
|
177
|
-
let foundItems
|
|
178
|
-
|
|
179
|
-
if (!caseSensitive) {
|
|
180
|
-
foundItems = arr.filter(item => comparisonValue.toUpperCase().includes(('' + item).toUpperCase()))
|
|
181
|
-
} else {
|
|
182
|
-
foundItems = arr.filter(item => comparisonValue.includes('' + item))
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (!foundItems.length) {
|
|
186
|
-
return true
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
return msg || $t('inri.validation.notContains', { match: foundItems.join(', ') })
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* The value must not begin with any of the strings in the array.
|
|
195
|
-
* @param {string[]} arr - Array of strings.
|
|
196
|
-
* @param {boolean} caseSensitive
|
|
197
|
-
* @param {string} [msg] - Override the default error message
|
|
198
|
-
*/
|
|
199
|
-
export function notBeginsWith (arr: string[], caseSensitive = false, msg?: string) {
|
|
200
|
-
return (value): true | string => {
|
|
201
|
-
if (!value) {
|
|
202
|
-
return true
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
let foundItems
|
|
206
|
-
|
|
207
|
-
if (!caseSensitive) {
|
|
208
|
-
foundItems = arr.filter(item => value.toUpperCase().startsWith(('' + item).toUpperCase()))
|
|
209
|
-
} else {
|
|
210
|
-
foundItems = arr.filter(item => value.startsWith('' + item))
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
if (!foundItems.length) {
|
|
214
|
-
return true
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
return msg || $t('inri.validation.notBeginsWith', { match: foundItems.join(', ') })
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* The value must not end with any of the strings in the array.
|
|
223
|
-
* @param {string[]} arr - Array of strings.
|
|
224
|
-
* @param {boolean} caseSensitive
|
|
225
|
-
* @param {string} [msg] - Override the default error message
|
|
226
|
-
*/
|
|
227
|
-
export function notEndsWith (arr: string[], caseSensitive = false, msg?: string) {
|
|
228
|
-
return (value): true | string => {
|
|
229
|
-
if (!value) {
|
|
230
|
-
return true
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
let foundItems
|
|
234
|
-
|
|
235
|
-
if (!caseSensitive) {
|
|
236
|
-
foundItems = arr.filter(item => value.toUpperCase().endsWith(('' + item).toUpperCase()))
|
|
237
|
-
} else {
|
|
238
|
-
foundItems = arr.filter(item => value.endsWith('' + item))
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
if (!foundItems.length) {
|
|
242
|
-
return true
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
return msg || $t('inri.validation.notEndsWith', { match: foundItems.join(', ') })
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* The file(s) cannot exceed max size
|
|
251
|
-
* @param {string | number} size - Max size in bytes
|
|
252
|
-
* @param {string} [type] - Only validate against files with this MIME type
|
|
253
|
-
* @param {string} [msg] - Override the default error message
|
|
254
|
-
*/
|
|
255
|
-
export function maxFileSize (size: string | number, type?: string, msg?: string) {
|
|
256
|
-
const parsedFileSize = typeof size === 'number' ? size : parseInt(size, 10)
|
|
257
|
-
|
|
258
|
-
return (value): true | string => {
|
|
259
|
-
if (!value) {
|
|
260
|
-
return true
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
let files: any[] = []
|
|
264
|
-
|
|
265
|
-
if (!value.length) {
|
|
266
|
-
files.push(value)
|
|
267
|
-
} else {
|
|
268
|
-
files = value
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
if (type) {
|
|
272
|
-
files = files.filter(file => file.type.includes(type))
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
return files.every(file => file.size <= size) || msg || $t('inri.validation.maxFileSize', { parsedFileSize })
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
export const rules = {
|
|
280
|
-
required,
|
|
281
|
-
maxLength,
|
|
282
|
-
minLength,
|
|
283
|
-
email,
|
|
284
|
-
url,
|
|
285
|
-
https,
|
|
286
|
-
extension,
|
|
287
|
-
contains,
|
|
288
|
-
notContains,
|
|
289
|
-
notBeginsWith,
|
|
290
|
-
notEndsWith,
|
|
291
|
-
maxFileSize,
|
|
292
|
-
}
|
|
1
|
+
import { i18n } from './i18n'
|
|
2
|
+
|
|
3
|
+
const $t = i18n.global.t
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The value is required.
|
|
7
|
+
* @param {string} [msg] - Override the default error message
|
|
8
|
+
*/
|
|
9
|
+
export function required (msg?: string) {
|
|
10
|
+
return (value): true | string => {
|
|
11
|
+
return !!value || msg || $t('inri.validation.required')
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The value must have a minimum length.
|
|
17
|
+
* @param {string | number} length - Min length
|
|
18
|
+
* @param {string} [msg] - Override the default error message
|
|
19
|
+
*/
|
|
20
|
+
export function minLength (length: string | number, msg?: string) {
|
|
21
|
+
const parsedLength = typeof length === 'number' ? length : parseInt(length, 10)
|
|
22
|
+
return (value): true | string => {
|
|
23
|
+
if (!value) {
|
|
24
|
+
return true
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return value.length >= parsedLength || msg || $t('inri.validation.minLength', { parsedLength: parsedLength })
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The value can not exceed maximum length.
|
|
33
|
+
* @param {string | number} length - Max length
|
|
34
|
+
* @param {string} [msg] - Override the default error message
|
|
35
|
+
*/
|
|
36
|
+
export function maxLength (length: string | number, msg?: string) {
|
|
37
|
+
const parsedLength = typeof length === 'number' ? length : parseInt(length, 10)
|
|
38
|
+
return (value): true | string => {
|
|
39
|
+
if (!value) {
|
|
40
|
+
return true
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return value.length <= parsedLength || msg || $t('inri.validation.maxLength', { parsedLength: parsedLength })
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The value must be a valid email.
|
|
49
|
+
* @param {string} [msg] - Override the default error message
|
|
50
|
+
*/
|
|
51
|
+
export function email (msg?: string) {
|
|
52
|
+
// eslint-disable-next-line no-useless-escape
|
|
53
|
+
const regExp = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
|
54
|
+
return (value): true | string => {
|
|
55
|
+
if (!value) {
|
|
56
|
+
return true
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return regExp.test(String(value).toLowerCase()) || msg || $t('inri.validation.email')
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The value must be a valid url.
|
|
65
|
+
* @param {string} [msg] - Override the default error message
|
|
66
|
+
*/
|
|
67
|
+
export function url (msg?: string) {
|
|
68
|
+
// eslint-disable-next-line no-useless-escape
|
|
69
|
+
const regExp = /^(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*))$/
|
|
70
|
+
return (value): true | string => {
|
|
71
|
+
if (!value) {
|
|
72
|
+
return true
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return regExp.test(String(value).toLowerCase()) || msg || $t('inri.validation.url')
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The value must be a valid url using https.
|
|
81
|
+
* @param {string} [msg] - Override the default error message
|
|
82
|
+
*/
|
|
83
|
+
export function https (msg?: string) {
|
|
84
|
+
// eslint-disable-next-line no-useless-escape
|
|
85
|
+
const regExp = /^(https:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*))$/
|
|
86
|
+
return (value): true | string => {
|
|
87
|
+
if (!value) {
|
|
88
|
+
return true
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return regExp.test(String(value).toLowerCase()) || msg || $t('inri.validation.https')
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Validate file extensions. Supports single and multiple files.
|
|
97
|
+
* @param {string} fileExtensions - A string containing a single file extension, "jpg", or a comma separated string, "jpg,png".
|
|
98
|
+
* @param {string} [msg] - Override the default error message
|
|
99
|
+
*/
|
|
100
|
+
export function extension (fileExtensions: string, msg?: string) {
|
|
101
|
+
// Extension string cleanup and convert to array
|
|
102
|
+
const extensions = fileExtensions
|
|
103
|
+
.toLowerCase()
|
|
104
|
+
.replaceAll(' ', '')
|
|
105
|
+
.replaceAll('.', '')
|
|
106
|
+
.split(',')
|
|
107
|
+
|
|
108
|
+
return (value): true | string => {
|
|
109
|
+
if (!value) {
|
|
110
|
+
return true
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
let files: any[] = []
|
|
114
|
+
let isValid = true
|
|
115
|
+
|
|
116
|
+
// If single file then push it into an array for consistency
|
|
117
|
+
if (!value.length) {
|
|
118
|
+
files.push(value)
|
|
119
|
+
} else {
|
|
120
|
+
files = value
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
for (const file of files) {
|
|
124
|
+
const fileExt = file.name.substring(file.name.lastIndexOf('.') + 1).toLowerCase()
|
|
125
|
+
if (!extensions.includes(fileExt)) {
|
|
126
|
+
isValid = false
|
|
127
|
+
break
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return isValid || msg || $t('inri.validation.extension', { extensions: extensions.join(', .') })
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* The value must contain all the strings in the array.
|
|
137
|
+
* @param {string[]} arr - Array of strings.
|
|
138
|
+
* @param {boolean} caseSensitive
|
|
139
|
+
* @param {string} [msg] - Override the default error message
|
|
140
|
+
*/
|
|
141
|
+
export function contains (arr: string[], caseSensitive = false, msg?: string) {
|
|
142
|
+
return (value): true | string => {
|
|
143
|
+
if (!value) {
|
|
144
|
+
return true
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
let foundItems
|
|
148
|
+
|
|
149
|
+
if (!caseSensitive) {
|
|
150
|
+
foundItems = arr.filter(item => !value.toUpperCase().includes(('' + item).toUpperCase()))
|
|
151
|
+
} else {
|
|
152
|
+
foundItems = arr.filter(item => !value.includes('' + item))
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (!foundItems.length) {
|
|
156
|
+
return true
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return msg || $t('inri.validation.contains', { match: foundItems.join(', ') })
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* The value must not contain any of the strings in the array.
|
|
165
|
+
* @param {string[]} arr - Array of strings.
|
|
166
|
+
* @param {boolean} caseSensitive
|
|
167
|
+
* @param {string} [msg] - Override the default error message
|
|
168
|
+
*/
|
|
169
|
+
export function notContains (arr: string[], caseSensitive = false, msg?: string) {
|
|
170
|
+
return (value): true | string => {
|
|
171
|
+
if (!value) {
|
|
172
|
+
return true
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const comparisonValue = value instanceof File ? value.name : value
|
|
176
|
+
|
|
177
|
+
let foundItems
|
|
178
|
+
|
|
179
|
+
if (!caseSensitive) {
|
|
180
|
+
foundItems = arr.filter(item => comparisonValue.toUpperCase().includes(('' + item).toUpperCase()))
|
|
181
|
+
} else {
|
|
182
|
+
foundItems = arr.filter(item => comparisonValue.includes('' + item))
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (!foundItems.length) {
|
|
186
|
+
return true
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return msg || $t('inri.validation.notContains', { match: foundItems.join(', ') })
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* The value must not begin with any of the strings in the array.
|
|
195
|
+
* @param {string[]} arr - Array of strings.
|
|
196
|
+
* @param {boolean} caseSensitive
|
|
197
|
+
* @param {string} [msg] - Override the default error message
|
|
198
|
+
*/
|
|
199
|
+
export function notBeginsWith (arr: string[], caseSensitive = false, msg?: string) {
|
|
200
|
+
return (value): true | string => {
|
|
201
|
+
if (!value) {
|
|
202
|
+
return true
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
let foundItems
|
|
206
|
+
|
|
207
|
+
if (!caseSensitive) {
|
|
208
|
+
foundItems = arr.filter(item => value.toUpperCase().startsWith(('' + item).toUpperCase()))
|
|
209
|
+
} else {
|
|
210
|
+
foundItems = arr.filter(item => value.startsWith('' + item))
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (!foundItems.length) {
|
|
214
|
+
return true
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return msg || $t('inri.validation.notBeginsWith', { match: foundItems.join(', ') })
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* The value must not end with any of the strings in the array.
|
|
223
|
+
* @param {string[]} arr - Array of strings.
|
|
224
|
+
* @param {boolean} caseSensitive
|
|
225
|
+
* @param {string} [msg] - Override the default error message
|
|
226
|
+
*/
|
|
227
|
+
export function notEndsWith (arr: string[], caseSensitive = false, msg?: string) {
|
|
228
|
+
return (value): true | string => {
|
|
229
|
+
if (!value) {
|
|
230
|
+
return true
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
let foundItems
|
|
234
|
+
|
|
235
|
+
if (!caseSensitive) {
|
|
236
|
+
foundItems = arr.filter(item => value.toUpperCase().endsWith(('' + item).toUpperCase()))
|
|
237
|
+
} else {
|
|
238
|
+
foundItems = arr.filter(item => value.endsWith('' + item))
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (!foundItems.length) {
|
|
242
|
+
return true
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return msg || $t('inri.validation.notEndsWith', { match: foundItems.join(', ') })
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* The file(s) cannot exceed max size
|
|
251
|
+
* @param {string | number} size - Max size in bytes
|
|
252
|
+
* @param {string} [type] - Only validate against files with this MIME type
|
|
253
|
+
* @param {string} [msg] - Override the default error message
|
|
254
|
+
*/
|
|
255
|
+
export function maxFileSize (size: string | number, type?: string, msg?: string) {
|
|
256
|
+
const parsedFileSize = typeof size === 'number' ? size : parseInt(size, 10)
|
|
257
|
+
|
|
258
|
+
return (value): true | string => {
|
|
259
|
+
if (!value) {
|
|
260
|
+
return true
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
let files: any[] = []
|
|
264
|
+
|
|
265
|
+
if (!value.length) {
|
|
266
|
+
files.push(value)
|
|
267
|
+
} else {
|
|
268
|
+
files = value
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (type) {
|
|
272
|
+
files = files.filter(file => file.type.includes(type))
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return files.every(file => file.size <= size) || msg || $t('inri.validation.maxFileSize', { parsedFileSize })
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export const rules = {
|
|
280
|
+
required,
|
|
281
|
+
maxLength,
|
|
282
|
+
minLength,
|
|
283
|
+
email,
|
|
284
|
+
url,
|
|
285
|
+
https,
|
|
286
|
+
extension,
|
|
287
|
+
contains,
|
|
288
|
+
notContains,
|
|
289
|
+
notBeginsWith,
|
|
290
|
+
notEndsWith,
|
|
291
|
+
maxFileSize,
|
|
292
|
+
}
|
package/src/shims-vue.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
declare module '*.vue' {
|
|
3
|
-
import type { DefineComponent } from 'vue'
|
|
4
|
-
const component: DefineComponent<{}, {}, any>
|
|
5
|
-
export default component
|
|
6
|
-
}
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
declare module '*.vue' {
|
|
3
|
+
import type { DefineComponent } from 'vue'
|
|
4
|
+
const component: DefineComponent<{}, {}, any>
|
|
5
|
+
export default component
|
|
6
|
+
}
|