@sap-ux/project-input-validator 0.3.3 → 0.3.4
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/dist/adp/validators.js +3 -4
- package/dist/deploy/validators.js +4 -5
- package/dist/flp/validators.d.ts +13 -0
- package/dist/flp/validators.js +35 -0
- package/dist/general/validators.d.ts +17 -0
- package/dist/general/validators.js +41 -7
- package/dist/i18n.d.ts +5 -0
- package/dist/i18n.js +13 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -0
- package/dist/translations/project-input-validator.i18n.json +3 -1
- package/dist/ui5/validators.js +4 -5
- package/package.json +1 -1
package/dist/adp/validators.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.hasContentDuplication = hasContentDuplication;
|
|
4
|
+
exports.hasCustomerPrefix = hasCustomerPrefix;
|
|
5
|
+
exports.isDataSourceURI = isDataSourceURI;
|
|
4
6
|
/**
|
|
5
7
|
* Validates a value for duplication in existing change files.
|
|
6
8
|
*
|
|
@@ -15,7 +17,6 @@ function hasContentDuplication(value, propertyName, changeFiles) {
|
|
|
15
17
|
return contentProperty && Object.keys(contentProperty).includes(value);
|
|
16
18
|
});
|
|
17
19
|
}
|
|
18
|
-
exports.hasContentDuplication = hasContentDuplication;
|
|
19
20
|
/**
|
|
20
21
|
* Validates a value for starting with a customer prefix.
|
|
21
22
|
*
|
|
@@ -25,7 +26,6 @@ exports.hasContentDuplication = hasContentDuplication;
|
|
|
25
26
|
function hasCustomerPrefix(value) {
|
|
26
27
|
return value.toLowerCase().startsWith('customer.');
|
|
27
28
|
}
|
|
28
|
-
exports.hasCustomerPrefix = hasCustomerPrefix;
|
|
29
29
|
/**
|
|
30
30
|
* Validates if a value is a valid data source URI.
|
|
31
31
|
*
|
|
@@ -35,5 +35,4 @@ exports.hasCustomerPrefix = hasCustomerPrefix;
|
|
|
35
35
|
function isDataSourceURI(uri) {
|
|
36
36
|
return /^(?!.*\/\/)\/([^\s]*)\/$/.test(uri);
|
|
37
37
|
}
|
|
38
|
-
exports.isDataSourceURI = isDataSourceURI;
|
|
39
38
|
//# sourceMappingURL=validators.js.map
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.validateAppName = validateAppName;
|
|
4
|
+
exports.validateAppDescription = validateAppDescription;
|
|
5
|
+
exports.validateTransportRequestNumber = validateTransportRequestNumber;
|
|
6
|
+
exports.validatePackage = validatePackage;
|
|
4
7
|
const i18n_1 = require("../i18n");
|
|
5
8
|
const os_1 = require("os");
|
|
6
9
|
/**
|
|
@@ -46,7 +49,6 @@ function validateAppName(name, prefix) {
|
|
|
46
49
|
}
|
|
47
50
|
return processErrorMessages(errorMessages);
|
|
48
51
|
}
|
|
49
|
-
exports.validateAppName = validateAppName;
|
|
50
52
|
/**
|
|
51
53
|
* Helper function to format an array of error messages to a single string.
|
|
52
54
|
*
|
|
@@ -79,7 +81,6 @@ function validateAppDescription(description) {
|
|
|
79
81
|
return true;
|
|
80
82
|
}
|
|
81
83
|
}
|
|
82
|
-
exports.validateAppDescription = validateAppDescription;
|
|
83
84
|
/**
|
|
84
85
|
* Transport request number is not required for local package.
|
|
85
86
|
*
|
|
@@ -96,7 +97,6 @@ function validateTransportRequestNumber(transportRequest, packageName) {
|
|
|
96
97
|
return true;
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
|
-
exports.validateTransportRequestNumber = validateTransportRequestNumber;
|
|
100
100
|
/**
|
|
101
101
|
* Validate package name cannot be empty.
|
|
102
102
|
*
|
|
@@ -111,5 +111,4 @@ function validatePackage(input) {
|
|
|
111
111
|
return true;
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
|
-
exports.validatePackage = validatePackage;
|
|
115
114
|
//# sourceMappingURL=validators.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AllowedCharacters } from '../general/validators';
|
|
2
|
+
/**
|
|
3
|
+
* Validates that text input does not have zero length and optionally is less than the specified maximum length.
|
|
4
|
+
* Returns an end user message if validation fails.
|
|
5
|
+
*
|
|
6
|
+
* @param input the text input to validate
|
|
7
|
+
* @param isCLI indicates if the platform is CLI
|
|
8
|
+
* @param maxLength optional, the maximum length of text to allow
|
|
9
|
+
* @param allowedCharacters optional, define a list of special characters that should be allowed in the input field
|
|
10
|
+
* @returns true, if all validation checks pass or a message explaining the validation failure
|
|
11
|
+
*/
|
|
12
|
+
export declare function validateText(input: string, isCLI: boolean, maxLength?: number, allowedCharacters?: AllowedCharacters[]): boolean | string;
|
|
13
|
+
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateText = validateText;
|
|
4
|
+
const i18n_1 = require("../i18n");
|
|
5
|
+
const validators_1 = require("../general/validators");
|
|
6
|
+
/**
|
|
7
|
+
* Validates that text input does not have zero length and optionally is less than the specified maximum length.
|
|
8
|
+
* Returns an end user message if validation fails.
|
|
9
|
+
*
|
|
10
|
+
* @param input the text input to validate
|
|
11
|
+
* @param isCLI indicates if the platform is CLI
|
|
12
|
+
* @param maxLength optional, the maximum length of text to allow
|
|
13
|
+
* @param allowedCharacters optional, define a list of special characters that should be allowed in the input field
|
|
14
|
+
* @returns true, if all validation checks pass or a message explaining the validation failure
|
|
15
|
+
*/
|
|
16
|
+
function validateText(input, isCLI, maxLength = 0, allowedCharacters) {
|
|
17
|
+
const trimmedInput = input ? input.trim() : '';
|
|
18
|
+
const length = trimmedInput.length;
|
|
19
|
+
if (!length) {
|
|
20
|
+
if (isCLI) {
|
|
21
|
+
return (0, i18n_1.t)('general.inputCannotBeEmpty');
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
const maxLengthValidation = (0, validators_1.validateMaxLength)(input, maxLength);
|
|
26
|
+
if (typeof maxLengthValidation === 'string') {
|
|
27
|
+
return maxLengthValidation;
|
|
28
|
+
}
|
|
29
|
+
const allowedCharsValidation = (0, validators_1.validateAllowedCharacters)(input, allowedCharacters);
|
|
30
|
+
if (typeof allowedCharsValidation === 'string') {
|
|
31
|
+
return allowedCharsValidation;
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=validators.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export type AllowedCharacters = '_';
|
|
1
2
|
/**
|
|
2
3
|
* SAP client number is either empty or 3 digit string.
|
|
3
4
|
*
|
|
@@ -26,6 +27,22 @@ export declare function validateEmptyString(input: string): boolean | string;
|
|
|
26
27
|
* @returns true or error message
|
|
27
28
|
*/
|
|
28
29
|
export declare function validateEmptySpaces(value: string): boolean | string;
|
|
30
|
+
/**
|
|
31
|
+
* Validates that the given string does not exceed the specified maximum length.
|
|
32
|
+
*
|
|
33
|
+
* @param {string} value - The string value to validate.
|
|
34
|
+
* @param {number} [maxLength] - The maximum allowed length of the string. If 0 or not provided, no length validation is performed.
|
|
35
|
+
* @returns {boolean | string} Returns `true` if the validation passes, or an error message string if it fails.
|
|
36
|
+
*/
|
|
37
|
+
export declare function validateMaxLength(value: string, maxLength?: number): boolean | string;
|
|
38
|
+
/**
|
|
39
|
+
* Validates whether the input contains only alphanumeric characters and allowed special characters.
|
|
40
|
+
*
|
|
41
|
+
* @param {string} value - The input string to validate.
|
|
42
|
+
* @param {string[]} allowedCharacters - An array of allowed special characters.
|
|
43
|
+
* @returns {boolean | string} Returns `true` if validation passes, or an error message string if validation fails.
|
|
44
|
+
*/
|
|
45
|
+
export declare function validateAllowedCharacters(value: string, allowedCharacters?: AllowedCharacters[]): boolean | string;
|
|
29
46
|
/**
|
|
30
47
|
* Validate input is valid JSON.
|
|
31
48
|
*
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.validateClient = validateClient;
|
|
4
|
+
exports.validateUrl = validateUrl;
|
|
5
|
+
exports.validateEmptyString = validateEmptyString;
|
|
6
|
+
exports.validateEmptySpaces = validateEmptySpaces;
|
|
7
|
+
exports.validateMaxLength = validateMaxLength;
|
|
8
|
+
exports.validateAllowedCharacters = validateAllowedCharacters;
|
|
9
|
+
exports.validateJSON = validateJSON;
|
|
10
|
+
exports.validateSpecialChars = validateSpecialChars;
|
|
4
11
|
const i18n_1 = require("../i18n");
|
|
5
12
|
/**
|
|
6
13
|
* SAP client number is either empty or 3 digit string.
|
|
@@ -18,7 +25,6 @@ function validateClient(client) {
|
|
|
18
25
|
return (0, i18n_1.t)('general.invalidClient', { client });
|
|
19
26
|
}
|
|
20
27
|
}
|
|
21
|
-
exports.validateClient = validateClient;
|
|
22
28
|
/**
|
|
23
29
|
* Validate url input is valid url format.
|
|
24
30
|
*
|
|
@@ -34,7 +40,6 @@ function validateUrl(input) {
|
|
|
34
40
|
return (0, i18n_1.t)('general.invalidUrl', { input });
|
|
35
41
|
}
|
|
36
42
|
}
|
|
37
|
-
exports.validateUrl = validateUrl;
|
|
38
43
|
/**
|
|
39
44
|
* Validate input is not empty string.
|
|
40
45
|
*
|
|
@@ -48,7 +53,6 @@ function validateEmptyString(input) {
|
|
|
48
53
|
}
|
|
49
54
|
return (0, i18n_1.t)('general.inputCannotBeEmpty');
|
|
50
55
|
}
|
|
51
|
-
exports.validateEmptyString = validateEmptyString;
|
|
52
56
|
/**
|
|
53
57
|
* Validate input does not contain any whitespace characters.
|
|
54
58
|
*
|
|
@@ -61,7 +65,39 @@ function validateEmptySpaces(value) {
|
|
|
61
65
|
}
|
|
62
66
|
return true;
|
|
63
67
|
}
|
|
64
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Validates that the given string does not exceed the specified maximum length.
|
|
70
|
+
*
|
|
71
|
+
* @param {string} value - The string value to validate.
|
|
72
|
+
* @param {number} [maxLength] - The maximum allowed length of the string. If 0 or not provided, no length validation is performed.
|
|
73
|
+
* @returns {boolean | string} Returns `true` if the validation passes, or an error message string if it fails.
|
|
74
|
+
*/
|
|
75
|
+
function validateMaxLength(value, maxLength = 0) {
|
|
76
|
+
if (maxLength > 0 && value.length > maxLength) {
|
|
77
|
+
return (0, i18n_1.t)('general.maxLength', { maxLength });
|
|
78
|
+
}
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Validates whether the input contains only alphanumeric characters and allowed special characters.
|
|
83
|
+
*
|
|
84
|
+
* @param {string} value - The input string to validate.
|
|
85
|
+
* @param {string[]} allowedCharacters - An array of allowed special characters.
|
|
86
|
+
* @returns {boolean | string} Returns `true` if validation passes, or an error message string if validation fails.
|
|
87
|
+
*/
|
|
88
|
+
function validateAllowedCharacters(value, allowedCharacters) {
|
|
89
|
+
// Asterisks is supported for the semantic object and action field but not the inbound title
|
|
90
|
+
if (allowedCharacters && allowedCharacters.length > 0) {
|
|
91
|
+
const escapedChars = allowedCharacters.map((char) => `\\${char}`).join('');
|
|
92
|
+
const regex = new RegExp(`^[a-zA-Z0-9${escapedChars}]+$`);
|
|
93
|
+
if (!regex.test(value)) {
|
|
94
|
+
return (0, i18n_1.t)('general.supportedFormats', {
|
|
95
|
+
allowedCharacters: allowedCharacters.join('')
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
65
101
|
/**
|
|
66
102
|
* Validate input is valid JSON.
|
|
67
103
|
*
|
|
@@ -77,7 +113,6 @@ function validateJSON(value) {
|
|
|
77
113
|
return (0, i18n_1.t)('general.invalidJSON');
|
|
78
114
|
}
|
|
79
115
|
}
|
|
80
|
-
exports.validateJSON = validateJSON;
|
|
81
116
|
/**
|
|
82
117
|
* Validates a value for special characters.
|
|
83
118
|
*
|
|
@@ -92,5 +127,4 @@ function validateSpecialChars(value, regexp = '^[a-zA-Z0-9_$.\\-]+$') {
|
|
|
92
127
|
}
|
|
93
128
|
return (0, i18n_1.t)('general.invalidValueForSpecialChars');
|
|
94
129
|
}
|
|
95
|
-
exports.validateSpecialChars = validateSpecialChars;
|
|
96
130
|
//# sourceMappingURL=validators.js.map
|
package/dist/i18n.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { TOptions } from 'i18next';
|
|
2
2
|
export declare const PROJECT_INPUT_VALIDATOR_NS = "project-input-validator";
|
|
3
|
+
/**
|
|
4
|
+
* Adds the `project-input-validator` resource bundle to i18next.
|
|
5
|
+
* May be required to load i18n translations after initialising in the consumer module.
|
|
6
|
+
*/
|
|
7
|
+
export declare function addi18nResourceBundle(): void;
|
|
3
8
|
/**
|
|
4
9
|
* Initialize i18next with the translations for this module.
|
|
5
10
|
*/
|
package/dist/i18n.js
CHANGED
|
@@ -3,17 +3,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.PROJECT_INPUT_VALIDATOR_NS = void 0;
|
|
7
|
+
exports.addi18nResourceBundle = addi18nResourceBundle;
|
|
8
|
+
exports.initI18nProjectValidators = initI18nProjectValidators;
|
|
9
|
+
exports.t = t;
|
|
7
10
|
const i18next_1 = __importDefault(require("i18next"));
|
|
8
11
|
const project_input_validator_i18n_json_1 = __importDefault(require("./translations/project-input-validator.i18n.json"));
|
|
9
12
|
exports.PROJECT_INPUT_VALIDATOR_NS = 'project-input-validator';
|
|
13
|
+
/**
|
|
14
|
+
* Adds the `project-input-validator` resource bundle to i18next.
|
|
15
|
+
* May be required to load i18n translations after initialising in the consumer module.
|
|
16
|
+
*/
|
|
17
|
+
function addi18nResourceBundle() {
|
|
18
|
+
i18next_1.default.addResourceBundle('en', exports.PROJECT_INPUT_VALIDATOR_NS, project_input_validator_i18n_json_1.default);
|
|
19
|
+
}
|
|
10
20
|
/**
|
|
11
21
|
* Initialize i18next with the translations for this module.
|
|
12
22
|
*/
|
|
13
23
|
async function initI18nProjectValidators() {
|
|
14
|
-
await i18next_1.default.init({ lng: 'en', fallbackLng: 'en' }
|
|
24
|
+
await i18next_1.default.init({ lng: 'en', fallbackLng: 'en' });
|
|
25
|
+
addi18nResourceBundle();
|
|
15
26
|
}
|
|
16
|
-
exports.initI18nProjectValidators = initI18nProjectValidators;
|
|
17
27
|
/**
|
|
18
28
|
* Helper function facading the call to i18next. Unless a namespace option is provided the local namespace will be used.
|
|
19
29
|
*
|
|
@@ -27,7 +37,6 @@ function t(key, options) {
|
|
|
27
37
|
}
|
|
28
38
|
return i18next_1.default.t(key, options);
|
|
29
39
|
}
|
|
30
|
-
exports.t = t;
|
|
31
40
|
initI18nProjectValidators().catch(() => {
|
|
32
41
|
// needed by lint
|
|
33
42
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -2,4 +2,6 @@ export * from './deploy/validators';
|
|
|
2
2
|
export * from './ui5/validators';
|
|
3
3
|
export * from './general/validators';
|
|
4
4
|
export * from './adp/validators';
|
|
5
|
+
export * from './flp/validators';
|
|
6
|
+
export { addi18nResourceBundle } from './i18n';
|
|
5
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -14,8 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.addi18nResourceBundle = void 0;
|
|
17
18
|
__exportStar(require("./deploy/validators"), exports);
|
|
18
19
|
__exportStar(require("./ui5/validators"), exports);
|
|
19
20
|
__exportStar(require("./general/validators"), exports);
|
|
20
21
|
__exportStar(require("./adp/validators"), exports);
|
|
22
|
+
__exportStar(require("./flp/validators"), exports);
|
|
23
|
+
var i18n_1 = require("./i18n");
|
|
24
|
+
Object.defineProperty(exports, "addi18nResourceBundle", { enumerable: true, get: function () { return i18n_1.addi18nResourceBundle; } });
|
|
21
25
|
//# sourceMappingURL=index.js.map
|
|
@@ -48,6 +48,8 @@
|
|
|
48
48
|
"inputCannotBeEmpty": "Input cannot be empty.",
|
|
49
49
|
"inputCannotHaveSpaces": "Input cannot contain spaces.",
|
|
50
50
|
"invalidJSON": "Invalid JSON",
|
|
51
|
-
"invalidValueForSpecialChars": "Input must contain only Latin alphanumeric characters or the following symbols: '-','_','$' and '.'"
|
|
51
|
+
"invalidValueForSpecialChars": "Input must contain only Latin alphanumeric characters or the following symbols: '-','_','$' and '.'",
|
|
52
|
+
"maxLength": "Maximum length: {{maxLength}} characters",
|
|
53
|
+
"supportedFormats": "Only alphanumeric and '{{allowedCharacters}}' characters are allowed"
|
|
52
54
|
}
|
|
53
55
|
}
|
package/dist/ui5/validators.js
CHANGED
|
@@ -3,7 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.validateNamespace = validateNamespace;
|
|
7
|
+
exports.validateLibModuleName = validateLibModuleName;
|
|
8
|
+
exports.validateProjectFolder = validateProjectFolder;
|
|
9
|
+
exports.validateModuleName = validateModuleName;
|
|
7
10
|
const path_1 = require("path");
|
|
8
11
|
const i18n_1 = require("../i18n");
|
|
9
12
|
const fs_1 = require("fs");
|
|
@@ -62,7 +65,6 @@ function validateNamespace(namespace, moduleName, allowUnderscore = true) {
|
|
|
62
65
|
}
|
|
63
66
|
return validateNamespacePattern(namespace, moduleName, allowUnderscore);
|
|
64
67
|
}
|
|
65
|
-
exports.validateNamespace = validateNamespace;
|
|
66
68
|
/**
|
|
67
69
|
* Validator: UI5 library module name.
|
|
68
70
|
*
|
|
@@ -79,7 +81,6 @@ function validateLibModuleName(libName) {
|
|
|
79
81
|
}
|
|
80
82
|
return true;
|
|
81
83
|
}
|
|
82
|
-
exports.validateLibModuleName = validateLibModuleName;
|
|
83
84
|
/**
|
|
84
85
|
* Validator: UI5 project directory can be used to create a UI5 application.
|
|
85
86
|
*
|
|
@@ -104,7 +105,6 @@ function validateProjectFolder(targetFolder, projectName) {
|
|
|
104
105
|
return (0, i18n_1.t)('ui5.enterProjectFolder');
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
|
-
exports.validateProjectFolder = validateProjectFolder;
|
|
108
108
|
/**
|
|
109
109
|
* Validator: UI5 package json module name validator. Validates a module name accoding to npm package rules and some additional UI5 specific rules.
|
|
110
110
|
*
|
|
@@ -148,7 +148,6 @@ function validateModuleName(moduleName) {
|
|
|
148
148
|
.map((msg) => messageMap[msg] ?? (0, i18n_1.t)('ui5.invalidModuleName'))
|
|
149
149
|
.join(', ');
|
|
150
150
|
}
|
|
151
|
-
exports.validateModuleName = validateModuleName;
|
|
152
151
|
/**
|
|
153
152
|
* Test for existence of specified directory path.
|
|
154
153
|
*
|