@naptics/vue-collection 0.0.2 → 0.0.3
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/README.md +118 -14
- package/components/NInputPhone.d.ts +1 -1
- package/components/NInputPhone.jsx +2 -1
- package/components/NInputSuggestion.d.ts +1 -1
- package/components/NTextArea.d.ts +1 -1
- package/components/NValInput.d.ts +1 -1
- package/i18n/index.d.ts +24 -1
- package/i18n/index.js +16 -15
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +3 -3
- package/utils/validation.d.ts +9 -3
- package/utils/validation.js +34 -24
- package/i18n/de/template.json +0 -10
- package/i18n/de.d.ts +0 -61
- package/i18n/de.js +0 -5
- package/i18n/en/template.json +0 -10
- package/i18n/en.d.ts +0 -61
- package/i18n/en.js +0 -5
package/README.md
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Vue Collection is a collection of styled and fully functional Vue components which can easily be integrated into our projects.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Demo Page 🎆
|
|
6
6
|
|
|
7
|
-
You can take a look at all components on [
|
|
7
|
+
You can take a look at all components on [GitHub Pages](https://naptics.github.io/vue-collection/).
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## Project Setup 🚧
|
|
10
|
+
|
|
11
|
+
This section shows how to create a new Vue project with the recommended tech-stack to be ready to install Vue Collection afterwards.
|
|
10
12
|
|
|
11
13
|
1. Create a new vue-project with `npm init vue@latest`. Add at least typescript, jsx, vue-router, eslint and prettier.
|
|
12
14
|
2. Remove boilerplate code.
|
|
@@ -14,14 +16,116 @@ You can take a look at all components on [Gitlab Pages](https://naptx.gitlab.io/
|
|
|
14
16
|
- `npm install -D tailwindcss postcss autoprefixer`
|
|
15
17
|
- `npx tailwindcss init`
|
|
16
18
|
- ... follow the further instructions
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
4. Add tailwind forms with `npm install -D @tailwindcss/forms`.
|
|
20
|
+
5. Add other dependencies with `npm install @heroicons/vue vue-i18n`
|
|
21
|
+
6. Copy files from `.vscode` to your project. Remove `.vscode/settings.json` file from `.gitignore`. Copy `.prettierrc` to your project.
|
|
22
|
+
7. Make sure typescript config is correct. Double check with this repo.
|
|
23
|
+
|
|
24
|
+
## Installation Guide 🔨
|
|
25
|
+
|
|
26
|
+
These are the steps to add Vue Collection to an existing project. You may have to go through the steps of `Project Setup` and check if you have the neccesary (peer-)dependencies installed.
|
|
27
|
+
|
|
28
|
+
1. Go to [npmjs.com](https://npmjs.com), sign in with naptics and create a new read-only classic access token.
|
|
29
|
+
2. Save your access token under `~/.npmrc` with the following content, replacing `YOUR_TOKEN` with the access token.
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
//registry.npmjs.org/:_authToken=YOUR_TOKEN
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
3. Install Vue Collection with `npm i @naptics/vue-collection`.
|
|
36
|
+
4. Add tailwind config -> See below
|
|
37
|
+
5. Register i18n provider -> See below
|
|
38
|
+
|
|
39
|
+
## Tailwind Config
|
|
40
|
+
|
|
41
|
+
With this tailwind config file, Vue Collection works as expected. Feel free to change the `default`, `primary` and `secondary` colors and add whatever is needed in your project.
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
// tailwind.config.js
|
|
45
|
+
|
|
46
|
+
/* eslint-disable no-undef */
|
|
47
|
+
const colors = require('tailwindcss/colors')
|
|
48
|
+
|
|
49
|
+
const unresolvedConfig = require('tailwindcss/defaultConfig')
|
|
50
|
+
const resolveConfig = require('tailwindcss/resolveConfig')
|
|
51
|
+
const config = resolveConfig(unresolvedConfig)
|
|
52
|
+
|
|
53
|
+
const allShades = '50|100|200|300|400|500|600|700|800|900'
|
|
54
|
+
const usedColors = 'default|primary|secondary|green|red|yellow|blue'
|
|
55
|
+
const smallSizes = '1|2|3|4|5|6|7|8|9|10|11|12|14|16|18|20'
|
|
56
|
+
|
|
57
|
+
/** @type {import('tailwindcss').Config} */
|
|
58
|
+
module.exports = {
|
|
59
|
+
content: ['./src/**/*.{tsx,ts}', './node_modules/@naptics/vue-collection/**/*.{jsx,js}'],
|
|
60
|
+
safelist: [
|
|
61
|
+
{
|
|
62
|
+
pattern: new RegExp(`^(bg|text)-(${usedColors})-(${allShades})$`),
|
|
63
|
+
variants: ['hover'],
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
pattern: new RegExp(`^ring-(${usedColors})-(${allShades})$`),
|
|
67
|
+
variants: ['focus-visible'],
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
pattern: new RegExp(`^(w|h)-(${smallSizes})$`),
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
theme: {
|
|
74
|
+
extend: {
|
|
75
|
+
colors: {
|
|
76
|
+
default: colors.slate,
|
|
77
|
+
primary: colors.violet,
|
|
78
|
+
secondary: colors.fuchsia,
|
|
79
|
+
},
|
|
80
|
+
minHeight: config.theme.spacing,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
plugins: [require('@tailwindcss/forms')],
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Register i18n Provider
|
|
88
|
+
|
|
89
|
+
These are two sample files, how the i18n provider can be registered by using `vue-i18n`. The translation files of Vue Collection have to be added to the i18n provider in order for the Vue Collection components to work properly.
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
// src/i18n/index.ts
|
|
93
|
+
|
|
94
|
+
import en from './en'
|
|
95
|
+
import de from './de'
|
|
96
|
+
import { createI18n } from 'vue-i18n'
|
|
97
|
+
import { registerTranslationProvider } from '@naptics/vue-collection/i18n'
|
|
98
|
+
|
|
99
|
+
const i18n = createI18n({
|
|
100
|
+
legacy: false,
|
|
101
|
+
locale: 'de',
|
|
102
|
+
messages: {
|
|
103
|
+
en,
|
|
104
|
+
de,
|
|
105
|
+
},
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
registerTranslationProvider({
|
|
109
|
+
trsl(key, params) {
|
|
110
|
+
return i18n.global.t(key, params == null ? {} : params)
|
|
111
|
+
},
|
|
112
|
+
trslc(key, count, params) {
|
|
113
|
+
const newCount = count ?? 0
|
|
114
|
+
const newParams = { n: newCount, ...params }
|
|
115
|
+
return i18n.global.t(key, newParams, { plural: newCount })
|
|
116
|
+
},
|
|
117
|
+
})
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
// src/i18n/de.ts
|
|
122
|
+
|
|
123
|
+
import vueCollection from '@naptics/vue-collection/i18n/de/vue-collection.json'
|
|
124
|
+
|
|
125
|
+
const de = {
|
|
126
|
+
['vue-collection']: vueCollection,
|
|
127
|
+
// other translation files
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export default de
|
|
131
|
+
```
|
|
@@ -140,10 +140,10 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
140
140
|
tooltipMaxWidth: import("../utils/tailwind").TWMaxWidth;
|
|
141
141
|
disabled: boolean;
|
|
142
142
|
error: boolean;
|
|
143
|
-
rules: import("../utils/validation").ValidationRule | import("../utils/validation").ValidationRule[];
|
|
144
143
|
autocomplete: string;
|
|
145
144
|
hideLabel: boolean;
|
|
146
145
|
optional: boolean;
|
|
146
|
+
rules: import("../utils/validation").ValidationRule | import("../utils/validation").ValidationRule[];
|
|
147
147
|
hideErrorMessage: boolean;
|
|
148
148
|
disableBlurValidation: boolean;
|
|
149
149
|
}>;
|
|
@@ -2,6 +2,7 @@ import { createComponent, createProps } from '../utils/component';
|
|
|
2
2
|
import { external } from '../utils/validation';
|
|
3
3
|
import { computed, Suspense } from 'vue';
|
|
4
4
|
import NValInput, { nValInputProps } from './NValInput';
|
|
5
|
+
import { trsl } from '../i18n';
|
|
5
6
|
export const nInputPhoneProps = createProps(nValInputProps);
|
|
6
7
|
/**
|
|
7
8
|
* The `NInputPhone` autoformats phone numbers and checks if they are valid.
|
|
@@ -27,5 +28,5 @@ const NPhoneInput = createComponent('NInputPhone', nInputPhoneProps, async (prop
|
|
|
27
28
|
return formatted || props.value;
|
|
28
29
|
});
|
|
29
30
|
const isValid = computed(() => parsePhoneNumber(props.value || '').valid);
|
|
30
|
-
return () => (<NValInput {...{ ...props, onUpdateValue }} value={value.value} rules={external(isValid.value, 'phone')} type="tel"/>);
|
|
31
|
+
return () => (<NValInput {...{ ...props, onUpdateValue }} value={value.value} rules={external(isValid.value, trsl('vue-collection.validation.rules.phone'))} type="tel"/>);
|
|
31
32
|
});
|
|
@@ -199,10 +199,10 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
199
199
|
tooltipMaxWidth: import("../utils/tailwind").TWMaxWidth;
|
|
200
200
|
disabled: boolean;
|
|
201
201
|
error: boolean;
|
|
202
|
-
rules: import("../utils/validation").ValidationRule | import("../utils/validation").ValidationRule[];
|
|
203
202
|
autocomplete: string;
|
|
204
203
|
hideLabel: boolean;
|
|
205
204
|
optional: boolean;
|
|
205
|
+
rules: import("../utils/validation").ValidationRule | import("../utils/validation").ValidationRule[];
|
|
206
206
|
hideErrorMessage: boolean;
|
|
207
207
|
disableBlurValidation: boolean;
|
|
208
208
|
maxItems: number;
|
|
@@ -241,10 +241,10 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
241
241
|
tooltipMaxWidth: import("../utils/tailwind").TWMaxWidth;
|
|
242
242
|
disabled: boolean;
|
|
243
243
|
error: boolean;
|
|
244
|
-
rules: import("../utils/validation").ValidationRule | import("../utils/validation").ValidationRule[];
|
|
245
244
|
autocomplete: string;
|
|
246
245
|
hideLabel: boolean;
|
|
247
246
|
optional: boolean;
|
|
247
|
+
rules: import("../utils/validation").ValidationRule | import("../utils/validation").ValidationRule[];
|
|
248
248
|
hideErrorMessage: boolean;
|
|
249
249
|
disableBlurValidation: boolean;
|
|
250
250
|
resizable: boolean;
|
|
@@ -287,10 +287,10 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
287
287
|
tooltipMaxWidth: import("../utils/tailwind").TWMaxWidth;
|
|
288
288
|
disabled: boolean;
|
|
289
289
|
error: boolean;
|
|
290
|
-
rules: ValidationRule | ValidationRule[];
|
|
291
290
|
autocomplete: string;
|
|
292
291
|
hideLabel: boolean;
|
|
293
292
|
optional: boolean;
|
|
293
|
+
rules: ValidationRule | ValidationRule[];
|
|
294
294
|
hideErrorMessage: boolean;
|
|
295
295
|
disableBlurValidation: boolean;
|
|
296
296
|
}>;
|
package/i18n/index.d.ts
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
import type { Nullish } from '../utils/utils';
|
|
2
|
+
/**
|
|
3
|
+
* @see {@link trsl}
|
|
4
|
+
*/
|
|
5
|
+
export type TranslationFunction = typeof trsl;
|
|
6
|
+
/**
|
|
7
|
+
* @see {@link trslc}
|
|
8
|
+
*/
|
|
9
|
+
export type TranslationCountFunction = typeof trslc;
|
|
10
|
+
/**
|
|
11
|
+
* A `TranslationProvider` has to implement the two functions `trsl` and `trslc`.
|
|
12
|
+
*/
|
|
13
|
+
export type TranslationProvider = {
|
|
14
|
+
trsl: TranslationFunction;
|
|
15
|
+
trslc: TranslationCountFunction;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Registeres a new translation provider for vue-collection.
|
|
19
|
+
* The translation provider should contain all vue-collection
|
|
20
|
+
* texts located under `i18n/<lang>/vue-collection.json`.
|
|
21
|
+
* @param newProvider
|
|
22
|
+
*/
|
|
23
|
+
export declare function registerTranslationProvider(newProvider: TranslationProvider): void;
|
|
1
24
|
/**
|
|
2
25
|
* Translates the specified key with the according message.
|
|
3
26
|
* @param key the key to translate.
|
|
@@ -14,4 +37,4 @@ export declare function trsl(key: string, params?: Record<string, unknown>): str
|
|
|
14
37
|
* @returns the translated message.
|
|
15
38
|
* @see trsl
|
|
16
39
|
*/
|
|
17
|
-
export declare function trslc(key: string, count: number
|
|
40
|
+
export declare function trslc(key: string, count: Nullish<number>, params?: Record<string, unknown>): string;
|
package/i18n/index.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
});
|
|
1
|
+
let provider = undefined;
|
|
2
|
+
/**
|
|
3
|
+
* Registeres a new translation provider for vue-collection.
|
|
4
|
+
* The translation provider should contain all vue-collection
|
|
5
|
+
* texts located under `i18n/<lang>/vue-collection.json`.
|
|
6
|
+
* @param newProvider
|
|
7
|
+
*/
|
|
8
|
+
export function registerTranslationProvider(newProvider) {
|
|
9
|
+
provider = newProvider;
|
|
10
|
+
}
|
|
12
11
|
/**
|
|
13
12
|
* Translates the specified key with the according message.
|
|
14
13
|
* @param key the key to translate.
|
|
@@ -16,7 +15,9 @@ const i18n = createI18n({
|
|
|
16
15
|
* @returns the translated message.
|
|
17
16
|
*/
|
|
18
17
|
export function trsl(key, params) {
|
|
19
|
-
|
|
18
|
+
if (!provider)
|
|
19
|
+
console.warn('Vue Collection: No translation provider has been registered!');
|
|
20
|
+
return provider?.trsl(key, params) ?? key;
|
|
20
21
|
}
|
|
21
22
|
/**
|
|
22
23
|
* Translates the specified key using pluralization.
|
|
@@ -28,7 +29,7 @@ export function trsl(key, params) {
|
|
|
28
29
|
* @see trsl
|
|
29
30
|
*/
|
|
30
31
|
export function trslc(key, count, params) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return
|
|
32
|
+
if (!provider)
|
|
33
|
+
console.warn('Vue Collection: No translation provider has been registered!');
|
|
34
|
+
return provider?.trslc(key, count, params) ?? key;
|
|
34
35
|
}
|
package/index.d.ts
CHANGED
|
@@ -62,3 +62,5 @@ import NValInput from './components/NValInput';
|
|
|
62
62
|
export { NValInput };
|
|
63
63
|
import { type ValidatedForm, createValidatedForm } from './components/ValidatedForm';
|
|
64
64
|
export { ValidatedForm, createValidatedForm };
|
|
65
|
+
import { createComponent, createView, createProps } from './utils/component';
|
|
66
|
+
export { createComponent, createView, createProps };
|
package/index.js
CHANGED
|
@@ -63,3 +63,5 @@ import NValInput from './components/NValInput';
|
|
|
63
63
|
export { NValInput };
|
|
64
64
|
import { createValidatedForm } from './components/ValidatedForm';
|
|
65
65
|
export { createValidatedForm };
|
|
66
|
+
import { createComponent, createView, createProps } from './utils/component';
|
|
67
|
+
export { createComponent, createView, createProps };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naptics/vue-collection",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "vite",
|
|
@@ -21,8 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"@heroicons/vue": "^2.0.16",
|
|
24
|
-
"vue": "^3.2.36"
|
|
25
|
-
"vue-i18n": "^9.2.2"
|
|
24
|
+
"vue": "^3.2.36"
|
|
26
25
|
},
|
|
27
26
|
"devDependencies": {
|
|
28
27
|
"@intlify/unplugin-vue-i18n": "^0.8.2",
|
|
@@ -47,6 +46,7 @@
|
|
|
47
46
|
"typescript": "^4.9.5",
|
|
48
47
|
"vite": "^4.1.3",
|
|
49
48
|
"vitest": "^0.28.5",
|
|
49
|
+
"vue-i18n": "^9.2.2",
|
|
50
50
|
"vue-router": "^4.1.6",
|
|
51
51
|
"vue-tsc": "^1.1.5"
|
|
52
52
|
}
|
package/utils/validation.d.ts
CHANGED
|
@@ -15,8 +15,14 @@ export type ValidationResult = ValidationResultValid | ValidationResultInvalid;
|
|
|
15
15
|
* with the {@link required} rule.
|
|
16
16
|
*/
|
|
17
17
|
export type ValidationRule = (input: InputValue) => ValidationResult;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a valid result.
|
|
20
|
+
*/
|
|
18
21
|
export declare function validResult(): ValidationResultValid;
|
|
19
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Creates an invalid result with the provided error message.
|
|
24
|
+
*/
|
|
25
|
+
export declare function invalidResult(errorMessage: string): ValidationResultInvalid;
|
|
20
26
|
/**
|
|
21
27
|
* Validates a given input with the specified rules.
|
|
22
28
|
* The rules are evaluated in the order they're in the array.
|
|
@@ -76,9 +82,9 @@ export declare function option(options: string[]): ValidationRule;
|
|
|
76
82
|
*/
|
|
77
83
|
export declare function regex(pattern: RegExp): ValidationRule;
|
|
78
84
|
/**
|
|
79
|
-
* This rule can be used if the validation logic happens
|
|
85
|
+
* This rule can be used if the validation logic happens somewhere else.
|
|
80
86
|
* When `isValid = true` is passed, the function will return a valid result,
|
|
81
87
|
* otherwise it will return the invalid result with the passed `errorKey`.
|
|
82
88
|
* Like always, a falsy input is always valid to not interefere with the {@link required} rule.
|
|
83
89
|
*/
|
|
84
|
-
export declare function external(isValid: boolean,
|
|
90
|
+
export declare function external(isValid: boolean, errorMessage: string): ValidationRule;
|
package/utils/validation.js
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import { trsl } from '../i18n';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a valid result.
|
|
4
|
+
*/
|
|
2
5
|
export function validResult() {
|
|
3
6
|
return { isValid: true };
|
|
4
7
|
}
|
|
5
|
-
|
|
6
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Creates an invalid result with the provided error message.
|
|
10
|
+
*/
|
|
11
|
+
export function invalidResult(errorMessage) {
|
|
12
|
+
return { isValid: false, errorMessage };
|
|
13
|
+
}
|
|
14
|
+
const TRANSLATION_KEY_BASE = 'vue-collection.validation.rules';
|
|
15
|
+
function invalidResultInternal(key, params) {
|
|
16
|
+
return invalidResult(trsl(`${TRANSLATION_KEY_BASE}.${key}`, params));
|
|
7
17
|
}
|
|
8
18
|
/**
|
|
9
19
|
* Validates a given input with the specified rules.
|
|
@@ -33,7 +43,7 @@ export const required = input => {
|
|
|
33
43
|
if (trimmed)
|
|
34
44
|
return validResult();
|
|
35
45
|
else
|
|
36
|
-
return
|
|
46
|
+
return invalidResultInternal('required');
|
|
37
47
|
};
|
|
38
48
|
/**
|
|
39
49
|
* This rule expects the input to be an integer.
|
|
@@ -42,7 +52,7 @@ export const integer = input => {
|
|
|
42
52
|
if (!input || Number.isInteger(+input))
|
|
43
53
|
return validResult();
|
|
44
54
|
else
|
|
45
|
-
return
|
|
55
|
+
return invalidResultInternal('integer');
|
|
46
56
|
};
|
|
47
57
|
/**
|
|
48
58
|
* This rule expects the input to be in the specified length range. An empty input
|
|
@@ -55,11 +65,11 @@ export function length(min, max) {
|
|
|
55
65
|
if (!input)
|
|
56
66
|
return validResult();
|
|
57
67
|
if (min !== undefined && max !== undefined && !(min <= input.length && input.length <= max))
|
|
58
|
-
return
|
|
68
|
+
return invalidResultInternal('length.min-max', { min, max });
|
|
59
69
|
else if (min !== undefined && !(min <= input.length))
|
|
60
|
-
return
|
|
70
|
+
return invalidResultInternal('length.min', { min });
|
|
61
71
|
else if (max !== undefined && !(input.length <= max))
|
|
62
|
-
return
|
|
72
|
+
return invalidResultInternal('length.max', { max });
|
|
63
73
|
return validResult();
|
|
64
74
|
};
|
|
65
75
|
}
|
|
@@ -74,13 +84,13 @@ export function numberRange(min, max) {
|
|
|
74
84
|
return validResult();
|
|
75
85
|
const parsed = Number.parseFloat(input);
|
|
76
86
|
if (Number.isNaN(parsed))
|
|
77
|
-
return
|
|
87
|
+
return invalidResultInternal('number-range.nan');
|
|
78
88
|
if (min !== undefined && max !== undefined && !(min <= parsed && parsed <= max))
|
|
79
|
-
return
|
|
89
|
+
return invalidResultInternal('number-range.min-max', { min, max });
|
|
80
90
|
else if (min !== undefined && !(min <= parsed))
|
|
81
|
-
return
|
|
91
|
+
return invalidResultInternal('number-range.min', { min });
|
|
82
92
|
else if (max !== undefined && !(parsed <= max))
|
|
83
|
-
return
|
|
93
|
+
return invalidResultInternal('number-range.max', { max });
|
|
84
94
|
return validResult();
|
|
85
95
|
};
|
|
86
96
|
}
|
|
@@ -92,7 +102,7 @@ export const email = input => {
|
|
|
92
102
|
if (!input || VALIDATION_FORMAT_EMAIL.test(input))
|
|
93
103
|
return validResult();
|
|
94
104
|
else
|
|
95
|
-
return
|
|
105
|
+
return invalidResultInternal('email');
|
|
96
106
|
};
|
|
97
107
|
export const VALIDATION_FORMAT_PASSWORD = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[#$^+\-=!*()@%&?]).{8,}$/;
|
|
98
108
|
/**
|
|
@@ -102,17 +112,17 @@ export const password = input => {
|
|
|
102
112
|
if (!input || VALIDATION_FORMAT_PASSWORD.test(input))
|
|
103
113
|
return validResult();
|
|
104
114
|
else if (input.length < 8)
|
|
105
|
-
return
|
|
115
|
+
return invalidResultInternal('password.to-short');
|
|
106
116
|
else if (!/[a-z]+/.test(input))
|
|
107
|
-
return
|
|
117
|
+
return invalidResultInternal('password.no-lowercase');
|
|
108
118
|
else if (!/[A-Z]+/.test(input))
|
|
109
|
-
return
|
|
119
|
+
return invalidResultInternal('password.no-uppercase');
|
|
110
120
|
else if (!/\d+/.test(input))
|
|
111
|
-
return
|
|
121
|
+
return invalidResultInternal('password.no-digits');
|
|
112
122
|
else if (!/[#$^+\-=!*()@%&?]+/.test(input))
|
|
113
|
-
return
|
|
123
|
+
return invalidResultInternal('password.no-special-chars');
|
|
114
124
|
else
|
|
115
|
-
return
|
|
125
|
+
return invalidResultInternal('password.unknown');
|
|
116
126
|
};
|
|
117
127
|
/**
|
|
118
128
|
* This rule expects the input-value to match another (input-) value.
|
|
@@ -125,7 +135,7 @@ export function matches(other) {
|
|
|
125
135
|
if (input === other)
|
|
126
136
|
return validResult();
|
|
127
137
|
else
|
|
128
|
-
return
|
|
138
|
+
return invalidResultInternal('matches');
|
|
129
139
|
};
|
|
130
140
|
}
|
|
131
141
|
/**
|
|
@@ -137,7 +147,7 @@ export function option(options) {
|
|
|
137
147
|
if (!input || options.includes(input || ''))
|
|
138
148
|
return validResult();
|
|
139
149
|
else
|
|
140
|
-
return
|
|
150
|
+
return invalidResultInternal('option');
|
|
141
151
|
};
|
|
142
152
|
}
|
|
143
153
|
/**
|
|
@@ -149,15 +159,15 @@ export function regex(pattern) {
|
|
|
149
159
|
if (!input || pattern.test(input || ''))
|
|
150
160
|
return validResult();
|
|
151
161
|
else
|
|
152
|
-
return
|
|
162
|
+
return invalidResultInternal('regex');
|
|
153
163
|
};
|
|
154
164
|
}
|
|
155
165
|
/**
|
|
156
|
-
* This rule can be used if the validation logic happens
|
|
166
|
+
* This rule can be used if the validation logic happens somewhere else.
|
|
157
167
|
* When `isValid = true` is passed, the function will return a valid result,
|
|
158
168
|
* otherwise it will return the invalid result with the passed `errorKey`.
|
|
159
169
|
* Like always, a falsy input is always valid to not interefere with the {@link required} rule.
|
|
160
170
|
*/
|
|
161
|
-
export function external(isValid,
|
|
162
|
-
return input => (!input || isValid ? validResult() : invalidResult(
|
|
171
|
+
export function external(isValid, errorMessage) {
|
|
172
|
+
return input => (!input || isValid ? validResult() : invalidResult(errorMessage));
|
|
163
173
|
}
|
package/i18n/de/template.json
DELETED
package/i18n/de.d.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
declare const de: {
|
|
2
|
-
"vue-collection": {
|
|
3
|
-
title: {};
|
|
4
|
-
subtitle: {};
|
|
5
|
-
text: {
|
|
6
|
-
"loading-search-results": string;
|
|
7
|
-
"no-search-results": string;
|
|
8
|
-
"drag-n-drop-files": string;
|
|
9
|
-
"files-selected": string;
|
|
10
|
-
};
|
|
11
|
-
property: {};
|
|
12
|
-
term: {};
|
|
13
|
-
action: {
|
|
14
|
-
search: string;
|
|
15
|
-
select: string;
|
|
16
|
-
remove: string;
|
|
17
|
-
cancel: string;
|
|
18
|
-
"all-right": string;
|
|
19
|
-
proceed: string;
|
|
20
|
-
save: string;
|
|
21
|
-
"clear-files": string;
|
|
22
|
-
};
|
|
23
|
-
enum: {};
|
|
24
|
-
error: {
|
|
25
|
-
"file-type": string;
|
|
26
|
-
"file-size": string;
|
|
27
|
-
"too-many-files": string;
|
|
28
|
-
};
|
|
29
|
-
validation: {
|
|
30
|
-
rules: {
|
|
31
|
-
email: string;
|
|
32
|
-
integer: string;
|
|
33
|
-
length: {
|
|
34
|
-
min: string;
|
|
35
|
-
max: string;
|
|
36
|
-
"min-max": string;
|
|
37
|
-
};
|
|
38
|
-
matches: string;
|
|
39
|
-
"number-range": {
|
|
40
|
-
nan: string;
|
|
41
|
-
min: string;
|
|
42
|
-
max: string;
|
|
43
|
-
"min-max": string;
|
|
44
|
-
};
|
|
45
|
-
option: string;
|
|
46
|
-
password: {
|
|
47
|
-
"to-short": string;
|
|
48
|
-
"no-lowercase": string;
|
|
49
|
-
"no-uppercase": string;
|
|
50
|
-
"no-digits": string;
|
|
51
|
-
"no-special-chars": string;
|
|
52
|
-
unknown: string;
|
|
53
|
-
};
|
|
54
|
-
phone: string;
|
|
55
|
-
required: string;
|
|
56
|
-
regex: string;
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
export default de;
|
package/i18n/de.js
DELETED
package/i18n/en/template.json
DELETED
package/i18n/en.d.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
declare const en: {
|
|
2
|
-
"vue-collection": {
|
|
3
|
-
title: {};
|
|
4
|
-
subtitle: {};
|
|
5
|
-
text: {
|
|
6
|
-
"loading-search-results": string;
|
|
7
|
-
"no-search-results": string;
|
|
8
|
-
"drag-n-drop-files": string;
|
|
9
|
-
"files-selected": string;
|
|
10
|
-
};
|
|
11
|
-
property: {};
|
|
12
|
-
term: {};
|
|
13
|
-
action: {
|
|
14
|
-
search: string;
|
|
15
|
-
select: string;
|
|
16
|
-
remove: string;
|
|
17
|
-
cancel: string;
|
|
18
|
-
"all-right": string;
|
|
19
|
-
proceed: string;
|
|
20
|
-
save: string;
|
|
21
|
-
"clear-files": string;
|
|
22
|
-
};
|
|
23
|
-
enum: {};
|
|
24
|
-
error: {
|
|
25
|
-
"file-type": string;
|
|
26
|
-
"file-size": string;
|
|
27
|
-
"too-many-files": string;
|
|
28
|
-
};
|
|
29
|
-
validation: {
|
|
30
|
-
rules: {
|
|
31
|
-
email: string;
|
|
32
|
-
integer: string;
|
|
33
|
-
length: {
|
|
34
|
-
min: string;
|
|
35
|
-
max: string;
|
|
36
|
-
"min-max": string;
|
|
37
|
-
};
|
|
38
|
-
matches: string;
|
|
39
|
-
"number-range": {
|
|
40
|
-
nan: string;
|
|
41
|
-
min: string;
|
|
42
|
-
max: string;
|
|
43
|
-
"min-max": string;
|
|
44
|
-
};
|
|
45
|
-
option: string;
|
|
46
|
-
password: {
|
|
47
|
-
"to-short": string;
|
|
48
|
-
"no-lowercase": string;
|
|
49
|
-
"no-uppercase": string;
|
|
50
|
-
"no-digits": string;
|
|
51
|
-
"no-special-chars": string;
|
|
52
|
-
unknown: string;
|
|
53
|
-
};
|
|
54
|
-
phone: string;
|
|
55
|
-
required: string;
|
|
56
|
-
regex: string;
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
export default en;
|